Oracle的IN vs OR,哪个更快? [英] IN vs OR of Oracle, which faster?
问题描述
我正在开发一个处理Oracle数据库中许多数据的应用程序.
在某些情况下,我必须根据给定的条件列表获取许多对象,并且使用SELECT ...FROM.. WHERE... IN...
,但是IN
表达式仅接受最大为1000个项目的列表.
I'm developing an application which processes many data in Oracle database.
In some case, I have to get many object based on a given list of conditions, and I use SELECT ...FROM.. WHERE... IN...
, but the IN
expression just accepts a list whose size is maximum 1,000 items.
所以我改用OR
表达式,但是据我观察-也许此查询(使用OR
)比IN
(具有相同条件列表)要慢.这样对吗?如果可以,如何提高查询速度?
So I use OR
expression instead, but as I observe -- perhaps this query (using OR
) is slower than IN
(with the same list of condition). Is it right? And if so, how to improve the speed of query?
推荐答案
IN
比OR
更可取--OR
的性能差劲,并且可能导致其他问题,这些问题需要在复杂的查询中使用括号
IN
is preferable to OR
-- OR
is a notoriously bad performer, and can cause other issues that would require using parenthesis in complex queries.
更好的选择是连接到包含所需(或不需要)值的表.该比较表可以派生,临时或已存在于您的模式中.
Better option than either IN
or OR
, is to join to a table containing the values you want (or don't want). This table for comparison can be derived, temporary, or already existing in your schema.
这篇关于Oracle的IN vs OR,哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!