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.
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?
Answers. Exist is more faster than IN because IN doesn't use indexes at the time of fetching but Exist uses Index at the time of fetching.
IN operator has less complexity.. it will be faster.
The EXISTS clause is much faster than IN when the subquery results is very large. Conversely, the IN clause is faster than EXISTS when the subquery results is very small. Also, the IN clause can't compare anything with NULL values, but the EXISTSclause can compare everything with NULLs. How can we use “between” in SQL?
EXISTS Is Faster in Performance than IN.
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.
In this scenario I would do this:
This means you can leave the sort to the database and write a simple query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With