Bug #87641 | Execution plan differs after upgrade to 5.7 | ||
---|---|---|---|
Submitted: | 1 Sep 2017 14:20 | Modified: | 6 Sep 2017 15:47 |
Reporter: | KORBULY Francois | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 5.6.33 / 5.7.18 | OS: | CentOS (6 (x86_64)) |
Assigned to: | CPU Architecture: | Any | |
Tags: | execution plan;difference;5.6;5.7 |
[1 Sep 2017 14:20]
KORBULY Francois
[1 Sep 2017 14:27]
KORBULY Francois
Create tables SQL
Attachment: Bug_87641_table_structure.txt (text/plain), 3.94 KiB.
[4 Sep 2017 7:18]
Øystein Grøvlen
In order to be able to analyze your issue, it would be helpful if you could provide optimizer for both 5.6 and 5.7. (For instructions on how to obtain such trace, see http://oysteing.blogspot.co.uk/2016/01/how-to-get-optimizer-trace-for-query.html) I also suggest to see if the following variant performs better: SELECT DISTINCT sa.attribute FROM sample_attribute sa WHERE sa.sample_id IN (SELECT s.id FROM sample s JOIN sample_kind sk ON (sk.id = s.sample_kind_id) WHERE sk.category = 'physiological') ORDER BY sa.attribute
[5 Sep 2017 15:39]
KORBULY Francois
Query optimizer trace on 5.6 Mysql server
Attachment: optimizer_trace_5.6.txt (text/plain), 19.89 KiB.
[5 Sep 2017 15:39]
KORBULY Francois
Query optimizer trace on 5.7 Mysql server
Attachment: optimizer_trace_5.7.txt (text/plain), 16.89 KiB.
[5 Sep 2017 15:45]
KORBULY Francois
Hi Øystein, Thanks for your answer. Please find the 2 traces in files for our query on both servers. Also, I gave a try with your suggested query. Execution time on 5.6 : 29 sec Execution time on 5.7 : 17 sec Let me know if you'd like to have optimizer trace for you suggested query on both servers, if it can help. I wish you a nice day, Francois
[6 Sep 2017 15:47]
Øystein Grøvlen
Looking at the optimizer trace, it seems that the cause for the change in query plan is the fix to Bug#83005: "When the Optimiser is using index for group-by it often gives wrong results." This bug was fixed in 5.6.36 and 5.7.18. Hence, you should be able to see the performance regression also in later versions of 5.6. AFAICT, also the query discussed here may give wrong result with the old query plan. "Using index for group-by" means that MySQL will only check the one row for each value of sa.attribute. If this row happens to be for a sample that is not of a "physiological" kind, this attribute value will not be part of the result even if there are other samples for this attribute value that are in the requested category. In other words, the change in query plan is intentional since the old plan is not guaranteed to give correct results.