MySQL Forums
Forum List  »  Performance

Re: Slow query
Posted by: Øystein Grøvlen
Date: December 14, 2015 02:34AM

Hi,

As Rick writes, MySQL can not use index when join condition contains OR and you need to rewrite.

Another issue I would like to point out is that in MySQL 5.6 and later, the query optimizer is be better at optimizing IN expressions than EXISTS expressions. Hence, the best practice is to write your query as:

SELECT * FROM clients
WHERE clients.client_id IN (SELECT archive.seller FROM archive)
OR clients.client_id IN (SELECT archive.buyer FROM archive);

In this particular case the performance will probably be the same, but in other cases there might be a significant difference.

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote


Subject
Views
Written By
Posted
1778
December 11, 2015 01:00PM
809
December 11, 2015 05:00PM
807
December 11, 2015 06:56PM
705
December 12, 2015 07:34AM
Re: Slow query
814
December 14, 2015 02:34AM
670
December 15, 2015 08:48AM
737
December 15, 2015 10:57AM
838
December 16, 2015 02:33AM


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.