主题表有30M行。我正在执行一个查询来查找重复的hash。hash被定义为
`hash` varchar(50) NOT NULL;查询是
SELECT Count(*)
FROM (SELECT Count(id) `num`,
`signature`
FROM `images`
WHERE `hash` IS NOT NULL
GROUP BY `hash`
HAVING `num` > 1) AS `count_table` 在按下Ctrl+C以中止查询之前,大约需要5-7分钟。我又跑了一遍,还是等不了那么久。
我怎样才能更快地得到这个结果?
我知道这样做会有点慢。我觉得But8 mins太多了。
发布于 2013-08-29 08:23:29
确保在hash上有一个索引(或者是signature?)。
将COUNT(id)替换为COUNT(hash) (或COUNT(signature))。
发布于 2013-08-29 11:14:14
如果您只需要重复条目的计数,那么可以尝试
select count(*)-count(distinct hash) from images发布于 2013-08-29 08:27:25
如果我正确地理解了这一点,那么您只希望返回哪些列是复制的?尝试这个SELECT *从table_name作为t1在哪里存在(从table_name选择*作为t2,其中t1.hash=t2.hash和t1.id!=t2.id);
https://stackoverflow.com/questions/18505600
复制相似问题