SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542540')
AND a.checked = 1
37.099 秒
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(SELECT inid FROM cms_aalbum_zt WHERE pid='542540')
AND a.checked = 1
36.661 秒
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(
542209,542207,542206,542205,542202,542201,830,829,828,827,825,823,822,821,819,817,815,814,542182,542181,542180,542179,542178,824,816,811,810,541285,541284,541281,530192,530190,530189,542749,542746,542744,542743,541295,541292,541288,541287,541282,541277
)
AND a.checked = 1
0.607 秒 + 0.002 秒
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(SELECT inid FROM (SELECT DISTINCT inid FROM cms_aalbum_zt
WHERE pid='542540') as temp_tab)
AND a.checked = 1 ;
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN( SELECT DISTINCT inid FROM cms_aalbum_zt
WHERE pid='542540' )
AND a.checked = 1
select ((select count(*) from cms_archives11 a where a.checked = 1) -
(select count(*) from cms_archives11 a
right join cms_aalbum_zt b on a.aid = b.inid
where b.pid = 542539 and a.checked = 1));
0.493 秒
select ((select count(*) from cms_archives11 a where a.checked = 1) -
(select count(*) from cms_aalbum_zt b
left join cms_archives11 a on a.aid = b.inid
where b.pid = 542540 and a.checked = 1));
0.496 秒
http://see.xidian.edu.cn/cpp/html/1468.html
索引的设计和使用
http://zhidao.baidu.com/link?url=pjirFwqRE01WnoF8ypBTaVHMOlCNIO1ReHVxJFDiaguHZeC1-D5ir2Iljgnus8eMwVgEDNzUhEU8NgZCPQragq
MYSQL NOT IN优化
http://ggmmchou.blog.163.com/blog/static/59333149201043153830652/
Mysql 下 SQL 优化NOT IN
http://zhwlsoft.blog.163.com/blog/static/1763712022011828113446684/
MySQL的Sql语句优化(转载)
http://www.cnblogs.com/xh831213/archive/2012/05/09/2491272.html --- OK
mysql in 子查询 效率慢 优化(转)
select id,title from article where id in(
select article_id from (select article_id from article_tag where tag_id=135) as tbt
)
SELECT COUNT(*) FROM cms_archives14 a
WHERE a.aid NOT IN(
SELECT inid FROM (SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542540') as tmptb
)
AND a.checked = 1
??? --- 后台 专题加载 内容
---------
SELECT COUNT(*) FROM cms_archives14 a
WHERE a.aid NOT IN(SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542540')
AND a.checked = 1
(36.452 秒)
-=>
SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542540';
SELECT COUNT(*) FROM cms_archives14 a
WHERE a.aid NOT IN(
542209,542207,542206,542205,542202,542201,830,829,828,827,825,823,822,821,819,817,815,814
)
AND a.checked = 1
-=>
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(SELECT inid FROM (SELECT DISTINCT inid FROM cms_aalbum_zt
WHERE pid='542540') as temp_tab)
AND a.checked = 1
(1.668 秒)
---------
SELECT COUNT(*) FROM cms_archives14 a
WHERE a.aid NOT IN(SELECT DISTINCT inid FROM cms_aalbum_zt
WHERE pid='542540')
AND a.checked = 1
select COUNT(*) from cms_archives14 a
where not exists(select b.inid from cms_aalbum_zt b where b.inid=a.id)
SELECT COUNT(*) FROM cms_archives14 a
WHERE a.aid NOT IN(SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542540')
AND a.checked = 1
;
select COUNT(*) from cms_archives14 a
where not exists(select b.inid from cms_aalbum_zt b where pid='542540' AND b.inid=a.aid)
SELECT COUNT(*) FROM cms_archives11 a
WHERE a.aid NOT IN(SELECT DISTINCT inid FROM cms_aalbum_zt WHERE pid='542539')
AND a.checked = 1
;
select COUNT(*) from cms_archives11 a
where not exists(select b.inid from cms_aalbum_zt b where pid='542539' AND b.inid=a.aid)