本文介绍了IN运算符对SQL查询性能有多严重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要9个小时执行的SQL查询.见下文:

I had SQL query that was taking 9 hours for execution. See below:

Select Field1, Field2
From A
Where Field3 IN (45 unique values here)

当我将此查询分为3个完全相同的查询时,每个查询在IN子句中只有15个值时,每个查询需要2分钟的时间来执行.因此,我现在不用花9个小时,而是花了6分钟(3个查询* 2分钟).

When I have split this query into 3 exactly the same queries only with each having 15 values within IN clause, they each took 2 minutes to execute.So instead of spending 9 hours I now spend 6 minutes (3 queries * 2 minutes).

任何人都可以解释一下IN子句中只有数量值不同的相同查询如何花费不同的时间运行吗?

Can anyone explain please how practically the same queries with only difference in quantity of values in the IN clause take that different an amount of time to run?

推荐答案

您尝试使用EXISTS吗?

 Select Field1, Field2 From A Where
 EXISTS (SELECT NULL FROM B Where
 B.value = A.Value )

这篇关于IN运算符对SQL查询性能有多严重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:24