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-21362: Mailing summary report group by MySQL 5.7 error #11206

Merged
merged 2 commits into from
Oct 29, 2017

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Oct 27, 2017

Overview

Steps to replicate the error:

  1. Go to Mailing Summary Report (template/instance)
  2. Ensure that 'End Date' is not selected in Columns section.
  3. Select 'End Date' in under Sorting form
  4. Submit the Criteria

Before

Throw DB Error: unknown error
nativecode=1055 ** Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'civicrm_db.mailing_job_civireport.end_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by|#1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'civicrm_db.mailing_job_civireport.end_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

After

Fixes the error, but note that chosen ORDER column is now appended in GROUP BY clause

Technical Details

You need MySQL 5.7 setup to test this. Also, this patch has some additional optimisation changes

Comments

This might be affecting other Reports where nonaggregated ORDER BY columns were not present in GROUP BY.


@seamuslee001
Copy link
Contributor

@monishdeb you may want to check out this PR as well #10934 i'm fairly certain that its whats preventing some of these issues from poping up through the 1604 box

@monishdeb
Copy link
Member Author

@seamuslee001 you I did and made some comments there. So as per both the patch we are introducing a two separate fn to set/unset ONLY_FULL_GROUP_BY in session as per mysql version respectively. Once #10934 gets merged I will add a UT for this fix

@lcdservices
Copy link
Contributor

Looks good. Mailing summary report no longer throws group by error. Breaking this out into separate functions to determine group by mode and apply changes to report order by clauses is a good way to handle it.

@lcdservices
Copy link
Contributor

@Monish just ran across an unintended consequence of this change that I didn't notice in my original testing. the start/end date field is derived from the job table, not the mailing table. when we add the end date to the group by clause, mailings with more than one job (large mailings that were multi-threaded) show up in the report as multiple rows.

so although I think the general utility function is helpful and my be used in other reports, in this particular case, we need to handle the start and end dates differently -- the start date should be set to MIN() and the end date to MAX() so that we get the earliest/latest job dates for the mailing -- and not group on them.

also -- another modified file was added to this PR, and I don't think it's relevant. it was likely intended for a different PR.

@@ -149,11 +149,13 @@ public function __construct() {
'order_bys' => array(
'start_date' => array(
'title' => ts('Start Date'),
'dbAlias' => 'MAX(mailing_job_civireport.start_date)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be MIN. We want the earliest start date, and latest end date.

@lcdservices
Copy link
Contributor

@Monish latest changes look good. we're now pulling distinct mailing records and do not get group by errors. @colemanw can you review and merge?

$sqlModes = self::getSqlModes();

// Disable only_full_group_by mode for lower sql versions.
if (!self::supportsFullGroupBy() || (!empty($sqlModes) && !in_array('ONLY_FULL_GROUP_BY', $sqlModes))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monishdeb should the 2nd half of that 2nd test be && in_array not && !in_array as we want it if ONLY_FULL_GROUP_BY is in the array right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 no because the second part (!empty($sqlModes) && !in_array('ONLY_FULL_GROUP_BY', $sqlModes)) is for Mysql 5.7 where if ONLY_FULL_GROUP_BY is intentionally not present (i.e. !in_array) in sql modes then return TRUE which means GroupByMode is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you expect then in would just jump to the return in L93 because the array_search in 89 won't find it then right?

Copy link
Member Author

@monishdeb monishdeb Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes .. exactly. Also this logic is already written and tested earlier. See above in Contact/BAO/Query.php from where this condition was moved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok no worries makes sense then

@seamuslee001
Copy link
Contributor

Agree with the PR, just want Monish to confirm that if statement but i think this is good to merge

@seamuslee001
Copy link
Contributor

ping @eileenmcnaughton @colemanw this looks good to me

@seamuslee001
Copy link
Contributor

ping @totten this seems to have been tested by Brian and fixes a problem

@colemanw colemanw merged commit f118998 into civicrm:master Oct 29, 2017
@monishdeb monishdeb deleted the CRM-21362 branch October 30, 2017 05:25
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21362: Mailing summary report group by MySQL 5.7 error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants