Skip to content

Commit 5a0bb55

Browse files
committed
optimization for IN conditions
fixes yiisoft/yii2#7586
1 parent 02589d8 commit 5a0bb55

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ActiveQuery.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ protected function executeScript($db, $type, $columnName = null)
350350
}
351351

352352
// find by primary key if possible. This is much faster than scanning all records
353-
if (is_array($this->where) && !isset($this->where[0]) && $modelClass::isPrimaryKey(array_keys($this->where))) {
353+
if (is_array($this->where) && (
354+
!isset($this->where[0]) && $modelClass::isPrimaryKey(array_keys($this->where)) ||
355+
isset($this->where[0]) && $this->where[0] === 'in' && $modelClass::isPrimaryKey($this->where[1])
356+
)) {
354357
return $this->findByPk($db, $type, $columnName);
355358
}
356359

@@ -372,7 +375,9 @@ protected function executeScript($db, $type, $columnName = null)
372375
*/
373376
private function findByPk($db, $type, $columnName = null)
374377
{
375-
if (count($this->where) == 1) {
378+
if (isset($this->where[0]) && $this->where[0] === 'in') {
379+
$pks = (array) $this->where[2];
380+
} elseif (count($this->where) == 1) {
376381
$pks = (array) reset($this->where);
377382
} else {
378383
foreach ($this->where as $values) {

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
44
2.0.6 under development
55
-----------------------
66

7-
- no changes in this release.
7+
- Enh: Optimized find by PK for relational queries and IN condition (cebe, andruha)
88

99

1010
2.0.5 March 17, 2016

0 commit comments

Comments
 (0)