A
A
atis //2016-11-21 12:53:57
Yii
atis //, 2016-11-21 12:53:57

Why does Yii2 pull all data from the database when calling the batch method?

In general, the thing is.

foreach(Item::find()->batch(100) as $batch) {

}

Nothing complicated. But there are n million rows in the database. When executing the code, a request flies to the database: Here comes the w... The request is executed in the yii2\db\Command:901 line:
SELECT * FROM items
$this->pdoStatement->execute();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-11-21
@atis2345

Are you sure you want batch and not limit() and offset() ?

A
atis //, 2016-11-21
@atis2345

Issue not resolved
https://github.com/yiisoft/yii2/issues/8420

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question