Unexpected index condition pushdown behaviour on range queries with InnoDB plugin
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
New
|
Undecided
|
Unassigned |
Bug Description
MariaDB version >= 5.5.23 does not use index condition pushdown for range query, when it should.
I have tested it with both 5.5.23 and 5.5.27. The same query when run against MySQL 5.6.6-m9 and MariaDB 5.3.5 results in index condition pushdown being used.
-- Test case:
CREATE TABLE `icp_test` (
`i` int(11) NOT NULL,
`k` int(11) NOT NULL,
`v` char(32) DEFAULT NULL,
KEY `k` (`k`,`i`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SOURCE icp_test.dump
EXPLAIN SELECT * FROM icp_test WHERE k BETWEEN 4000 AND 5000 AND i < 1000 ORDER BY k ASC LIMIT 10\G
The data to use with the table is attached with this bug report.
Explain output is seen on MariaDB 5.5.27:
MariaDB [test]> explain select * from icp_test where k between 4000 and 5000 and i < 1000 order by k asc limit 10\G
*******
id: 1
select_type: SIMPLE
table: icp_test
type: range
possible_keys: k
key: k
key_len: 8
ref: NULL
rows: 222436
Extra: Using where
1 row in set (0.00 sec)
Explain output as seen on MySQL 5.6.6-m9:
mysql> explain select sql_no_cache * from icp_test where k between 4000 and 5000 and i < 1000 order by k asc limit 10\G
*******
id: 1
select_type: SIMPLE
table: icp_test
type: range
possible_keys: k
key: k
key_len: 8
ref: NULL
rows: 222436
Extra: Using index condition
1 row in set (0.00 sec)
Explain output as seen on MariaDB 5.3.5:
MariaDB [test]> explain select sql_no_cache * from icp_test where k between 4000 and 5000 and i < 1000 order by k asc limit 10\G
*******
id: 1
select_type: SIMPLE
table: icp_test
type: range
possible_keys: k
key: k
key_len: 8
ref: NULL
rows: 223490
Extra: Using index condition
1 row in set (0.00 sec)
This obviously means that the above query executes slowly on MariaDB 5.5.27.
The query times on MariaDB 5.3.5 and MySQL 5.6.6-m9:
+-----+
| i | k | v |
+-----+
| 162 | 4010 | 0fcaae4367d0090
| 729 | 4016 | 8b52c5ceff7638e
| 370 | 4032 | 7235547a596a1db
| 707 | 4035 | 7f55c7c738ed3b5
| 645 | 4047 | e265b948627662a
| 757 | 4051 | 9cdd8a926d21433
| 572 | 4100 | f3daf307a688940
| 89 | 4143 | 2cf9585a3ec9803
| 321 | 4184 | 4fbc60b0aa1ebb5
| 751 | 4185 | 0d47c6f6f50b78f
+-----+
10 rows in set (0.00 sec)
The query time on MariaDB 5.5.27:
+-----+
| i | k | v |
+-----+
| 162 | 4010 | 0fcaae4367d0090
| 729 | 4016 | 8b52c5ceff7638e
| 370 | 4032 | 7235547a596a1db
| 707 | 4035 | 7f55c7c738ed3b5
| 645 | 4047 | e265b948627662a
| 757 | 4051 | 9cdd8a926d21433
| 572 | 4100 | f3daf307a688940
| 89 | 4143 | 2cf9585a3ec9803
| 321 | 4184 | 4fbc60b0aa1ebb5
| 751 | 4185 | 0d47c6f6f50b78f
+-----+
10 rows in set (0.73 sec)
This is because MariaDB 5.5.27 is reading more data (Handler_read_* = 19328), while MySQL 5.6.6-m9 and MariaDB 5.3.5 are reading far fewer data (Handler_read_* = 10)
Hi,
I'm getting ICP with your test case (tried 5.5.27 which is the latest 5.5 release):
MariaDB [test]> CREATE TABLE `icp_test` (
-> `i` int(11) NOT NULL,
-> `k` int(11) NOT NULL,
-> `v` char(32) DEFAULT NULL,
-> KEY `k` (`k`,`i`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.12 sec)
MariaDB [test]> SOURCE icp_test.dump;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.05 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.07 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 21539 rows affected (0.93 sec)
Records: 21539 Duplicates: 0 Warnings: 0
Query OK, 21405 rows affected (0.89 sec)
Records: 21405 Duplicates: 0 Warnings: 0
Query OK, 21405 rows affected (1.27 sec)
Records: 21405 Duplicates: 0 Warnings: 0
Query OK, 21000 rows affected (0.91 sec)
Records: 21000 Duplicates: 0 Warnings: 0
Query OK, 20977 rows affected (1.40 sec)
Records: 20977 Duplicates: 0 Warnings: 0
Query OK, 20975 rows affected (1.22 sec)
Records: 20975 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.21 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (0.94 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20974 rows affected (1.23 sec)
Records: 20974 Duplicates: 0 Warnings: 0
Query OK, 20975 rows affected (1.89 sec)
Records: 20975 Duplicates: 0 Warnings: 0
Query OK, 20975 rows affected (1.68 sec)
Records: 20975 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.22 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20977 rows affected (1.39 sec)
Records: 20977 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.54 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20977 rows affected (1.74 sec)
Records: 20977 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (0.99 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20977 rows affected (1.34 sec)
Records: 20977 Duplicates: 0 Warnings: 0
Query OK, 20978 rows affected (1.99 sec)
Records: 20978 Duplicates: 0 Warnings: 0
Query OK, 20975 rows affected (2.26 sec)
Records: 20975 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.35 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20975 rows affected (2.18 sec)
Records: 20975 Duplicates: 0 Warnings: 0
Query OK, 20979 rows affected (1.67 sec)
Records: 20979 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.80 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20977 rows affected (1.27 sec)
Records: 20977 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (1.94 sec)
Records: 20976 Duplicates: 0 Warnings: 0
Query OK, 20976 rows affected (2.09 sec)
Record...