Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20632: Exporting Contacts using "Export PRIMARY fields" and "Merge Household Members into their Households" produces db error #11870

Closed
wants to merge 2 commits into from

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Mar 23, 2018

Overview

Exporting Contacts using the settings "Export PRIMARY fields" and "Merge Household Members into their Households" produces db error: "Database Error Code: Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline., 1118"

Before

screen shot 2018-03-23 at 2 34 28 pm

After

It fixes this error, also the patch is tested in 5.7 on FULL_GROUP_BY_MODE enabled.

Technical Details

Fix need a minor modification in appendAnyValueToSelect(...) to support alias when there isn't any and when select column is used in aggregate fn. On the other hand, modified the existing UT to include mergeSameHousehold = TRUE criteria.


@monishdeb
Copy link
Member Author

ping @lcdservices

@monishdeb
Copy link
Member Author

Jenkins test this please

@lcdservices
Copy link
Contributor

@monishdeb I implemented this and ran tests. I no longer get the error, but the merge does not happen.

  • created two test individuals and one household
  • created household member relationships between them
  • searched for all three contacts and triggered export
  • chose primary export and option to merge household members
  • resulting file had all three contacts listed. it should have only had the household record.

@lcdservices
Copy link
Contributor

Ran through tests, and we're making progress.

  1. exported primary fields + merge households = single household record exported (correct result)
  2. exported primary fields + same address = household + combined indivs (should have only exported the household; the existence of a household overrides the same address merge; it does correctly match and merge records that have the same address though)
  3. exported select fields + merge households = single household record exported (correct)
  4. exported select fields + same address = household + combined indivs (same issue as 2)

So it looks like we just need to sort out the issue with the merge same address function so that if a household relationship exists, it uses that instead of constructing the merged record. The help text for that field explains the intended behavior.

@eileenmcnaughton
Copy link
Contributor

If you are touching this code you should also remove the cloning per #11703 - it's a bit of a timebomb in the code because of the way it interacts with the memory leak bug in the DAO.

@monishdeb
Copy link
Member Author

monishdeb commented Mar 24, 2018

@lcdservices re 2nd and 4rth point, isn't this a separate issue as the current patch only fixes the fatal error related to Merge Household Members into their Households NOT Merge All Contacts with the Same Address ? The current code only refactor mergeSameHousehold() fn and it's related code. Also it doesn't bring any unintended affect to Merge All Contacts with the Same Address scenario.

@eileenmcnaughton thanks for pointing that memory leak case, will bring up the change in next PR update.

@lcdservices
Copy link
Contributor

@monishdeb I assumed (perhaps incorrectly) that these changes may have impacted that functionality. If you think otherwise, let's break it out into a separate issue (we will need to address it one way or the other).

@eileenmcnaughton
Copy link
Contributor

@monishdeb extractions are really good for the code base but hard to review when combined with other changes - if you do a clean extraction as a stand alone PR then I can look to merge that & this will be a lot simpler

@monishdeb
Copy link
Member Author

@eileenmcnaughton I am unable to extract the code into a separate PR because of this variable $relationType which is being used in every change. Let me explain what I did in terms of LOC:

  1. L572-582: Initialised variable $relationType which will contain relationship direction (i.e. 8_a_b) and temp table as its value. This temp table will store the related household record, whereas earlier a single table was used to store these data on separate set of columns appended with relationship prefix i.e. 8_a_b_contact_type, 8_a_b_display_name etc. Later leads to the current issue, reason why we are recording the related Household data in a separate table and later merged with it's member.
  2. L848 : moved the chunk of codes in a separate function fetchRelationshipDetails() that stores the related 8_a_b or 7_b_a records in a separate array structure like
$row = [
id,
contact_type,
...
8_a_b => [
   id,
   ...
  ]
7_b_a => [
 ...
 ],
]

unlike earlier as $row = [..., 8_a_b_id, ...,7_b_a_id...]

  1. L942-944: Is about creating and assigning temp table for respective relationship types as explained in step 1.

  2. Changes in writeDetailsToTable() function is to INSERT records of related contacts in those separate temp tables here

  3. Changes in mergeSameHousehold() is to UPDATE the main temp table that contain all the exported contacts, with the related records of Household contacts via INNER JOIN on relationship temp table (that contain corresponding Household records). This is the point

  4. L1845 - is a point where we doing GROUP_CONCAT on select columns except civicrm_primary_id which is used in GROUP BY. This is to avoid FULL_GROUP_BY_MODE DB error on Mysql 5.7

  5. L2028-2087 is no longer required as a result of change in logic.

  6. Extended ability of appendAnyValueToSelect to retain the SELECT column name by appending alias

@monishdeb
Copy link
Member Author

@eileenmcnaughton I have merged #11918 and rebased this PR. Please have a look.

@monishdeb
Copy link
Member Author

Added UT

@monishdeb
Copy link
Member Author

Jenkins test this please

… Members into their Households" produces db error
@eileenmcnaughton
Copy link
Contributor

@monishdeb current iteration towards getting this merged is #12290

@eileenmcnaughton
Copy link
Contributor

@monishdeb I'm going to close this now & keep chipping away at rationalising the export function. The current refactor is here #12579 and #12586

I'm now about 95% sure we gain no performance benefit by ever writing the household merge fields to a table as we actually iterate through them in php and we have all the information we need to merge them in php at a time when we are already doing heavy processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants