Bug #112362 | WHERE NOT IN with subquery is much slower on 8.1 than 5.7 | ||
---|---|---|---|
Submitted: | 15 Sep 2023 20:19 | Modified: | 19 Dec 2024 21:44 |
Reporter: | Bradley Grainger (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 8.1.0, 8.0.34 | OS: | Ubuntu (22.04) |
Assigned to: | CPU Architecture: | x86 | |
Tags: | regression |
[15 Sep 2023 20:19]
Bradley Grainger
[19 Sep 2023 11:27]
MySQL Verification Team
Hi Mr. Grainger, Thank you for your bug report. However, there are literally hundreds of bug reports , which show significant slowdown for the read or write DMLs between 5.7 and 8.0/8.1. This is a widely known fact. We have found these bugs in this forum that show that behaviour: https://bugs.mysql.com/bug.php?id=94387, https://bugs.mysql.com/bug.php?id=93734, https://bugs.mysql.com/bug.php?id=94283 However, we have found one bug, with exactly WHERE NOT IN, but this is an internally reported bug, which is not visible to you. Hence, the performance degradation from 5.7 to 8.0 / 8.1 is very well known fact. Duplicate.
[25 Sep 2023 14:12]
MySQL Verification Team
Hello Bradley Grainger, Thank you for the report and test case. Verified as described. regards, Umesh
[25 Sep 2023 14:13]
MySQL Verification Team
Test results - 8.0.11+, 5.7.43
Attachment: Bug112362_5.7.43_8.0.11_8.0.34_8.1.0.txt (text/plain), 18.09 KiB.
[26 Sep 2023 10:34]
Roy Lyseng
Posted by developer: Pretty strange nobody have noticed this regression before. The "problem" with semi-join and anti-join is that it converts a single-table query into a multi-table query, by dragging in the subquery tables, and the index range scan algorithm is only implemented for single-table queries. Until this has been fixed, there is a simple workaround that you can try: disable semi-join (and anti-join) conversion by this command: set optimizer_switch='semijoin=off'; or use the equivalent query hint.
[19 Dec 2024 21:44]
Jon Stephens
Documented fix as follows in the MySQL 8.0.41, 8.4.4, and 9.2.0 changelogs: In MySQL 8.0 and later, queries of the form SELECT DISTINCT ... FROM t1 WHERE NOT IN(SELECT ...) were transformed into an antijoin if possible, causing the optimizer not to choose a group skip scan for table t1 whereas it would have been chosen in MySQL 5.7. This resulted in a performance degradation for such queries. Group skip scan is not chosen, since the query is now no longer a single-table query following the antijoin transformation, and this access method is enabled only for single table queries. The same behaviour can be seen for queries which are transformed into semijoins as well. In such cases, group skip scan access method can still be used if the access method is used only for duplicate removal (that is, DISTINCT or GROUP BY without aggregate functions). To fix this, we enable group skip scan when there is only one table in the original query, irrespective of the number of semijoin tables present after internal transformations as long as the query contains no aggregate functions. Closed.
[20 Dec 2024 10:45]
MySQL Verification Team
Thank you, Jon.