简体   繁体   English

Exists in sql server的执行

[英]Execution of Exists in sql server

As we know all are saying EXISTS is good over IN clause.正如我们所知,所有人都在说EXISTS优于IN子句。 I have question ever which not answered every time.我有一个问题,每次都没有回答。

when we use Exists , is complete execution of inner query while it get first record or it will continue execution for all records??当我们使用Exists时,是在获取第一条记录时完整执行内部查询还是继续执行所有记录?

both exists and in are the same. existsin都是一样的。 Any sane query plan optimizer will produce the same plan for them both.任何理智的查询计划优化器都会为它们生成相同的计划。

-- http://sqlfiddle.com/#!6/97c87/1
select *
from t1
where name in (select name from t2)

This query will produce the plan:此查询将生成计划:

计划一

-- http://sqlfiddle.com/#!6/97c87/2
select *
from t1
where exists (select name from t2 where t2.name=t1.name)

And this second query will produce the plan:第二个查询将生成计划:

在此处输入图像描述

As you can see, both are identical.如您所见,两者是相同的。

[NOT] EXISTS operator gives best performance when the subquery ie driven query contains huge volume of data. [NOT] EXISTS 运算符在子查询即驱动查询包含大量数据时提供最佳性能。 The reason is that it follows the principle of 'At least found' in queries.原因是它遵循查询中“至少找到”的原则。 It is set to TRUE, if at least one record is found in the subquery correlating with the main driving query, and stops further scanning of the table.如果在与主驱动查询相关的子查询中找到至少一条记录,则将其设置为 TRUE,并停止对该表的进一步扫描。 Unlike other comparison operators like [NOT] IN, LIKE and others, which returns data for comparison, [NOT] EXISTS return BOOLEAN output.与 [NOT] IN、LIKE 等返回数据进行比较的其他比较运算符不同,[NOT] EXISTS 返回 BOOLEAN 输出。

You can find more detailed illustrations in the link :您可以在链接中找到更详细的插图:

http:\/\/www.dbanotes.com\/database-development\/using-exists-in-oracle-sql-queries\/<\/a> http:\/\/www.dbanotes.com\/database-development\/using-exists-in-oracle-sql-queries\/<\/a>

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM