对于较大的连接行,mysql查询返回500内部服务器错误

时间:2017-03-29 14:02:06

标签: mysql

  • 我查看过类似的问题及相关问题,但我找不到与此问题类似的问题。我正在使用CentOS6 VPS,Apache服务器。

如果我在我的PHP应用程序或直接phpmyadmin(通过浏览器)中运行以下mysql查询,则返回 500内部服务器错误。但是如果我在mysql中运行相同的查询(通过终端),它会在2.62秒内返回44864行。 并且它还将正确的结果返回给其他“town_id”(其中少量产品分配给给定的town_id)。

apache2 / access_log&中没有登录error_log,mysql错误日志既没有关于此的mysql-slow-queries。

SELECT DISTINCT(t.pid) FROM 
( SELECT Product.id AS pid FROM products Product 
LEFT JOIN productagents Productagent ON Productagent.product_id = Product.id 
LEFT JOIN productlocations Productlocation ON Productlocation.product_id = Product.id 
WHERE 1 AND Product.active = 1 AND Productagent.saleorent = 1 
AND ( Productlocation.town_id = 1682 ) 
AND (Productagent.product_status_id = 1) AND Productagent.product_status_id != 17 
ORDER BY Product.updated_at desc ) 
AS t 

我只是查询productlocation表,如下所示。它返回172388行。

SELECT id FROM `productlocations` WHERE town_id = 1682

以下是每个表格中的索引:

  

表:产品,索引名称:PRIMARY列:id

     

表:产品,索引名称:idx_act_updt列:id,active,updated_at

     

表:productagents,索引名称:PRIMARY列:id

     

表:productagents,索引名称:idx_prod_sor_sts列:product_id,saleorent,product_status_id

     

表:productlocations,索引名称:PRIMARY列:id

     

表:productlocations,索引名称:idx_prod_town列:product_id,town_id

0 个答案:

没有答案
相关问题