【发布时间】:2013-11-04 07:40:00
【问题描述】:
我有以下 MySQL 查询:
SELECT t1.id, t1.releaseid, t1.site, t1.date, t2.pos FROM `tracers` as t1
LEFT JOIN (
SELECT `releaseid`, `date`, COUNT(*) AS `pos`
FROM `tracers` GROUP BY `releaseid`
) AS t2 ON t1.releaseid = t2.releaseid AND t2.date <= t1.date
ORDER BY `date` DESC , `pos` DESC LIMIT 0 , 100
这个想法是选择一个版本并计算在记录日期之前有多少其他网站也发布了它,以获得职位。
解释说:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 498422 Using temporary; Using filesort
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 91661
2 DERIVED tracers index NULL releaseid 4 NULL 498422
关于如何消除 Using 临时的任何建议;使用文件排序?这需要很长时间。我想过并尝试过的索引没有任何帮助。
【问题讨论】:
-
您的确切指数是多少?
(releaseid)、(releaseid, date)和(date, pos)?