Skip to content

Commit

Permalink
index_merge_innodb did sometimes give wrong results
Browse files Browse the repository at this point in the history
Fixed by adding more rows to a table

Other things:
- Speed up index_merge tests 20% by adding begin/commit around loops that
  generated rows.
  • Loading branch information
montywi authored and dr-m committed Apr 4, 2019
1 parent 6a9b216 commit 71a2e6a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mysql-test/include/index_merge1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);

let $1=7;
set @d=8;
begin;
while ($1)
{
eval insert into t0 select key1+@d from t0;
eval set @d=@d*2;
dec $1;
}
commit;
--enable_query_log

alter table t0 add key2 int not null, add index i2(key2);
Expand Down Expand Up @@ -360,6 +362,7 @@ INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ');

--disable_query_log
let $1=9;
begin;
while ($1)
{
eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo';
Expand All @@ -372,6 +375,7 @@ while ($1)
eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo';
dec $1;
}
commit;

--enable_query_log

Expand Down
8 changes: 8 additions & 0 deletions mysql-test/include/index_merge2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ create table t1

--disable_query_log
let $1=200;
begin;
while ($1)
{
eval insert into t1 values (200-$1, $1);
dec $1;
}
commit;
--enable_query_log

# No primary key
Expand Down Expand Up @@ -80,11 +82,13 @@ create table t1 (
show warnings;
--disable_query_log
let $1=30;
begin;
while ($1)
{
eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data');
dec $1;
}
commit;
--enable_query_log
explain select pk from t1 where key1 = 1 and key2 = 1;
select pk from t1 where key2 = 1 and key1 = 1;
Expand Down Expand Up @@ -331,16 +335,20 @@ insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);

let $1=7;
set @d=8;
begin;
while ($1)
{
eval insert into t1 (key1) select key1+@d from t1;
eval set @d=@d*2;
dec $1;
}
commit;

alter table t1 add index i2(key2);
alter table t1 add index i3(key3);
update t1 set key2=key1,key3=key1;

insert into t1 select 10000+key1, 10000+key2,10000+key3 from t1;
analyze table t1;

# to test the bug, the following must use "sort_union":
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/include/index_merge_2sweeps.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ create table t1 (


--disable_query_log
begin;
let $1=1000;
while ($1)
{
eval insert into t1 values($1, $1, $1, 'filler-data','filler-data-2');
dec $1;
}
commit;
--enable_query_log

select * from t1 where (key1 >= 2 and key1 <= 10) or (pk >= 4 and pk <=8 );
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/include/index_merge_ror.inc
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ create table t1
create table t0 as select * from t1;
--disable_query_log
--echo # Printing of many insert into t0 values (....) disabled.
begin;
let $cnt=1000;
while ($cnt)
{
eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
dec $cnt;
}
commit;
--enable_query_log

alter table t1 disable keys;
--disable_query_log
--echo # Printing of many insert into t1 select .... from t0 disabled.
let $1=4;
begin;
while ($1)
{
let $2=4;
Expand All @@ -94,13 +97,15 @@ while ($1)
}
dec $1;
}
commit;

--echo # Printing of many insert into t1 (...) values (....) disabled.
# Row retrieval tests
# -1 is used for values 'out of any range we are using'
# insert enough rows for index intersection to be used for (key1,key2)
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4');
let $cnt=400;
begin;
while ($cnt)
{
eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
Expand All @@ -112,6 +117,7 @@ while ($cnt)
eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
dec $cnt;
}
commit;
--enable_query_log
alter table t1 enable keys;
select count(*) from t1;
Expand Down Expand Up @@ -249,13 +255,15 @@ create table t2 (

--disable_query_log
let $1=8;
begin;
while ($1)
{
eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2');
dec $1;
}
insert into t2 select * from t2;
insert into t2 select * from t2;
commit;
--enable_query_log

# The table row buffer is reused. Fill it with rows that don't match.
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/include/index_merge_ror_cpk.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ create table t1
);

--disable_query_log
set autocommit=0;
begin;
let $1=10000;
while ($1)
{
eval insert into t1 values ($1 div 10,$1 mod 100, $1/100,$1/100, $1/100,$1/100,$1/100,$1/100,$1/100, $1 mod 100, $1/1000,'filler-data-$1','filler2');
dec $1;
}
set autocommit=1;
commit;
--enable_query_log

# Verify that range scan on CPK is ROR
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/r/index_merge_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ key3 int not null default 0
);
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
set @d=8;
begin;
insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
insert into t1 (key1) select key1+@d from t1;
Expand All @@ -308,9 +309,11 @@ insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
commit;
alter table t1 add index i2(key2);
alter table t1 add index i3(key3);
update t1 set key2=key1,key3=key1;
insert into t1 select 10000+key1, 10000+key2,10000+key3 from t1;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
Expand Down Expand Up @@ -672,6 +675,7 @@ a int,
b int,
INDEX idx(a))
ENGINE=INNODB;
begin;
INSERT INTO t1(a,b) VALUES
(11, 1100), (2, 200), (1, 100), (14, 1400), (5, 500),
(3, 300), (17, 1700), (4, 400), (12, 1200), (8, 800),
Expand All @@ -691,6 +695,7 @@ INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1 VALUES (1000000, 0, 0);
commit;
SET SESSION sort_buffer_size = 1024*36;
set @tmp_optimizer_switch=@@optimizer_switch;
set optimizer_switch='derived_merge=off,derived_with_keys=off';
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/r/index_merge_myisam.result
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ key3 int not null default 0
);
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
set @d=8;
begin;
insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
insert into t1 (key1) select key1+@d from t1;
Expand All @@ -1143,9 +1144,11 @@ insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
insert into t1 (key1) select key1+@d from t1;
set @d=@d*2;
commit;
alter table t1 add index i2(key2);
alter table t1 add index i3(key3);
update t1 set key2=key1,key3=key1;
insert into t1 select 10000+key1, 10000+key2,10000+key3 from t1;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/t/index_merge_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CREATE TABLE t1 (
INDEX idx(a))
ENGINE=INNODB;

begin;
INSERT INTO t1(a,b) VALUES
(11, 1100), (2, 200), (1, 100), (14, 1400), (5, 500),
(3, 300), (17, 1700), (4, 400), (12, 1200), (8, 800),
Expand All @@ -65,6 +66,7 @@ INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1(a,b) SELECT a,b FROM t1;
INSERT INTO t1 VALUES (1000000, 0, 0);
commit;

SET SESSION sort_buffer_size = 1024*36;
set @tmp_optimizer_switch=@@optimizer_switch;
Expand Down

0 comments on commit 71a2e6a

Please sign in to comment.