📄 merge.result
字号:
KEY `a` (`a`,`b`)) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`,`t3`)select * from t4 order by a,b;a b1 11 21 31 42 12 22 32 43 13 23 33 45 15 26 16 2alter table t4 INSERT_METHOD=FIRST;show create table t4;Table Create Tablet4 CREATE TABLE `t4` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, KEY `a` (`a`,`b`)) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=FIRST UNION=(`t1`,`t2`,`t3`)insert into t4 values (4,1),(4,2);select * from t1 order by a,b;a b1 11 21 31 44 14 25 15 2select * from t2 order by a,b;a b2 12 22 32 46 16 2select * from t3 order by a,b;a b3 13 23 33 4select * from t4 order by a,b;a b1 11 21 31 42 12 22 32 43 13 23 33 44 14 25 15 26 16 2select * from t5 order by a,b;a b1 11 21 31 42 12 22 32 44 14 25 15 26 16 2select 1;11insert into t5 values (1,NULL),(5,NULL);insert into t6 values (2,NULL),(6,NULL);select * from t1 order by a,b;a b1 11 21 31 41 54 14 25 15 25 3select * from t2 order by a,b;a b2 12 22 32 42 56 16 26 3select * from t5 order by a,b;a b1 11 21 31 41 52 12 22 32 42 54 14 25 15 25 36 16 26 3select * from t6 order by a,b;a b1 11 21 31 41 52 12 22 32 42 54 14 25 15 25 36 16 26 3insert into t1 values (99,NULL);select * from t4 where a+0 > 90;a b99 1insert t5 values (1,1);ERROR 23000: Duplicate entry '1-1' for key 1insert t6 values (2,1);ERROR 23000: Duplicate entry '2-1' for key 1insert t5 values (1,1) on duplicate key update b=b+10;insert t6 values (2,1) on duplicate key update b=b+20;select * from t5 where a < 3;a b1 21 31 41 51 112 22 32 42 52 21drop table t6, t5, t4, t3, t2, t1;CREATE TABLE t1 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) ENGINE=MyISAM;INSERT INTO t1 VALUES (1,1), (2,1);CREATE TABLE t2 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) ENGINE=MyISAM;INSERT INTO t2 VALUES (1,2), (2,2);CREATE TABLE t3 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', KEY a (a,b)) ENGINE=MRG_MyISAM UNION=(t1,t2);select max(b) from t3 where a = 2;max(b)2select max(b) from t1 where a = 2;max(b)1drop table t3,t1,t2;create table t1 (a int not null);create table t2 (a int not null);insert into t1 values (1);insert into t2 values (2);create temporary table t3 (a int not null) ENGINE=MERGE UNION=(t1,t2);select * from t3;a12create temporary table t4 (a int not null);create temporary table t5 (a int not null);insert into t4 values (1);insert into t5 values (2);create temporary table t6 (a int not null) ENGINE=MERGE UNION=(t4,t5);select * from t6;a12drop table t6, t3, t1, t2, t4, t5;CREATE TABLE t1 (fileset_id tinyint(3) unsigned NOT NULL default '0',file_code varchar(32) NOT NULL default '',fileset_root_id tinyint(3) unsigned NOT NULL default '0',PRIMARY KEY (fileset_id,file_code),KEY files (fileset_id,fileset_root_id)) ENGINE=MyISAM;INSERT INTO t1 VALUES (2, '0000000111', 1), (2, '0000000112', 1), (2, '0000000113', 1),(2, '0000000114', 1), (2, '0000000115', 1), (2, '0000000116', 1), (2, '0000000117', 1),(2, '0000000118', 1), (2, '0000000119', 1), (2, '0000000120', 1);CREATE TABLE t2 (fileset_id tinyint(3) unsigned NOT NULL default '0',file_code varchar(32) NOT NULL default '',fileset_root_id tinyint(3) unsigned NOT NULL default '0',PRIMARY KEY (fileset_id,file_code),KEY files (fileset_id,fileset_root_id)) ENGINE=MRG_MyISAM UNION=(t1);EXPLAIN SELECT * FROM t2 IGNORE INDEX (files) WHERE fileset_id = 2AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 range PRIMARY PRIMARY 35 NULL 5 Using whereEXPLAIN SELECT * FROM t2 WHERE fileset_id = 2AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 range PRIMARY,files PRIMARY 35 NULL 5 Using whereEXPLAIN SELECT * FROM t1 WHERE fileset_id = 2AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range PRIMARY,files PRIMARY 35 NULL 5 Using whereEXPLAIN SELECT * FROM t2 WHERE fileset_id = 2AND file_code = '0000000115' LIMIT 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref PRIMARY,files PRIMARY 35 const,const 1 Using whereDROP TABLE t2, t1;create table t1 (x int, y int, index xy(x, y));create table t2 (x int, y int, index xy(x, y));create table t3 (x int, y int, index xy(x, y)) engine=merge union=(t1,t2);insert into t1 values(1, 2);insert into t2 values(1, 3);select * from t3 where x = 1 and y < 5 order by y;x y1 21 3select * from t3 where x = 1 and y < 5 order by y desc;x y1 31 2drop table t1,t2,t3;create table t1 (a int);create table t2 (a int);insert into t1 values (0);insert into t2 values (1);create table t3 engine=merge union=(t1, t2) select * from t1;ERROR HY000: You can't specify target table 't1' for update in FROM clausecreate table t3 engine=merge union=(t1, t2) select * from t2;ERROR HY000: You can't specify target table 't2' for update in FROM clausecreate table t3 engine=merge union=(t1, t2) select (select max(a) from t2);ERROR HY000: You can't specify target table 't2' for update in FROM clausedrop table t1, t2;create table t1 (a double(14,4),b varchar(10),index (a,b)) engine=merge union=(t2,t3);create table t2 (a double(14,4),b varchar(10),index (a,b)) engine=myisam;create table t3 (a double(14,4),b varchar(10),index (a,b)) engine=myisam;insert into t2 values ( null, '');insert into t2 values ( 9999999999.999, '');insert into t3 select * from t2;select min(a), max(a) from t1;min(a) max(a)9999999999.9990 9999999999.9990flush tables;select min(a), max(a) from t1;min(a) max(a)9999999999.9990 9999999999.9990drop table t1, t2, t3;create table t1 (a int,b int,c int, index (a,b,c));create table t2 (a int,b int,c int, index (a,b,c));create table t3 (a int,b int,c int, index (a,b,c))engine=merge union=(t1 ,t2);insert into t1 (a,b,c) values (1,1,0),(1,2,0);insert into t2 (a,b,c) values (1,1,1),(1,2,1);explain select a,b,c from t3 force index (a) where a=1 order by a,b,c;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t3 ref a a 5 const 2 Using where; Using indexselect a,b,c from t3 force index (a) where a=1 order by a,b,c;a b c1 1 01 1 11 2 01 2 1explain select a,b,c from t3 force index (a) where a=1 order by a desc, b desc, c desc;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t3 ref a a 5 const 2 Using where; Using indexselect a,b,c from t3 force index (a) where a=1 order by a desc, b desc, c desc;a b c1 2 11 2 01 1 11 1 0show index from t3;Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Commentt3 1 a 1 a A NULL NULL NULL YES BTREE t3 1 a 2 b A NULL NULL NULL YES BTREE t3 1 a 3 c A NULL NULL NULL YES BTREE drop table t1, t2, t3;CREATE TABLE t1 ( a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), UNIQUE (b) )ENGINE=MyISAM;CREATE TABLE t2 ( a INT AUTO_INCREMENT, b VARCHAR(10), INDEX (a), INDEX (b) )ENGINE=MERGE UNION (t1) INSERT_METHOD=FIRST;INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=2;INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=3;SELECT b FROM t2;b3DROP TABLE t1, t2;create table t1(a int);create table t2(a int);insert into t1 values (1);insert into t2 values (2);create table t3 (a int) engine=merge union=(t1, t2) insert_method=first;select * from t3;a12insert t2 select * from t2;select * from t2;a22insert t3 select * from t1;select * from t3;a1122insert t1 select * from t3;select * from t1;a111122select * from t2;a22select * from t3;a11112222check table t1, t2;Table Op Msg_type Msg_texttest.t1 check status OKtest.t2 check status OKdrop table t1, t2, t3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -