我对具有 400 万条记录的表进行了自联接查询....我们如何优化查询...查询必须获取具有最大日期的行
SELECT DISTINCT d1.C1 AS c1, d1.C2 AS c2, d1.C3 AS c3,
d1.datedm_id AS c4 FROM TABLEA d1 LEFT OUTER JOIN TABLEA d2
ON (d1.C1 = d2.C1 AND d1.C2 = d2.C2 AND d1.datedm_id < d2.datedm_id )
WHERE d2.C1 IS NULL AND d2.C2 IS NULL
目前,此查询需要很长时间才能执行
EXPLAIN 显示如下
d1 4051368 Using index; Using temporary
d2 1 Using where; Using index; Not exists; Distinct