子查询的运行速度比联接快?

编程入门 行业动态 更新时间:2024-10-28 00:18:06
本文介绍了子查询的运行速度比联接快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从同一列的另一列中确实存在的一列中识别值

I am trying to identify value from one column which does exist in another column in same table

子查询

SELECT DISTINCT `Wear it With - Outfits 1` FROM `product list` WHERE `Wear it With - Outfits 1` NOT IN (SELECT `sku` FROM `product list`)

...返回结果为2.7287秒

...returns result in 2.7287sec

我尝试用左联接替换子查询

I tried to replace sub query by left join

SELECT DISTINCT table1.`Wear it With - Outfits 1` FROM `product list` as table1 LEFT JOIN `product list` as table2 ON table1.`Wear it With - Outfits 1`=table2.sku WHERE table2.sku IS NULL AND table1.`Wear it With - Outfits 1` IS NOT NULL

...在5.7651秒内返回结果

...which returns result in 5.7651 sec

通常联接返回结果要快得多.所以我相信我在查询中做了一些有趣的事情? 但是找不到任何原因使我的子查询运行得比

Normally joins return results much faster. So i believe i did something funny in my query? But can not find any reason why my subquery is running faster than

推荐答案

语句通常加入返回结果要快得多".是愚蠢的,尤其是在没有引用任何特定数据库系统的情况下.

The statement 'Normally joins return results much faster.' is silly, especially without reference to any particular database system.

许多因素影响确定特定查询的性能.您可以在所使用的任何数据库产品中使用EXPLAIN工具来确定在这种情况下为什么最好使用子查询(提示:它可能与关键字DISTINCT有关).

Many factors go into determining the performance of a particular query. You can use the EXPLAIN tool in whatever database product you're using to determine exactly why the sub-query is preferable in this case (hint: it likely has to do with the use of the keyword DISTINCT).

更多推荐

子查询的运行速度比联接快?

本文发布于:2023-10-18 11:41:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:运行速度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!