Maison  >  Article  >  php教程  >  SQL中in或or与union all性能对比

SQL中in或or与union all性能对比

WBOY
WBOYoriginal
2016-05-25 16:43:271131parcourir

//使用or,代码如下: 
WHERE * FROM article  
WHERE article_category=2  
OR article_category=3  
ORDER BY article_id DESC  
LIMIT 5  
// 执行时间:11.0777 
 
//使用in,代码如下: 
SELECT * FROM article  
WHERE article_category IN (2,3)  
ORDER BY article_id DESC  
LIMIT 5 
 // 执行时间:11.2850 
 
//使用union all,代码如下: 
(  
SELECT * FROM article  
WHERE article_category=2  
ORDER BY article_id DESC  
LIMIT 5  
) UNION ALL (  
SELECT * FROM article  
WHERE article_category=3  
ORDER BY article_id DESC  
LIMIT 5  
)  
ORDER BY article_id DESC  
LIMIT 5  
// 执行时间:0.0261


教程链接:

随意转载~但请保留教程地址★

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn