MySQL Forums
Forum List  »  Newbie

WHERE OR performance issue
Posted by: Lee Fear
Date: March 30, 2012 03:33AM

I have two sql statements which achieve the same thing but have vastly different performance and I was just wondering why this is.

The first statement is as follows.

FROM tbl_sectordistances
WHERE (destinationsectorid=300 AND distance<=20) OR (originsectorid=300 AND distance<=20);

I end up aborting this query after around 4 or 5 mins as I get fed up of waiting.

However the other statement is as follows

FROM tbl_sectordistances
WHERE (destinationsectorid=300 AND distance<=20)
FROM tbl_sectordistances
WHERE (ORIGINSECTORID=300 AND distance<=20);

this returns the results in less than 1/4 or a second!

Why does the OR statement hit the performance so hard?

Options: ReplyQuote

Written By
WHERE OR performance issue
March 30, 2012 03:33AM
March 30, 2012 05:43AM
March 30, 2012 09:02AM
March 30, 2012 09:03AM
March 30, 2012 09:05AM
March 30, 2012 09:38AM
March 30, 2012 12:51PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.