if (select count(*) from table_name where 条件) 与 if exists(select * from table_name where 条件) 哪个效率更高?
if (select count(*) from table_name where 条件) 与 if exists(select * from table_name where 条件) 哪个效率更高?
调试欢乐多
这个比你说的那两个更高~
if exists(select 1 from table_name where 条件)
这个比你说的那两个更高~
------------------------------------------------------------
if exists(select * from table_name where 条件)
与 if exists(select 1 from table_name where 条件) 的执行计划是一样的,
效率应该是一致的。
与 if exists(select 1 from table_name where 条件) 的执行计划是一样的,
效率应该是一致的。------------------------------------
恐怕你的列数比较少
最快
if exists(select 1 from table_name where 条件)
if exists(select 某字段 from table_name where 条件)
if (select count(*) from table_name where 条件)>0
都快COUNT不解释了
EXiSTS可以从关系运算的角度给出解释这是我以前测试过的测试数据100000条,测试循环次数100~10000(大数定理,hoho)
当然也测试了有无索引的情况
与 if exists(select 1 from table_name where 条件) 的执行计划是一样的,
效率应该是一致的。------------------------------------
恐怕你的列数比较少---------------------------------
exists并不需要将列返回,*,列名,1作用几乎相当EXISTS
指定一个子查询,检测行的存在。 语法
EXISTS subquery参数
subquery是一个受限的 SELECT 语句 (不允许有 COMPUTE 子句和 INTO 关键字)。有关更多信息,请参见 SELECT 中有关子查询的讨论。 结果类型
Boolean结果值
如果子查询包含行,则返回 TRUE。
因为后者没有使用count函数