Recently when I come across some slow queries, I have seen this "Using sort_union(sourceClass,destinationClass)" phrase in the EXPLAIN plan.
When I run the EXPLAIN with the same query with FORCE INDEX of each index separately, I saw it is doing almost the full table scan due to data distribution.
I understood that this is to improve the performance and this decision is taken by the query optimizer only.
In my query the keys and query are like this
sourceClass: KEY (`sourceClass`,`sourceId`,`kind`)
destinationClass: KEY (`destinationClass`,`destinationId`,`kind`),
query:
WHERE (sourceClass='channel' && sourceId=1016) || (destinationClass='channel'
&& destinationId=1016)
I would like to know at what when the optimizer comes to choose this and are there any disadvantages due to this kind of finding results ?