1
1
drop table if exists t0,t1,t2,t3,t4,t5;
3
3
grp int default NULL,
4
a bigint unsigned default NULL,
5
5
c char(10) NOT NULL default ''
7
7
INSERT INTO t1 VALUES (1,1,'a'),(2,2,'b'),(2,3,'c'),(3,4,'E'),(3,5,'C'),(3,6,'D'),(NULL,NULL,'');
8
create table t2 (id int, a bigint unsigned not null, c char(10), d int, primary key (a));
8
create table t2 (id int, a bigint not null, c char(10), d int, primary key (a));
9
9
insert into t2 values (1,1,"a",1),(3,4,"A",4),(3,5,"B",5),(3,6,"C",6),(4,7,"D",7);
10
10
select t1.*,t2.* from t1 JOIN t2 where t1.a=t2.a;
91
91
NULL NULL NULL NULL NULL NULL
92
92
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
93
93
id select_type table type possible_keys key key_len ref rows Extra
94
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
94
1 SIMPLE NULL NULL NULL NULL NULL NULL # Impossible WHERE
95
95
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
96
96
id select_type table type possible_keys key key_len ref rows Extra
97
1 SIMPLE t1 ALL NULL NULL NULL NULL 7
98
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 8 test.t1.a 1 Using where
97
1 SIMPLE t1 ALL NULL NULL NULL NULL #
98
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 8 test.t1.a # Using where
99
99
select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
100
100
grp a c id a c d a
129
129
drop table t1,t2;
130
130
CREATE TABLE t1 (
131
usr_id INT unsigned NOT NULL,
132
uniq_id INT unsigned NOT NULL AUTO_INCREMENT,
133
start_num INT unsigned NOT NULL DEFAULT 1,
134
increment INT unsigned NOT NULL DEFAULT 1,
132
uniq_id INT NOT NULL AUTO_INCREMENT,
133
start_num INT NOT NULL DEFAULT 1,
134
increment INT NOT NULL DEFAULT 1,
135
135
PRIMARY KEY (uniq_id),
136
136
INDEX usr_uniq_idx (usr_id, uniq_id),
137
137
INDEX uniq_usr_idx (uniq_id, usr_id)
139
139
CREATE TABLE t2 (
140
id INT unsigned NOT NULL DEFAULT 0,
141
usr2_id INT unsigned NOT NULL DEFAULT 0,
142
max INT unsigned NOT NULL DEFAULT 0,
143
c_amount INT unsigned NOT NULL DEFAULT 0,
144
d_max INT unsigned NOT NULL DEFAULT 0,
145
d_num INT unsigned NOT NULL DEFAULT 0,
146
orig_time INT unsigned NOT NULL DEFAULT 0,
147
c_time INT unsigned NOT NULL DEFAULT 0,
140
id INT NOT NULL DEFAULT 0,
141
usr2_id INT NOT NULL DEFAULT 0,
142
max INT NOT NULL DEFAULT 0,
143
c_amount INT NOT NULL DEFAULT 0,
144
d_max INT NOT NULL DEFAULT 0,
145
d_num INT NOT NULL DEFAULT 0,
146
orig_time INT NOT NULL DEFAULT 0,
147
c_time INT NOT NULL DEFAULT 0,
148
148
active ENUM ("no","yes") NOT NULL,
149
149
PRIMARY KEY (id,usr2_id),
150
150
INDEX id_idx (id),
238
238
dni_pasaporte char(16) DEFAULT '' NOT NULL,
239
239
idPla int DEFAULT '0' NOT NULL,
240
240
cod_asig int DEFAULT '0' NOT NULL,
241
any smallint DEFAULT '0' NOT NULL,
242
quatrimestre smallint DEFAULT '0' NOT NULL,
241
any int DEFAULT '0' NOT NULL,
242
quatrimestre int DEFAULT '0' NOT NULL,
243
243
estat char(1) DEFAULT 'M' NOT NULL,
244
244
PRIMARY KEY (id),
245
245
UNIQUE dni_pasaporte (dni_pasaporte,idPla),
623
621
bug_id reporter bug_id who
625
623
drop table t1,t2;
626
create table t1 (fooID smallint unsigned auto_increment, primary key (fooID));
627
create table t2 (fooID smallint unsigned not null, barID smallint unsigned not null, primary key (fooID,barID));
624
create table t1 (fooID int auto_increment, primary key (fooID));
625
create table t2 (fooID int not null, barID int not null, primary key (fooID,barID));
628
626
insert into t1 (fooID) values (10),(20),(30);
629
627
insert into t2 values (10,1),(20,2),(30,3);
630
628
explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30;
631
629
id select_type table type possible_keys key key_len ref rows Extra
632
1 SIMPLE t2 index NULL PRIMARY 4 NULL 3 Using index
633
1 SIMPLE t1 const PRIMARY PRIMARY 2 const 1 Using index
630
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index
631
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
634
632
select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30;
635
633
fooID barID fooID
713
711
drop table t1,t2;
714
712
create table t1 (
715
match_id tinyint unsigned not null auto_increment,
716
home tinyint unsigned default '0',
713
match_id int not null auto_increment,
714
home int default '0',
717
715
unique key match_id (match_id),
718
716
key match_id_2 (match_id)
720
718
insert into t1 values("1", "2");
721
719
create table t2 (
722
player_id tinyint unsigned default '0',
723
match_1_h tinyint unsigned default '0',
720
player_id int default '0',
721
match_1_h int default '0',
724
722
key player_id (player_id)
726
724
insert into t2 values("1", "5");
738
736
order by m.match_id desc;
739
737
id select_type table type possible_keys key key_len ref rows Extra
740
738
1 SIMPLE s ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
741
1 SIMPLE m const match_id,match_id_2 match_id 1 const 1
739
1 SIMPLE m const match_id,match_id_2 match_id 4 const 1
742
740
explain select s.*, '*', m.*, (s.match_1_h - m.home) UUX from
743
741
(t2 s left join t1 m on m.match_id = 1)
744
742
order by UUX desc;
745
743
id select_type table type possible_keys key key_len ref rows Extra
746
744
1 SIMPLE s ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
747
1 SIMPLE m const match_id,match_id_2 match_id 1 const 1
745
1 SIMPLE m const match_id,match_id_2 match_id 4 const 1
748
746
select s.*, '*', m.*, (s.match_1_h - m.home) UUX from
749
747
(t2 s left join t1 m on m.match_id = 1)
750
748
order by UUX desc;
792
790
drop table t1, t2;
794
ts_id bigint default NULL,
795
inst_id tinyint default NULL,
796
flag_name varchar(64) default NULL,
798
UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
799
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
801
ts_id bigint default NULL,
802
inst_id tinyint default NULL,
803
flag_name varchar(64) default NULL,
805
UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
806
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
791
CREATE TEMPORARY TABLE t1 (
792
ts_id bigint default NULL,
793
inst_id int default NULL,
794
flag_name varchar(64) default NULL,
796
UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
798
CREATE TEMPORARY TABLE t2 (
799
ts_id bigint default NULL,
800
inst_id int default NULL,
801
flag_name varchar(64) default NULL,
803
UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
807
805
INSERT INTO t1 VALUES
808
806
(111056548820001, 0, 'flag1', NULL),
809
807
(111056548820001, 0, 'flag2', NULL),
963
961
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
964
962
drop table t1, t2;
965
963
set group_concat_max_len=default;
966
create table t1 (gid smallint unsigned not null, x int not null, y int not null, art int not null, primary key (gid,x,y));
964
create table t1 (gid int not null, x int not null, y int not null, art int not null, primary key (gid,x,y));
967
965
insert t1 values (1, -5, -8, 2), (1, 2, 2, 1), (1, 1, 1, 1);
968
create table t2 (gid smallint unsigned not null, x int not null, y int not null, id int not null, primary key (gid,id,x,y), key id (id));
966
create table t2 (gid int not null, x int not null, y int not null, id int not null, primary key (gid,id,x,y), key id (id));
969
967
insert t2 values (1, -5, -8, 1), (1, 1, 1, 1), (1, 2, 2, 1);
970
create table t3 ( set_id smallint unsigned not null, id tinyint unsigned not null, name char(12) not null, primary key (id,set_id));
968
create table t3 ( set_id int not null, id int not null, name char(12) not null, primary key (id,set_id));
971
969
insert t3 values (0, 1, 'a'), (1, 1, 'b'), (0, 2, 'c'), (1, 2, 'd'), (1, 3, 'e'), (1, 4, 'f'), (1, 5, 'g'), (1, 6, 'h');
972
970
explain select name from t1 left join t2 on t1.x = t2.x and t1.y = t2.y
973
971
left join t3 on t1.art = t3.id where t2.id =1 and t2.x = -5 and t2.y =-8
974
972
and t1.gid =1 and t2.gid =1 and t3.set_id =1;
975
973
id select_type table type possible_keys key key_len ref rows Extra
976
1 SIMPLE t1 const PRIMARY PRIMARY 10 const,const,const 1
977
1 SIMPLE t2 const PRIMARY,id PRIMARY 14 const,const,const,const 1 Using index
978
1 SIMPLE t3 const PRIMARY PRIMARY 3 const,const 1
974
1 SIMPLE t1 const PRIMARY PRIMARY 12 const,const,const 1
975
1 SIMPLE t2 const PRIMARY,id PRIMARY 16 const,const,const,const 1 Using index
976
1 SIMPLE t3 const PRIMARY PRIMARY 8 const,const 1
979
977
drop tables t1,t2,t3;
980
978
CREATE TABLE t1 (c11 int);
981
979
CREATE TABLE t2 (c21 int);
1155
1153
DROP TABLE t1,t2;
1156
1154
CREATE TABLE t1 (
1157
f1 varchar(16) collate latin1_swedish_ci PRIMARY KEY,
1158
f2 varchar(16) collate latin1_swedish_ci
1155
f1 varchar(16) collate utf8_swedish_ci PRIMARY KEY,
1156
f2 varchar(16) collate utf8_swedish_ci
1160
1158
CREATE TABLE t2 (
1161
f1 varchar(16) collate latin1_swedish_ci PRIMARY KEY,
1162
f3 varchar(16) collate latin1_swedish_ci
1159
f1 varchar(16) collate utf8_swedish_ci PRIMARY KEY,
1160
f3 varchar(16) collate utf8_swedish_ci
1164
1162
INSERT INTO t1 VALUES ('bla','blah');
1165
1163
INSERT INTO t2 VALUES ('bla','sheep');