-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Remove ORDER BY and GROUP BY from alphabetQuery to improve performance #16877
Conversation
…e. Refs civicrm#1665 CIVICRM-1457
(Standard links)
|
Does this work with fullgroupby enables on mysql? |
Jenkins test this please |
@mattwire the test system uses the MySQL 5.7 Only Full Group By sql mode |
@agileware-justin @seamuslee001 Please see #13772 where this code had a major refactor and switched to newer methods. I think the reason those group by/order by clauses are there are just because that's what the old code did. Please have a quick read through that PR to be happy that this change won't break anything. This code is responsible for generating the "alphabet" pager along the top of search results. The letters should appear in the right order (including non-english characters eg. á etc.). If you test and confirm this is the case then happy for it to be merged. |
{$sqlParts['having']} | ||
GROUP BY sort_name | ||
ORDER BY sort_name asc"; | ||
{$sqlParts['having']}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note it's invalid to have a having without a group by - however, it's also invalid to have one BEFORE the group by I think so ??? (WTF)
Betty and I are reviewing PRs and we came across this one. No work has happened since March 23. @agileware-justin are you planning to do any work on this? If not we will advice to close this PR. |
Jenkins re test this please |
I started testing this last week but still need more testing to do will report back |
Hi, As explained in a question on Stack Exchange, usage of The |
Ok - so here is my take on this
So I think it's OK to remove the orderBy & GroupBy as long as we ALSO remove HAVING - since having without group by makes no sense. @agileware-justin are you OK to make that change? |
OK I'll review |
@eileenmcnaughton why do only "larger sites" get the benefit of this performance tweak? Surely, the "smaller sites" would have a much better user experience if they could also have a more responsive site and disabling these options as you mentioned should really be the default, not some obsure "large site only hack". Don't you agree? |
@agileware-justin lots of things that perform badly on large data sets don't have noticeable issues on small datasets |
It seems that a similar error occurs in $select = 'SELECT count(DISTINCT contact_a.id) as rowCount'; HAVING clauses become orphan, as SELECT is limited to |
@bastienho what query generates a HAVING clause? |
None in the core, but a one added by an extension. |
I'm going to merge this and follow up with a subsequent PR to remove the having clause |
Overview
Copied from https://lab.civicrm.org/dev/core/issues/1665
MySQL uses filesort index when building the query which can cause performance issues. This can be solved by simply removing the GROUP BY and ORDER BY options from query in function alphabetQuery, CRM/Contact/BAO/Query.php see https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/BAO/Query.php#L5012
This change has no visible impact on the search results pager or listing.
Before
function alphabetQuery, CRM/Contact/BAO/Query.php see https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/BAO/Query.php#L5012
Original query:
The query was generated by CiviCRM when doing an Advanced Search and selecting 6 CiviCRM Groups (not Smart Groups) - displaying results as contacts.
Before this change, note the "Using filesort" on 24754 rows. Query takes longer than 90 seconds to complete - can trigger a PHP timeout.
After
Remove the GROUP BY and ORDER BY options from query in function alphabetQuery, CRM/Contact/BAO/Query.php see https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/BAO/Query.php#L5012
Change query to:
After this change, note absence of the "Using filesort". Query completes in 5 seconds or less.
This change has no visible impact on the search results pager or listing.
Technical Details
None.
Comments
See Gitlab, https://lab.civicrm.org/dev/core/issues/1665
Agileware ref: CIVICRM-1457