Re: Slow query
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
Subject
Views
Written By
Posted
1884
December 11, 2015 01:00PM
881
December 11, 2015 05:00PM
844
December 11, 2015 06:56PM
789
December 12, 2015 07:34AM
Re: Slow query
886
December 14, 2015 02:34AM
717
December 15, 2015 08:48AM
778
December 15, 2015 10:57AM
901
December 16, 2015 02:33AM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
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.