Home » SQL & PL/SQL » SQL & PL/SQL » OR clause degrades performance of a query? (Oracle database, any, Linux)
OR clause degrades performance of a query? [message #670861] Mon, 30 July 2018 07:53 Go to next message
raresn
Messages: 2
Registered: July 2018
Junior Member
Hello SQL Experts,
I was digging this forum in my search for an answer, but without much luck.
Does anyone knows if under SQL the "OR" clause degrades the performance of a query?
Do we have any alternatives other than union?

I would very much appreciate an answer.

Best regards!
Re: OR clause degrades performance of a query? [message #670862 is a reply to message #670861] Mon, 30 July 2018 08:11 Go to previous messageGo to next message
cookiemonster
Messages: 13642
Registered: September 2008
Location: Rainy Manchester
Senior Member
Not in the way you're probably thinking

(col = variable OR col = other variable)
will generally take a bit longer than
col = variable
since the first has to find and retrieve more data than the second

(col = variable or variable is null)
can take a lot longer than
col = variable

since it has to scan and return everything when variable is null.

Point is adding an OR can make things slower but that's to be expected since OR generally implies more work needs to be done. There is no general way round that

If you've got a specific problem with a specific query then you should post the query and we may be able to make suggestions.
icon14.gif  Re: OR clause degrades performance of a query? [message #670863 is a reply to message #670862] Mon, 30 July 2018 08:31 Go to previous message
raresn
Messages: 2
Registered: July 2018
Junior Member
Thank you very much for the incredible fast reply!
Previous Topic: Performance of Stored Programs
Next Topic: Create JSON from SQL 12C R1
Goto Forum:
  


Current Time: Sun Jul 21 02:19:37 CDT 2019