From 6f5824c1fc881af00c28f96b3ff3ac8b11745fdb Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 19 Nov 2018 13:45:54 +1300 Subject: [PATCH] Fix Export when full group by mode is used After upgrading locally to mysql 5.7 I found that the exportIM test was taking so long locally that I was killing it rather than finding out how long it would take. Digging into it I found that we were changing the query so that attempts to group by contact ID were being nullified when full group by is enabled. This meant that we were winding up with 7776 rows being retrieved to reflect a grid of permutations, which was being iterated down to 1 in php. In general the practice of altering the groupby to meet this new standard is one that we determined to be causing problems and we discontinued / rolled back --- CRM/Export/BAO/Export.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index c530add01e..c56ca09031 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -166,14 +166,7 @@ class CRM_Export_BAO_Export { $groupBy = "civicrm_activity.id "; } - if (!empty($groupBy)) { - if (!Civi::settings()->get('searchPrimaryDetailsOnly')) { - CRM_Core_DAO::disableFullGroupByMode(); - } - $groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($query->_select, $groupBy); - } - - return $groupBy; + return $groupBy ? ' GROUP BY ' . $groupBy : ''; } /** @@ -463,7 +456,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c while (!$limitReached) { $limitQuery = "{$queryString} LIMIT {$offset}, {$rowCount}"; + CRM_Core_DAO::disableFullGroupByMode(); $iterationDAO = CRM_Core_DAO::executeQuery($limitQuery); + CRM_Core_DAO::reenableFullGroupByMode(); // If this is less than our limit by the end of the iteration we do not need to run the query again to // check if some remain. $rowsThisIteration = 0; @@ -1585,11 +1580,13 @@ WHERE {$whereClause}"; $today = date('Ymd'); $relationActive = " AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= {$today} ) )"; $relationWhere = " WHERE contact_a.is_deleted = 0 {$relationshipClause} {$relationActive}"; - $relationGroupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($relationQuery->_select, "crel.{$contactA}"); + CRM_Core_DAO::disableFullGroupByMode(); $relationSelect = "{$relationSelect}, {$contactA} as refContact "; - $relationQueryString = "$relationSelect $relationFrom $relationWhere $relationHaving $relationGroupBy"; + $relationQueryString = "$relationSelect $relationFrom $relationWhere $relationHaving GROUP BY crel.{$contactA}"; $allRelContactDAO = CRM_Core_DAO::executeQuery($relationQueryString); + CRM_Core_DAO::reenableFullGroupByMode(); + while ($allRelContactDAO->fetch()) { $relationQuery->convertToPseudoNames($allRelContactDAO); $row = []; -- 2.25.1