OR condition in where clause

classic Classic list List threaded Threaded
2 messages Options
prasadbhalerao1983 prasadbhalerao1983
Reply | Threaded
Open this post in threaded view
|

OR condition in where clause

As per this doc, if the query contains OR operator indexes may not be used as expected. As a work around the query can be rewritten using UNION ALL condition.

But if I use "USE INDEX" hint to force query optimizer to use given index, will it solve the problem with OR operator?

Is it guaranteed that query optimizer will always use the index provided in "USE INDEX" hint?

Thanks,
Prasad
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: OR condition in where clause

Hello!

You can use EXPLAIN to see whether index was used or not. I suggest you to check your specific queries.

Regards,
--
Ilya Kasnacheev


вт, 2 июл. 2019 г. в 10:17, Prasad Bhalerao <[hidden email]>:
As per this doc, if the query contains OR operator indexes may not be used as expected. As a work around the query can be rewritten using UNION ALL condition.

But if I use "USE INDEX" hint to force query optimizer to use given index, will it solve the problem with OR operator?

Is it guaranteed that query optimizer will always use the index provided in "USE INDEX" hint?

Thanks,
Prasad