SQL效率 – [=] vs [in] vs [like] vs [matches]
发布时间:2020-12-12 07:48:39 所属栏目:MsSql教程 来源:网络整理
导读:出于好奇,我想知道在使用[=]与[in]与[like]与[matches](仅为1值)语法的sql中是否存在任何速度/效率差异. select field from table where field = value; 与 select field from table where field in (value); 与 select field from table where field like va
出于好奇,我想知道在使用[=]与[in]与[like]与[matches](仅为1值)语法的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引擎的优化器. 在oracle中,IN和EXISTS之间存在很多差异,但不一定在SQL Server中. 您必须考虑的另一件事是您使用的列的选择性.有些案例表明IN更好. 但是你必须记住IN是非sargable(非搜索参数能够)所以它不会使用索引来解析查询,LIKE和=是可搜索的并且支持索引 最好的 ?你应该花一些时间在你的环境中测试它 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |