Bug #114237 Unexpected Cardinality by Index
| Submitted: | 6 Mar 2024 6:57 | Modified: | 6 Mar 2024 8:17 |
|---|---|---|---|
| Reporter: | JINSHENG BA | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
| Version: | 8.2.0, 8.3.0 | OS: | Any |
| Assigned to: | CPU Architecture: | Any |
[6 Mar 2024 8:17]
MySQL Verification Team
Hello Jinsheng Ba, Thank you for the report and test case. Verified as described. regards, Umesh
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
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.
Description: CREATE TABLE IF NOT EXISTS t0(c0 FLOAT, c1 DOUBLE); CREATE INDEX i0 ON t0(c0); INSERT INTO t0(c0) VALUES(''), (1), (2), (3), (4), (5), (6), (7), (8), (9); INSERT INTO t0(c0) VALUES(NULL); INSERT INTO t0(c0) VALUES(10), (NULL); INSERT INTO t0(c0) VALUES(NULL), (11), (12); INSERT INTO t0(c0) VALUES(13); INSERT INTO t0(c0) VALUES(NULL); ANALYZE TABLE t0 UPDATE HISTOGRAM ON c0; EXPLAIN FORMAT=JSON SELECT t0.c0 FROM t0; -- rows_examined_per_scan: 3, rows_produced_per_join: 3 EXPLAIN FORMAT=JSON SELECT t0.c0 FROM t0 WHERE (t0.c0) IS NULL; -- rows_examined_per_scan: 4, rows_produced_per_join: 4 The second query has one more WHERE predicate than the first query, so I expect it should have a bigger estimated cardinality than the first query. If we remove the index i0, the cardinality of the second query is changed to: rows_examined_per_scan: 3, rows_produced_per_join: 1, which is expected. How to repeat: docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:8.2.0 Then execute the above test case.