我有以下查询,需要几分钟才能在 mysql 上运行:
SELECT * FROM
sys_quote_master AS g1
JOIN (SELECT order_id, order_base_id, max(order_date_last_revised) as mostrecent
FROM sys_quote_master group by order_base_id) AS g2
ON g2.mostrecent = g1.order_date_last_revised
ORDER BY g1.order_id;
查询运行了几分钟,最终我得到了这个错误:
Incorrect key file for table '/tmp/#sql_4f0_1.MYI'; try to repair it
有人可以帮助我并告诉我出了什么问题吗?
最佳答案
如果您解释计划,我想您会发现内部 SELECT 必须执行表扫描才能找到 max(order_date_last_revised)。
我想知道如果使用 GROUP BY 和 HAVING 子选择是否会更快?
http://www.java2s.com/Code/SQL/Select-Clause/GROUPandHAVINGwithsubquery.htm
请 EXPLAIN PLAN 告诉你我是否正确。
关于mysql - 为什么这个查询需要一整天才能在 mysql 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22725949/