MySQL Forums
Forum List  »  Newbie

OR condition causing unnecessary lag ?
Posted by: John Tan
Date: March 19, 2023 03:54AM

i have a query to show all non-cancelled records that goes something like this

Select * from Parent,Child where Parent.ID = Child.ID
AND ( Parent_cancelled = 0 AND Child_cancelled = 0 )

- this query took 6 seconds

now i wanted to show ALL CANCELLED records even though there aren't any
and so i have made this query and expected it to complete much less than 6 sec.

Select * from Parent,Child where Parent.ID = Child.ID
AND ( Parent_cancelled = 1 OR Child_cancelled = 1 )

- BUT this query actually took 6 seconds STILL ..

so i did some experiments and changed the filter to AND Parent_cancelled = 1
- this query showed instantly

also AND Child_cancelled = 1 showed instantly because there are no cancelled records


why combining AND ( Parent_cancelled = 1 OR Child_cancelled = 1 )
is very slow ?

Options: ReplyQuote


Subject
Written By
Posted
OR condition causing unnecessary lag ?
March 19, 2023 03:54AM


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.