Skip to content
Extraits de code Groupes Projets
Valider a37254a9 rédigé par mattab's avatar mattab
Parcourir les fichiers

The ultimate prize and final step to close the issue: do not group by the...

The ultimate prize and final step to close the issue: do not group by the whole set of matched rows, way too slow on huge datasets!
parent dac71ca1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -184,14 +184,18 @@ class LogQueryBuilder ...@@ -184,14 +184,18 @@ class LogQueryBuilder
$innerSelect = implode(", \n", $neededFields); $innerSelect = implode(", \n", $neededFields);
$innerFrom = $from; $innerFrom = $from;
$innerWhere = $where; $innerWhere = $where;
$innerGroupBy = "log_visit.idvisit";
$innerLimit = $limit;
$innerLimit = $limit;
$innerGroupBy = "log_visit.idvisit";
$innerOrderBy = "NULL"; $innerOrderBy = "NULL";
// Only when there is a LIMIT then we can apply to the inner query the same ORDER BY as the parent query
if($innerLimit && $orderBy) { if($innerLimit && $orderBy) {
// only When LIMITing we can apply to the inner query the same ORDER BY as the parent query
$innerOrderBy = $orderBy; $innerOrderBy = $orderBy;
} }
if($innerLimit) {
// When LIMITing, no need to GROUP BY (GROUPing by is done before the LIMIT which is super slow when large amount of rows is matched)
$innerGroupBy = false;
}
$innerQuery = $this->buildSelectQuery($innerSelect, $innerFrom, $innerWhere, $innerGroupBy, $innerOrderBy, $innerLimit); $innerQuery = $this->buildSelectQuery($innerSelect, $innerFrom, $innerWhere, $innerGroupBy, $innerOrderBy, $innerLimit);
......
...@@ -91,7 +91,6 @@ class ModelTest extends SystemTestCase ...@@ -91,7 +91,6 @@ class ModelTest extends SystemTestCase
AND log_visit.visit_last_action_time >= ? AND log_visit.visit_last_action_time >= ?
AND log_visit.visit_last_action_time <= ? ) AND log_visit.visit_last_action_time <= ? )
AND ( log_link_visit_action.custom_var_k1 = ? ) AND ( log_link_visit_action.custom_var_k1 = ? )
GROUP BY log_visit.idvisit
ORDER BY idsite, visit_last_action_time DESC ORDER BY idsite, visit_last_action_time DESC
LIMIT 100 LIMIT 100
) AS log_inner ) AS log_inner
......
...@@ -458,7 +458,7 @@ class SegmentTest extends IntegrationTestCase ...@@ -458,7 +458,7 @@ class SegmentTest extends IntegrationTestCase
} }
public function test_getSelectQuery_whenLimit_innerQueryShouldHaveLimit() public function test_getSelectQuery_whenLimit_innerQueryShouldHaveLimitAndNoGroupBy()
{ {
$select = 'sum(log_visit.visit_total_time) as sum_visit_length'; $select = 'sum(log_visit.visit_total_time) as sum_visit_length';
$from = 'log_visit'; $from = 'log_visit';
...@@ -489,7 +489,6 @@ class SegmentTest extends IntegrationTestCase ...@@ -489,7 +489,6 @@ class SegmentTest extends IntegrationTestCase
( log_visit.idvisit = ? ) ( log_visit.idvisit = ? )
AND AND
( log_link_visit_action.custom_var_k1 = ? ) ( log_link_visit_action.custom_var_k1 = ? )
GROUP BY log_visit.idvisit
ORDER BY NULL ORDER BY NULL
LIMIT 33 LIMIT 33
) AS log_inner ) AS log_inner
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter