| Bug #120475 | Index Merge Intersection incorrectly drops matching rows in SELECT with OR predicate, returning wrong result count | ||
|---|---|---|---|
| Submitted: | 14 May 9:09 | Modified: | 18 May 10:20 |
| Reporter: | Li Zeyan | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
| Version: | 8.0.46 | OS: | Linux |
| Assigned to: | CPU Architecture: | Any | |
[14 May 9:09]
Li Zeyan
[14 May 10:21]
Li Zeyan
The minimal reproduction sql for this bug
Attachment: min_mysql_index_merge_intersect_repro.sql (application/octet-stream, text), 16.35 KiB.
[14 May 10:28]
Li Zeyan
Update on possible root cause & Minimal reproduction SQL
PLEASE use the attachment SQL file (min_mysql_index_merge_intersect_repro.sql) to reproduce the bug. The SQL in "How to repeat" failed to reproduce the bug. I apologize for the mistake.
After further investigation, I want to update my discovery on the possible root cause:
The optimizer performs an "Intersect rows sorted by row ID" on TWO indexes both covering c2 (i83 and hash_idx_3119), which incorrectly reduces the 2 matching rows for c2 = 0.7559466140838738 down to 1 row. The intersect step is meant to find rows that appear in both index scans for the same condition, but it wrongly deduplicates two distinct rows that happen to share the same c2 value into one. This deduplicated result is then unioned with the c7 index scan result, yielding 2 rows total instead of the correct 3.
The EXPLAIN output shows:
-> Filter: ((t.c2 = 0.7559466140838738) or (t.c7 = 287496496))
-> Deduplicate rows sorted by row ID
-> Intersect rows sorted by row ID
-> Index range scan on t using i83 over (c2 = 0.7559466140838738)
-> Index range scan on t using hash_idx_3119 over (c2 = 0.7559466140838738)
-> Covering index range scan on t using i95 over (c7 = 287496496)
Note: Both i83 and hash_idx_3119 scans find 2 matching rows, but the Intersect step incorrectly reduces them to 1 row.
[18 May 10:20]
Roy Lyseng
Thank you for the bug report. Verified as described.
