SQL 效率

编程入门 行业动态 更新时间:2024-10-16 02:25:49
本文介绍了SQL 效率 - [=] vs [in] vs [like] vs [matches]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

出于好奇,我想知道使用 [=] 与 [in] 与 [like] 与 [matches](只有 1 个值)的 sql 语法.

Just out of curiosity, I was wondering if there are any speed/efficiency differences in using [=] versus [in] versus [like] versus [matches] (for only 1 value) syntax for sql.

select field from table where field = value;

对比

select field from table where field in (value);

对比

select field from table where field like value;

对比

select field from table where field matches value;

推荐答案

我将添加也存在和子查询.

但性能取决于给定 SQL 引擎的优化器.

But the performance depends on the optimizer of the given SQL engine.

在 oracle 中,IN 和 EXISTS 之间有很多区别,但在 SQL Server 中不一定.

In oracle you have a lot of differences between IN and EXISTS, but not necessarily in SQL Server.

您必须考虑的另一件事是您使用的列的选择性.一些案例表明IN更好.

The other thing that you have to consider is the selectivity of the column that you use. Some cases show that IN is better.

但您必须记住 IN 是 non-sargable(不可搜索参数),因此它不会使用索引来解析查询,LIKE 和 = sargable 并支持索引

But you have to remember that IN is non-sargable (non search argument able) so it will not use the index to resolve the query, the LIKE and = are sargable and support the index

最好的?您应该花一些时间在您的环境中对其进行测试

The best ? You should spend some time to test it in your environment

更多推荐

SQL 效率

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

发布评论

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

>www.elefans.com

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