Skip to content

Commit

Permalink
Fix regression from getSelectCountSql optimization when collection us…
Browse files Browse the repository at this point in the history
…es bind parameters in join clauses. Refs OpenMage#2210
  • Loading branch information
colinmollenhour committed May 26, 2023
1 parent e3c88f1 commit 1830dd8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/Varien/Data/Collection/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ public function getSelectCountSql()
} else {
$countSelect->columns('COUNT(*)');

// Simple optimization - remove all joins if there are no where clauses using joined tables and all joins are left joins
$leftJoins = array_filter($countSelect->getPart(Zend_Db_Select::FROM), function ($table) {
// Simple optimization - remove all joins if:
// - there are no where clauses using joined tables
// - all joins are left joins
// - there are no join conditions using bind params (for simplicity)
$leftJoins = array_filter($countSelect->getPart(Zend_Db_Select::FROM), function($table) {
return ($table['joinType'] == Zend_Db_Select::LEFT_JOIN || $table['joinType'] == Zend_Db_Select::FROM);
});
if (count($leftJoins) == count($countSelect->getPart(Zend_Db_Select::FROM))) {
Expand All @@ -258,7 +261,13 @@ public function getSelectCountSql()
return !preg_match($pattern, $clause);
});
});
if (empty($whereUsingJoin)) {
if ($this->_bindParams) {
$bindPattern = '/('.implode('|', array_keys($this->_bindParams)).')/';
$joinUsingBind = array_filter($leftJoins, function ($table) use ($bindPattern) {
return preg_match($bindPattern, $table['joinCondition']);
});
}
if (empty($whereUsingJoin) && empty($joinUsingBind)) {
$from = array_slice($leftJoins, 0, 1);
$countSelect->setPart(Zend_Db_Select::FROM, $from);
}
Expand Down

0 comments on commit 1830dd8

Please sign in to comment.