📄 index_merge.test
字号:
# index_merge on second table in joinexplain select * from t0,t1 where t0.key1 = 5 and (t1.key1 = t0.key1 or t1.key8 = t0.key1);# Fix for bug#1974explain select * from t0,t1 where t0.key1 < 3 and (t1.key1 = t0.key1 or t1.key8 = t0.key1);# index_merge inside unionexplain select * from t1 where key1=3 or key2=4 union select * from t1 where key1<4 or key3=5;# index merge in subselectexplain select * from (select * from t1 where key1 = 3 or key2 =3) as Z where key8 >5;# 12. check for long index_merges.create table t3 like t0;insert into t3 select * from t0;alter table t3 add key9 int not null, add index i9(key9);alter table t3 add keyA int not null, add index iA(keyA);alter table t3 add keyB int not null, add index iB(keyB);alter table t3 add keyC int not null, add index iC(keyC);update t3 set key9=key1,keyA=key1,keyB=key1,keyC=key1;explain select * from t3 where key1=1 or key2=2 or key3=3 or key4=4 or key5=5 or key6=6 or key7=7 or key8=8 or key9=9 or keyA=10 or keyB=11 or keyC=12; select * from t3 where key1=1 or key2=2 or key3=3 or key4=4 or key5=5 or key6=6 or key7=7 or key8=8 or key9=9 or keyA=10 or keyB=11 or keyC=12; # Test for Bug#3183explain select * from t0 where key1 < 3 or key2 < 4;select * from t0 where key1 < 3 or key2 < 4;update t0 set key8=123 where key1 < 3 or key2 < 4;select * from t0 where key1 < 3 or key2 < 4;delete from t0 where key1 < 3 or key2 < 4;select * from t0 where key1 < 3 or key2 < 4;select count(*) from t0;# Test for BUG#4177drop table t4;create table t4 (a int);insert into t4 values (1),(4),(3);set @save_join_buffer_size=@@join_buffer_size;set join_buffer_size= 4000;explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A force index(i1,i2), t0 as B force index (i1,i2) where (A.key1 < 500000 or A.key2 < 3) and (B.key1 < 500000 or B.key2 < 3);select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A force index(i1,i2), t0 as B force index (i1,i2) where (A.key1 < 500000 or A.key2 < 3) and (B.key1 < 500000 or B.key2 < 3);update t0 set key1=1;explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A force index(i1,i2), t0 as B force index (i1,i2) where (A.key1 = 1 or A.key2 = 1) and (B.key1 = 1 or B.key2 = 1);select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A force index(i1,i2), t0 as B force index (i1,i2) where (A.key1 = 1 or A.key2 = 1) and (B.key1 = 1 or B.key2 = 1);alter table t0 add filler1 char(200), add filler2 char(200), add filler3 char(200);update t0 set key2=1, key3=1, key4=1, key5=1,key6=1,key7=1 where key7 < 500;# The next query will not use index i7 in intersection if the OS doesn't # support file sizes > 2GB. (ha_myisam::ref_length depends on this and index# scan cost estimates depend on ha_myisam::ref_length)--replace_column 9 #--replace_result "4,4,4,4,4,4,4" X "4,4,4,4,4,4" X "i6,i7" "i6,i7?" "i6" "i6,i7?"explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A, t0 as B where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A, t0 as B where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);set join_buffer_size= @save_join_buffer_size;# Test for BUG#4177 ends drop table t0, t1, t2, t3, t4;# BUG#16166CREATE TABLE t1 ( cola char(3) not null, colb char(3) not null, filler char(200), key(cola), key(colb));INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ');--disable_query_loglet $1=9;while ($1){ eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo'; dec $1;}let $1=13;while ($1){ eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo'; dec $1;}--enable_query_logOPTIMIZE TABLE t1;select count(*) from t1;explain select * from t1 WHERE cola = 'foo' AND colb = 'bar';explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar';drop table t1;## BUG#17314: Index_merge/intersection not choosen by the optimizer for MERGE tables#create table t0 (a int);insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);create table t1 ( a int, b int, filler1 char(200), filler2 char(200), key(a),key(b));insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C;create table t2 like t1;create table t3 ( a int, b int, filler1 char(200), filler2 char(200), key(a),key(b)) engine=merge union=(t1,t2);--replace_column 9 #explain select * from t1 where a=1 and b=1;--replace_column 9 #explain select * from t3 where a=1 and b=1;drop table t3;drop table t0, t1, t2;## BUG#20256 - LOCK WRITE - MyISAM#CREATE TABLE t1(a INT);INSERT INTO t1 VALUES(1);CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b));INSERT INTO t2(a,b) VALUES(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(1,2);LOCK TABLES t1 WRITE, t2 WRITE;INSERT INTO t2(a,b) VALUES(1,2);SELECT t2.a FROM t1,t2 WHERE t2.b=2 AND t2.a=1;UNLOCK TABLES;DROP TABLE t1, t2;## BUG#29740: HA_KEY_SCAN_NOT_ROR wasn't set for HEAP engine# CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL, `filler` char(200) DEFAULT NULL, `b` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ENGINE=MEMORY DEFAULT CHARSET=latin1;insert into t1 values(0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9), (0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9), (10, 'filler', 10), (11, 'filler', 11), (12, 'filler', 12), (13, 'filler', 13),(14, 'filler', 14), (15, 'filler', 15), (16, 'filler', 16), (17, 'filler', 17), (18, 'filler', 18), (19, 'filler', 19), (4, '5 ', 0), (5, '4 ', 0), (4, '4 ', 0), (4, 'qq ', 5), (5, 'qq ', 4), (4, 'zz ', 4);create table t2( `a` int(11) DEFAULT NULL, `filler` char(200) DEFAULT NULL, `b` int(11) DEFAULT NULL, KEY USING BTREE (`a`), KEY USING BTREE (`b`)) ENGINE=MEMORY DEFAULT CHARSET=latin1;insert into t2 select * from t1;--echo must use sort-union rather than union:--replace_column 9 #explain select * from t1 where a=4 or b=4;--sorted_resultselect * from t1 where a=4 or b=4;--sorted_resultselect * from t1 ignore index(a,b) where a=4 or b=4;--echo must use union, not sort-union:--replace_column 9 #explain select * from t2 where a=4 or b=4;--sorted_resultselect * from t2 where a=4 or b=4;drop table t1, t2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -