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 关注
- 121 浏览
添加回答
举报