We had the same problem and it was resolved by dividing it into 100-sided IN offer packages
select * from mytable where id in (...) or id in (...).
Notes:
- make sure you use bind variables
- make sure the query always looks the same. This is done by filling in the IN articles with -1 until there are 100 elements in it.
- try to always use the same amount of ORed in (...) so that the query always looks the same
Why do you want the items above? This means that the query optimizer can reuse the query plan.
Additional optimization:
- instead of using -1, you can just use the last true value again. It is even a little better.
example: in (1, 2, 3, 4, 4, ..., 4)
Please note: we tested with different fixed element numbers in the in section and observed a performance degradation for more than 100 elements.
Patrick hammer
source share