MYSQL 5.1.52-community 我有一个250万行的大桌子:
我写了这个查询来解析数据:
SELECT DISTINCT a.id_dem FROM planning_demandes a
INNER JOIN planning_demandes b ON a.id_dem = b.id_dem
AND b.idrh IS NOT NULL
AND b.idrh <> 'férié'
AND b.idrh <> 'Pferié'
INNER JOIN planning_demandes c ON a.id_dem = c.id_dem
AND c.idrh IS NULL
执行时间超过100秒。
如何快速重写此请求? (使用agregates?我应该创建临时表)
THX
答案 0 :(得分:0)
删除一个连接,这是多余的
查询使用以下两种连接条件: a.id_dem = b.id_dem 和 a.id_dem = c.id_dem ,
所以这也必须是真的: b.id_dem = c.id_dem
SELECT DISTINCT b.id_dem
FROM planning_demandes b
JOIN planning_demandes c ON B.id_dem = c.id_dem
WHERE
b.idrh IS NOT NULL
AND b.idrh <> 'férié'
AND b.idrh <> 'Pferié'
AND c.idrh IS NULL