没有通配符的 SQL LIKE 与“="相同吗? [英] SQL LIKE with no wildcards the same as '='?

查看:29
本文介绍了没有通配符的 SQL LIKE 与“="相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常基本的问题,我认为我知道答案......但我想确认一下.

I know this is a pretty basic question, and I think I know the answer...but I'd like to confirm.

这些查询真的等价吗?

SELECT * FROM FOO WHERE BAR LIKE 'X'
SELECT * FROM FOO WHERE BAR ='X'

在没有通配符的情况下使用 like 可能会产生性能开销?

Perhaps there is a performance overhead in using like with no wild cards?

我有一个应用程序可以选择使用 LIKE &外卡.SP 当前执行类似操作并附加通配符 - 我正在考虑更新查询以使用类似但让应用程序根据需要附加通配符.

I have an app that optionally uses LIKE & wild cards. The SP currently does the like and appends the wild cards -- I am thinking of just updating the query to use like but have the app append the wild cards as needed.

推荐答案

正如@ocdecio 所说,如果优化器足够聪明,应该没有区别,但是如果您想确定幕后发生的事情,您应该比较两个查询的执行计划.

As @ocdecio says, if the optimizer is smart enough there should be no difference, but if you want to make sure about what is happening behind the scenes you should compare the two query's execution plans.

这篇关于没有通配符的 SQL LIKE 与“="相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆