Query in MySQL 5.0 uses index merge but MariaDB does a full table scan
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Won't Fix
|
Medium
|
Igor Babaev |
Bug Description
The following query in MySQL 5.0.72sp1 correctly uses the index_merge optimization and executes in less than a second. On MariaDB it doesn't use the index_merge optimization and instead does a full scan of t3. The attached file fast_in_
SELECT
*
FROM t1
LEFT JOIN t2 /* use index (primary, c3) */
ON t2.c2 = t1.c2
LEFT JOIN t3
ON t2.c1 = t3.c1
WHERE
((t2.c2 <=> 182104825 OR t2.c3 <=> 182104825)) AND
(t3.c1 IS NOT NULL)
Explain output from MariaDB:
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | t3 | index | PRIMARY | PRIMARY | 8 | NULL | 99879 | Using where; Using index |
| 1 | SIMPLE | t2 | ref | PRIMARY,c1,c3 | c1 | 9 | test2.t3.c1 | 1 | Using where |
| 1 | SIMPLE | t1 | ref | c2 | c2 | 9 | test2.t2.c2 | 1 | Using where; Using index |
+----+-
3 rows in set (0.01 sec)
Desired explain output from MySQL:
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | t2 | index_merge | PRIMARY,c1,c3 | PRIMARY,c3 | 8,8 | NULL | 2 | Using union(PRIMARY,c3); Using where |
| 1 | SIMPLE | t3 | eq_ref | PRIMARY | PRIMARY | 8 | test2.t2.c1 | 1 | Using where; Using index |
| 1 | SIMPLE | t1 | ref | c2 | c2 | 9 | test2.t2.c2 | 1 | Using where; Using index |
+----+-
3 rows in set (0.00 sec)
Changed in maria: | |
assignee: | nobody → Igor Babaev (igorb-seattle) |
milestone: | none → 5.2 |
Changed in maria: | |
importance: | Undecided → Medium |
Repeatable in maria-5.1 as described above. The default plan does not use index merge and takes 2.5 seconds. The USE INDEX plan uses index_merge and takes 0.01 seconds.
Not repeatable in mysql 5.1.58 . The default plan there uses index_merge and completes in 0.01 seconds.