3 回答

TA貢獻1842條經驗 獲得超22個贊
我發現問題在于 laravel 獲取分頁結果的記錄總數:
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
...
$total = $this->toBase()->getCountForPagination()
...
}
protected function runPaginationCountQuery($columns = ['*'])
{
return $this->cloneWithout($without)->cloneWithoutBindings($this->unions ? ['order'] : ['select', 'order'])->setAggregate('count', $this->withoutSelectAliases($columns))->get()->all();
}
通常,最后一種方法運行分頁CountRy為了獲取記錄計數而創建對數據庫的原始查詢,如下所示:
選擇 count(*) 作為從左聯接開始的聚合。= .左聯接上 ...lotstenderstendersidlotstender_idcustomerslotscustomer_id
但是使用groupBy在查詢中而不是一行,總計數我得到了420650行,每行一行!它是足夠大的數組,創建只是為了獲取行數,在我的情況下,這是完成內存的原因。
我知道groupBy對于大數據不是一個好的決定,我對我的代碼進行了重構,以從我的查詢中撤消groupBy。但事實上,在我看來,這并不是你可能預料到的正常的拉拉維爾行為。
- 3 回答
- 0 關注
- 120 瀏覽
添加回答
舉報