Commit 424a7a26 authored by Monty's avatar Monty

Fixed randomly failing test main.order_by_optimizer_innodb

The problem was that sometimes InnoDB returned sligtly wrong record count
for table, which causes the optimizer to disregard the result from
the range optimizer. The end result was that the optimizer choosed a
ref access instead of a range access which caused errors in buildbot.

Fixed by adding more rows to the table to ensure that table scan is
more costly than range scan of the given interval.
parent 6e9b421f
......@@ -2,10 +2,6 @@ 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,
......@@ -17,13 +13,13 @@ UNIQUE KEY ux_pk1_fd5 (pk1,fd5)
) ENGINE=InnoDB;
insert into t2
select
round(log(2,t1.a+1)),
t1.a,
t1.a,
round(log(2,seq+1)),
seq,
seq,
REPEAT('filler-data-', 10),
REPEAT('filler-data-', 10)
from
t1;
seq_0_to_1999;
select pk1, count(*) from t2 group by pk1;
pk1 count(*)
0 1
......@@ -36,7 +32,8 @@ pk1 count(*)
7 91
8 181
9 362
10 276
10 724
11 552
# 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
......@@ -45,7 +42,7 @@ id select_type table type possible_keys key key_len ref rows Extra
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 138 Using where
drop table t0,t1, t2;
drop table t2;
#
# MDEV-6814: Server crashes in calculate_key_len on query with ORDER BY
#
......
--source include/have_innodb.inc
--source include/have_sequence.inc
--disable_warnings
drop table if exists t0,t1,t2,t3;
......@@ -7,11 +8,6 @@ drop table if exists t0,t1,t2,t3;
--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,
......@@ -25,13 +21,13 @@ CREATE TABLE t2 (
insert into t2
select
round(log(2,t1.a+1)),
t1.a,
t1.a,
round(log(2,seq+1)),
seq,
seq,
REPEAT('filler-data-', 10),
REPEAT('filler-data-', 10)
from
t1;
seq_0_to_1999;
select pk1, count(*) from t2 group by pk1;
......@@ -40,7 +36,7 @@ EXPLAIN SELECT * FROM t2 USE INDEX(ux_pk1_fd5) WHERE pk1=9 AND fd5 < 500 ORDER B
--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;
drop table t2;
--echo #
--echo # MDEV-6814: Server crashes in calculate_key_len on query with ORDER BY
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment