MYSQL两条SQL语句效率测试……
结合连表…两条语句的效率相差甚大!主要是OR与IN的区别……
SELECT tid,sum(downloads) AS downloads FROM cdb_attachments GROUP BY tid ORDER BY aid
UPDATE cdb_threads SET downs = '$downloads' WHERE tid = '$tid'
SELECT t.tid, t.views, t.subject, sum( a.downloads ) AS downloads FROM cdb_threads t LEFT JOIN cdb_attachments a ON t.tid = a.tid WHERE t.fid IN ( '62', '61', '60', '59', '58', '57', '56', '55', '31', '30', '29', '28', '27', '26', '25', '24', '19' ) GROUP BY t.tid ORDER BY downloads DESC LIMIT 6
SELECT tid,sum(downloads) AS downloads FROM cdb_attachments GROUP BY tid ORDER BY aid
UPDATE cdb_threads SET downs = '$downloads' WHERE tid = '$tid'
SELECT t.tid, t.views, t.subject, sum( a.downloads ) AS downloads FROM cdb_threads t LEFT JOIN cdb_attachments a ON t.tid = a.tid WHERE ( t.fid = '62' OR t.fid = '61' OR t.fid = '60' OR t.fid = '59' OR t.fid = '58' OR t.fid = '57' OR t.fid = '56' OR t.fid = '55' OR t.fid = '31' OR t.fid = '30', '29' OR t.fid = '28' OR t.fid = '27' OR t.fid = '26' OR t.fid = '25' OR t.fid = '24' OR t.fid ='19' ) GROUP BY t.tid ORDER BY downloads DESC LIMIT 6
|