[MDEV-2628] LP:1000051 - Query with simple join and ORDER BY takes thousands times longer when run with ICP Created: 2012-05-16 Updated: 2015-02-02 Resolved: 2012-10-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
Initially reported in the knowledge base: http://kb.askmonty.org/en/index-pushdown-bug-or-side-effect The following query SELECT SQL_NO_CACHE * takes much longer when it's run with index_condition_pushdown=on (current default) than without it. bzr version-info Also reproducible on MariaDB 5.5 (revno 3403) and MySQL trunk (revno 3827). EXPLAIN: id select_type table type possible_keys key key_len ref rows filtered Extra Full optimizer_switch:
CREATE TABLE A ( LOAD DATA LOCAL INFILE 'A.data' INTO TABLE A; CREATE TABLE B ( INSERT INTO B VALUES SELECT SQL_NO_CACHE *
|
| Comments |
| Comment by Elena Stepanova [ 2012-05-16 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP |
| Comment by Elena Stepanova [ 2012-05-16 ] |
|
data file for the test case |
| Comment by Elena Stepanova [ 2012-05-16 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP |
| Comment by Sergei Petrunia [ 2012-05-18 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP The problem is caused by a combination of
h->ha_index_read_map( ..., HA_READ_PREFIX_LAST); When we enter index_prev() call, we don't know where we should stop scanning (that is, SQL layer and join_read_prev_same() knows that we're only interested in records with t.key=const, but this information is not passed down the storage engine). The storage engine starts walking the index in reverse direction. If all index tuples fail the index condition, it will continue walking until it reaches the start of the index. We don't get this problem with normal index scans, because they make these calls: We also don't get this problem with forward range non-equality scans because we use read_range_first()/read_range_next() functions which set h->end_range which is checked by the ICP function. I'll need to check what happens with reverse range scans. |
| Comment by Sergei Petrunia [ 2012-05-18 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP |
| Comment by Elena Stepanova [ 2012-06-24 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP |
| Comment by Rasmus Johansson (Inactive) [ 2012-09-18 ] |
|
Launchpad bug id: 1000051 |
| Comment by Ovais Tariq [ 2012-09-18 ] |
|
Re: Query with simple join and ORDER BY takes thousands times longer when run with ICP MariaDB 5.5.23 EXPLAIN output:
MariaDB [test]> EXPLAIN SELECT SQL_NO_CACHE * FROM A, B WHERE b1 = a1 AND a3 = "3" ORDER BY a2 ASC\G
MySQL 5.6.6-m9 EXPLAIN output:
mysql> EXPLAIN SELECT SQL_NO_CACHE * FROM A, B WHERE b1 = a1 AND a3 = "3" ORDER BY a2 ASC\G
|