Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL查询内存不足_Php_Mysql_Laravel - Fatal编程技术网

Php MySQL查询内存不足

Php MySQL查询内存不足,php,mysql,laravel,Php,Mysql,Laravel,我有一个系统,其中商店是一个帐户,客户在这些商店购物。有一个表存储客户和商店的多对多关联。该表的关键属性是accountid、customerid和last_Visite_date。对于一组AccountID,我需要查找每个客户最近的访问。我有一个查询工作得很好,但似乎效率很低,因为大约21000个客户的内存不足 SELECT ac.customerId FROM account_customer ac INNER JOIN (SELECT customerId, max(last

我有一个系统,其中商店是一个帐户,客户在这些商店购物。有一个表存储客户和商店的多对多关联。该表的关键属性是accountid、customerid和last_Visite_date。对于一组AccountID,我需要查找每个客户最近的访问。我有一个查询工作得很好,但似乎效率很低,因为大约21000个客户的内存不足

SELECT ac.customerId FROM account_customer ac 
      INNER JOIN (SELECT customerId, max(last_visit_date) AS 
                     LastVisitDate FROM account_customer 
                  WHERE accountId in        
                     (311,307,318,320,321,322,323,332,347,439,519,630,634,643) 
                 GROUP BY customerId) grouped_ac 
     ON ac.customerId = grouped_ac.customerId 
          AND ac.last_visit_date = grouped_ac.LastVisitDate 
          AND ac.last_visit_date <= '2016-10-18' 
          OR ac.last_visit_date is null
当我运行上面的查询时,它为较小的数据集提供了正确的结果,但对于较大的数据集,我得到了内存错误。我甚至不是说一个非常大的集合-大约20000多名客户

SELECT ac.customerId FROM account_customer ac 
      INNER JOIN (SELECT customerId, max(last_visit_date) AS 
                     LastVisitDate FROM account_customer 
                  WHERE accountId in        
                     (311,307,318,320,321,322,323,332,347,439,519,630,634,643) 
                 GROUP BY customerId) grouped_ac 
     ON ac.customerId = grouped_ac.customerId 
          AND ac.last_visit_date = grouped_ac.LastVisitDate 
          AND ac.last_visit_date <= '2016-10-18' 
          OR ac.last_visit_date is null
任何帮助都将不胜感激。

你的意思是

ac.customerId = grouped_ac.customerId 
AND ac.last_visit_date = grouped_ac.LastVisitDate 
and (ac.last_visit_date <= '2016-10-18' or ac.last_visit_date is null)
我认为如果没有括号,查询可能会返回那里的所有记录,最后的访问日期为空


查看。

发布您的PHP代码的答案。在MySQL中为查询运行解释计划。它可能暗示缺少索引。现在我正试图运行我使用mysql workbench直接在mysql服务器中发布的原始查询,但内存不足。@WaqarSadiq将解释粘贴在它的前面并发布结果。我这样做了,它返回了三行,但没有指出任何完整的表扫描或类似的内容。你知道吗你说得对。这就是正在发生的事情。谢谢。是不是因为这么多记录都回来了,所以导致了内存问题?我想是的。一旦我把这些括号放在周围,它就工作得很好,不会耗尽记忆。