| Bug #117439 | Suspicious behaviour around creation of multi-column indexes | ||
|---|---|---|---|
| Submitted: | 11 Feb 14:27 | Modified: | 12 Feb 6:46 |
| Reporter: | Emily Ong | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
| Version: | 8.0, 8.0.41, 8.4.4, 9.2.0 | OS: | Ubuntu |
| Assigned to: | CPU Architecture: | x86 | |
[11 Feb 14:27]
Emily Ong
[12 Feb 6:46]
MySQL Verification Team
Hello Emily Ong, Thank you for the report and test case. regards, Umesh
[20 Feb 13:12]
huahua xu
Hi all:
The 5th row affects the cost evaluation of covering_index_scan and group_skip_scan, so that the optimizer chooses a different physical execution plan.
mysql> explain format=tree SELECT t0.c0 AS ref0, MAX(t0.c1) AS ref1 FROM t0 WHERE (t0.c1 = 1) > 0 GROUP BY t0.c0;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| -> Group aggregate: max(t0.c1) (cost=1.05 rows=2)
-> Filter: ((t0.c1 = 1) > 0) (cost=0.65 rows=4)
-> Covering index scan on t0 using i0 (cost=0.65 rows=4)
|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
mysql> INSERT INTO t0(c0, c1) VALUES(1, 1);
mysql> explain format=tree SELECT t0.c0 AS ref0, MAX(t0.c1) AS ref1 FROM t0 WHERE (t0.c1 = 1) > 0 GROUP BY t0.c0;
+-----------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN |
+-----------------------------------------------------------------------------------------------------------------------------+
| -> Filter: ((t0.c1 = 1) > 0) (cost=1 rows=3)
-> Covering index skip scan for grouping on t0 using i0 (cost=1 rows=3)
|
+-----------------------------------------------------------------------------------------------------------------------------+
Undeniably, it is a bug.
mysql> explain format=tree SELECT t0.c0 AS ref0, MAX(t0.c1) AS ref1 FROM t0 WHERE (t0.c1 = 1) GROUP BY t0.c0;
+-------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN |
+-------------------------------------------------------------------------------------------------------------------------------------+
| -> Filter: (t0.c1 = 1) (cost=1 rows=3)
-> Covering index skip scan for grouping on t0 using i0 over (c1 = 1) (cost=1 rows=3)
|
+-------------------------------------------------------------------------------------------------------------------------------------+
It may be a solution that the predicate condition `(t0.c1 = 1) > 0` should be transformed to `t0.c1 = 1` by the predicate logic inference rules during optimizing conditions.
