Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge ../10.1-mdev6402 into bb-10.1-orderby-fixes
- Loading branch information
Showing
3 changed files
with
149 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
drop table if exists t0,t1,t2,t3; | ||
# | ||
# MDEV-6402: Optimizer doesn't choose best execution plan when composite key is used | ||
# | ||
create table t0(a int); | ||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); | ||
create table t1(a int); | ||
insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; | ||
CREATE TABLE t2 ( | ||
pk1 int(11) NOT NULL, | ||
pk2 int(11) NOT NULL, | ||
fd5 bigint(20) DEFAULT NULL, | ||
filler1 char(200), | ||
filler2 char(200), | ||
PRIMARY KEY (pk1,pk2), | ||
UNIQUE KEY ux_pk1_fd5 (pk1,fd5) | ||
) ENGINE=InnoDB; | ||
insert into t2 | ||
select | ||
round(log(2,t1.a+1)), | ||
t1.a, | ||
t1.a, | ||
REPEAT('filler-data-', 10), | ||
REPEAT('filler-data-', 10) | ||
from | ||
t1; | ||
select pk1, count(*) from t2 group by pk1; | ||
pk1 count(*) | ||
0 1 | ||
1 1 | ||
2 3 | ||
3 6 | ||
4 11 | ||
5 23 | ||
6 45 | ||
7 91 | ||
8 181 | ||
9 362 | ||
10 276 | ||
# The following should use range(ux_pk1_fd5), two key parts (key_len=5+8=13) | ||
EXPLAIN SELECT * FROM t2 USE INDEX(ux_pk1_fd5) WHERE pk1=9 AND fd5 < 500 ORDER BY fd5 DESC LIMIT 10; | ||
id select_type table type possible_keys key key_len ref rows Extra | ||
1 SIMPLE t2 range ux_pk1_fd5 ux_pk1_fd5 13 NULL 137 Using where | ||
# This also must use range, not ref. key_len must be 13 | ||
EXPLAIN SELECT * FROM t2 WHERE pk1=9 AND fd5 < 500 ORDER BY fd5 DESC LIMIT 10; | ||
id select_type table type possible_keys key key_len ref rows Extra | ||
1 SIMPLE t2 range PRIMARY,ux_pk1_fd5 ux_pk1_fd5 13 NULL 137 Using where | ||
drop table t0,t1, t2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--source include/have_innodb.inc | ||
|
||
--disable_warnings | ||
drop table if exists t0,t1,t2,t3; | ||
--enable_warnings | ||
|
||
--echo # | ||
--echo # MDEV-6402: Optimizer doesn't choose best execution plan when composite key is used | ||
--echo # | ||
create table t0(a int); | ||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); | ||
|
||
create table t1(a int); | ||
insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; | ||
|
||
CREATE TABLE t2 ( | ||
pk1 int(11) NOT NULL, | ||
pk2 int(11) NOT NULL, | ||
fd5 bigint(20) DEFAULT NULL, | ||
filler1 char(200), | ||
filler2 char(200), | ||
PRIMARY KEY (pk1,pk2), | ||
UNIQUE KEY ux_pk1_fd5 (pk1,fd5) | ||
) ENGINE=InnoDB; | ||
|
||
insert into t2 | ||
select | ||
round(log(2,t1.a+1)), | ||
t1.a, | ||
t1.a, | ||
REPEAT('filler-data-', 10), | ||
REPEAT('filler-data-', 10) | ||
from | ||
t1; | ||
|
||
select pk1, count(*) from t2 group by pk1; | ||
|
||
--echo # The following should use range(ux_pk1_fd5), two key parts (key_len=5+8=13) | ||
EXPLAIN SELECT * FROM t2 USE INDEX(ux_pk1_fd5) WHERE pk1=9 AND fd5 < 500 ORDER BY fd5 DESC LIMIT 10; | ||
--echo # This also must use range, not ref. key_len must be 13 | ||
EXPLAIN SELECT * FROM t2 WHERE pk1=9 AND fd5 < 500 ORDER BY fd5 DESC LIMIT 10; | ||
|
||
drop table t0,t1, t2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters