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

Always add outer limit when specified in case inner queries return more rows

parent 68c2b280
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -408,21 +408,28 @@ class Model
$orderBy .= "visit_last_action_time " . $filterSortOrder;
$orderByParent = "sub.visit_last_action_time " . $filterSortOrder;
// this $innerLimit is a workaround (see https://github.com/piwik/piwik/issues/9200#issuecomment-183641293)
$innerLimit = $limit;
if (!$segment->isEmpty()) {
$limit = $limit * 10;
$innerLimit = $limit * 10;
}
$subQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy, $groupBy, $limit, $offset);
$innerQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy, $groupBy, $innerLimit, $offset);
$bind = $subQuery['bind'];
// Group by idvisit so that a visitor converting 2 goals only appears once
$bind = $innerQuery['bind'];
// Group by idvisit so that a given visit appears only once, useful when for example:
// 1) when a visitor converts 2 goals
// 2) when an Action Segment is used, the inner query will return one row per action, but we want one row per visit
$sql = "
SELECT sub.* FROM (
" . $subQuery['sql'] . "
" . $innerQuery['sql'] . "
) AS sub
GROUP BY sub.idvisit
ORDER BY $orderByParent
";
if($limit) {
$sql .= sprintf("LIMIT %d \n", $limit);
}
return array($sql, $bind);
}
......
......@@ -57,6 +57,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......@@ -97,6 +98,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'2',
......@@ -135,6 +137,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......@@ -175,12 +178,13 @@ class ModelTest extends IntegrationTestCase
AND log_visit.visit_last_action_time <= ? )
AND ( log_link_visit_action.custom_var_k1 = ? )
ORDER BY idsite, visit_last_action_time DESC
LIMIT 10, 100
LIMIT 10, 1000
) AS log_inner
ORDER BY idsite, visit_last_action_time DESC
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......
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