whereIn 大数据,内存占用问题
// 取 order 表的部分符合条件的 uuid ,此处为简单示例直接取 all
$orderUUIDs = Order::all()->pluck('order_uuid');
info('内存记录:'.memory_get_usage());
// 代码执行到下面这句内存溢出,实际使用时 $orderUUIDs 大概有十几万条
OrderFee::whereIn('order_uuid', $orderUUIDs)->sum('fee');
以上代码输出
[2022-07-27 18:36:02] production.INFO: 内存记录:51784224
[2022-07-27 18:36:02] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1052672 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 1052672 bytes) at /apps/storage/20220720181003/vendor/laravel/framework/src/Illuminate/Collections/Arr.php:558)
问题:MySQL in 怎么这么耗内存,我只是取一个聚合结果
推荐文章: