Skip to content
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

Fix regression from getSelectCountSql optimization when collection us… #3279

Merged
merged 4 commits into from
May 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/Varien/Data/Collection/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ 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
// 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);
});
Expand All @@ -258,7 +261,16 @@ public function getSelectCountSql()
return !preg_match($pattern, $clause);
});
});
if (empty($whereUsingJoin)) {
if ($this->_bindParams) {
$bindParams = array_map(function ($token) {
return ltrim($token, ':');
}, array_keys($this->_bindParams));
$bindPattern = '/:('.implode('|', $bindParams).')/';
$joinUsingBind = array_filter($leftJoins, function ($table) use ($bindPattern) {
return !empty($table['joinCondition']) && 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