code: public function batch($batchSize = 100, $db = null)
      {
          return Yii::createObject([
              'class' => BatchQueryResult::className(),
              'query' => $this,
              'batchSize' => $batchSize,
              'db' => $db,
              'each' => false,
          ]);
      }
docs: Starts a batch query.
  
  A batch query supports fetching data in batches, which can keep the memory usage under a limit.
  This method will return a [[BatchQueryResult]] object which implements the [[\Iterator]] interface
  and can be traversed to retrieve the data in batches.
  
  For example,
  
  ```php
  $query = (new Query)->from('user');
  foreach ($query->batch() as $rows) {
  // $rows is an array of 100 or fewer rows from user table
  }
  ```
  
  @param int $batchSize the number of records to be fetched in each batch.
  @param Connection $db the database connection. If not set, the "db" application component will be used.
  @return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface
  and can be traversed to retrieve the data in batches.