2003-01-06 00:48:59 +01:00
|
|
|
drop table if exists t1,t2;
|
2003-12-10 05:31:42 +01:00
|
|
|
create table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
|
2001-09-28 07:05:54 +02:00
|
|
|
insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6);
|
|
|
|
explain select * from t1 where a is null;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a a 5 const 3 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b = 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 9 const,const 1 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b = 7;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 9 const,const 1 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a=2 and b = 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2004-05-05 11:31:17 +02:00
|
|
|
1 SIMPLE t1 const a,b a 9 const,const 1 Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a<=>b limit 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 index NULL a 9 NULL 12 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range a,b a 9 NULL 3 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null or a = 7) and b=7;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2003-06-30 12:23:54 +02:00
|
|
|
1 SIMPLE t1 ref_or_null a,b a 9 const,const 2 Using where; Using index
|
|
|
|
explain select * from t1 where (a is null or a = 7) and b=7 order by a;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t1 ref_or_null a,b a 9 const,const 2 Using where; Using index; Using filesort
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2004-06-22 02:47:28 +02:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 2 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a > 1 and a < 3 limit 1;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2004-09-09 05:59:26 +02:00
|
|
|
1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a > 8 and a < 9;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2004-09-09 05:59:26 +02:00
|
|
|
1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
NULL 7
|
|
|
|
NULL 9
|
|
|
|
NULL 9
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null and b = 7;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
NULL 7
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a<=>b limit 2;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
2 2
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
2 2
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
NULL 9
|
|
|
|
NULL 9
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a = 7) and b=7;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
7 7
|
2003-06-30 12:23:54 +02:00
|
|
|
NULL 7
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b
|
|
|
|
NULL 7
|
|
|
|
NULL 9
|
|
|
|
NULL 9
|
2004-09-09 05:59:26 +02:00
|
|
|
select * from t1 where a > 1 and a < 3 limit 1;
|
|
|
|
a b
|
|
|
|
2 2
|
|
|
|
select * from t1 where a > 8 and a < 9;
|
|
|
|
a b
|
2003-06-30 12:23:54 +02:00
|
|
|
create table t2 like t1;
|
|
|
|
insert into t2 select * from t1;
|
2001-09-28 07:05:54 +02:00
|
|
|
alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10));
|
|
|
|
explain select * from t1 where a is null and b = 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b = 2 and c=0;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b = 7 and c=0;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a=2 and b = 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 1 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a<=>b limit 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range a,b a 5 NULL 5 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2003-06-30 12:23:54 +02:00
|
|
|
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref a,b a 5 const 3 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a > 1 and a < 3 limit 1;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range a a 5 NULL 1 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range a,b a 5 NULL 4 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where a > 8 and a < 9;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range a a 5 NULL 1 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select * from t1 where b like "6%";
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 range b b 12 NULL 1 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
NULL 7 0
|
|
|
|
NULL 9 0
|
|
|
|
NULL 9 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null and b = 7 and c=0;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
NULL 7 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a<=>b limit 2;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
1 1 0
|
|
|
|
2 2 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
1 1 0
|
|
|
|
2 2 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
NULL 9 0
|
|
|
|
NULL 9 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where (a is null or a = 7) and b=7 and c=0;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
7 7 0
|
2003-06-30 12:23:54 +02:00
|
|
|
NULL 7 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
NULL 7 0
|
|
|
|
NULL 9 0
|
|
|
|
NULL 9 0
|
2001-09-28 07:05:54 +02:00
|
|
|
select * from t1 where b like "6%";
|
2000-12-28 02:56:38 +01:00
|
|
|
a b c
|
|
|
|
6 6 0
|
2001-09-28 07:05:54 +02:00
|
|
|
drop table t1;
|
2003-06-30 12:23:54 +02:00
|
|
|
rename table t2 to t1;
|
|
|
|
alter table t1 modify b int null;
|
|
|
|
insert into t1 values (7,null), (8,null), (8,7);
|
|
|
|
explain select * from t1 where a = 7 and (b=7 or b is null);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t1 ref_or_null a,b a 10 const,const 2 Using where; Using index
|
|
|
|
select * from t1 where a = 7 and (b=7 or b is null);
|
|
|
|
a b
|
|
|
|
7 7
|
|
|
|
7 NULL
|
|
|
|
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2004-09-09 05:59:26 +02:00
|
|
|
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where; Using index
|
2003-06-30 12:23:54 +02:00
|
|
|
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
|
|
|
|
a b
|
|
|
|
7 NULL
|
|
|
|
7 7
|
2004-09-09 05:59:26 +02:00
|
|
|
NULL 7
|
2003-06-30 12:23:54 +02:00
|
|
|
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t1 ref_or_null a a 5 const 5 Using where; Using index
|
|
|
|
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
|
|
|
|
a b
|
|
|
|
7 NULL
|
|
|
|
7 7
|
|
|
|
NULL 7
|
|
|
|
NULL 9
|
|
|
|
NULL 9
|
|
|
|
create table t2 (a int);
|
|
|
|
insert into t2 values (7),(8);
|
|
|
|
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
|
|
|
1 SIMPLE t1 ref a,b a 10 test.t2.a,const 2 Using where; Using index
|
|
|
|
drop index b on t1;
|
|
|
|
explain select * from t2,t1 where t1.a=t2.a and b is null;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
|
|
|
1 SIMPLE t1 ref a a 10 test.t2.a,const 2 Using where; Using index
|
|
|
|
select * from t2,t1 where t1.a=t2.a and b is null;
|
|
|
|
a a b
|
|
|
|
7 7 NULL
|
|
|
|
8 8 NULL
|
|
|
|
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
|
|
|
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const 4 Using where; Using index
|
|
|
|
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
|
|
|
|
a a b
|
|
|
|
7 7 7
|
|
|
|
7 7 NULL
|
|
|
|
8 8 7
|
|
|
|
8 8 NULL
|
|
|
|
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
|
|
|
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const 4 Using where; Using index
|
|
|
|
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
|
|
|
|
a a b
|
|
|
|
7 7 7
|
|
|
|
7 NULL 7
|
|
|
|
8 8 7
|
|
|
|
8 NULL 7
|
|
|
|
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
|
|
|
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using where; Using index
|
|
|
|
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
|
|
|
|
a a b
|
|
|
|
7 7 NULL
|
|
|
|
7 7 7
|
|
|
|
7 NULL 7
|
|
|
|
8 8 NULL
|
|
|
|
8 8 7
|
|
|
|
8 NULL 7
|
|
|
|
insert into t2 values (null),(6);
|
|
|
|
delete from t1 where a=8;
|
|
|
|
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 4
|
|
|
|
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using where; Using index
|
|
|
|
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 4
|
|
|
|
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using where; Using index
|
|
|
|
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
|
|
|
|
a a b
|
|
|
|
7 7 NULL
|
|
|
|
7 7 7
|
|
|
|
7 NULL 7
|
|
|
|
8 NULL 7
|
|
|
|
NULL NULL 7
|
|
|
|
NULL NULL 9
|
|
|
|
NULL NULL 9
|
|
|
|
6 6 6
|
|
|
|
6 NULL 7
|
|
|
|
drop table t1,t2;
|
2001-09-28 07:05:54 +02:00
|
|
|
CREATE TABLE t1 (
|
|
|
|
id int(10) unsigned NOT NULL auto_increment,
|
|
|
|
uniq_id int(10) unsigned default NULL,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE KEY idx1 (uniq_id)
|
2003-12-10 05:31:42 +01:00
|
|
|
) ENGINE=MyISAM;
|
2001-09-28 07:05:54 +02:00
|
|
|
CREATE TABLE t2 (
|
|
|
|
id int(10) unsigned NOT NULL auto_increment,
|
|
|
|
uniq_id int(10) unsigned default NULL,
|
|
|
|
PRIMARY KEY (id)
|
2003-12-10 05:31:42 +01:00
|
|
|
) ENGINE=MyISAM;
|
2001-09-28 07:05:54 +02:00
|
|
|
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
|
|
|
|
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
|
|
|
|
explain select id from t1 where uniq_id is null;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-11-21 14:56:48 +01:00
|
|
|
1 SIMPLE t1 ref idx1 idx1 5 const 1 Using where
|
2001-09-28 07:05:54 +02:00
|
|
|
explain select id from t1 where uniq_id =1;
|
2002-09-26 22:08:22 +02:00
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
2002-10-03 17:47:04 +02:00
|
|
|
1 SIMPLE t1 const idx1 idx1 5 const 1
|
2001-09-28 07:05:54 +02:00
|
|
|
UPDATE t1 SET id=id+100 where uniq_id is null;
|
|
|
|
UPDATE t2 SET id=id+100 where uniq_id is null;
|
|
|
|
select id from t1 where uniq_id is null;
|
2001-04-10 10:32:28 +02:00
|
|
|
id
|
|
|
|
101
|
|
|
|
102
|
|
|
|
105
|
|
|
|
106
|
|
|
|
109
|
|
|
|
110
|
2001-09-28 07:05:54 +02:00
|
|
|
select id from t2 where uniq_id is null;
|
2001-04-10 10:32:28 +02:00
|
|
|
id
|
|
|
|
101
|
|
|
|
102
|
|
|
|
105
|
|
|
|
106
|
|
|
|
109
|
|
|
|
110
|
2001-09-28 07:05:54 +02:00
|
|
|
DELETE FROM t1 WHERE uniq_id IS NULL;
|
|
|
|
DELETE FROM t2 WHERE uniq_id IS NULL;
|
|
|
|
SELECT * FROM t1 ORDER BY uniq_id, id;
|
2001-04-10 10:32:28 +02:00
|
|
|
id uniq_id
|
|
|
|
3 1
|
|
|
|
4 2
|
|
|
|
7 3
|
|
|
|
8 4
|
2001-09-28 07:05:54 +02:00
|
|
|
SELECT * FROM t2 ORDER BY uniq_id, id;
|
2001-04-10 10:32:28 +02:00
|
|
|
id uniq_id
|
|
|
|
3 1
|
|
|
|
4 2
|
|
|
|
7 3
|
|
|
|
8 4
|
2002-10-16 18:05:10 +02:00
|
|
|
DROP table t1,t2;
|
|
|
|
CREATE TABLE `t1` (
|
|
|
|
`order_id` char(32) NOT NULL default '',
|
|
|
|
`product_id` char(32) NOT NULL default '',
|
|
|
|
`product_type` int(11) NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`order_id`,`product_id`,`product_type`)
|
2003-12-10 05:31:42 +01:00
|
|
|
) ENGINE=MyISAM;
|
2002-10-16 18:05:10 +02:00
|
|
|
CREATE TABLE `t2` (
|
|
|
|
`order_id` char(32) NOT NULL default '',
|
|
|
|
`product_id` char(32) NOT NULL default '',
|
|
|
|
`product_type` int(11) NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`order_id`,`product_id`,`product_type`)
|
2003-12-10 05:31:42 +01:00
|
|
|
) ENGINE=MyISAM;
|
2002-10-16 18:05:10 +02:00
|
|
|
INSERT INTO t1 (order_id, product_id, product_type) VALUES
|
|
|
|
('3d7ce39b5d4b3e3d22aaafe9b633de51',1206029, 3),
|
|
|
|
('3d7ce39b5d4b3e3d22aaafe9b633de51',5880836, 3),
|
|
|
|
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
|
|
|
|
INSERT INTO t2 (order_id, product_id, product_type) VALUES
|
|
|
|
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
select t1.* from t1 left join t2
|
|
|
|
on (t1.order_id = t2.order_id and
|
|
|
|
t1.product_id = t2.product_id and
|
|
|
|
t1.product_type = t2.product_type)
|
|
|
|
where t2.order_id = NULL;
|
2002-10-14 16:04:12 +02:00
|
|
|
order_id product_id product_type
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
select t1.* from t1 left join t2
|
|
|
|
on (t1.order_id = t2.order_id and
|
|
|
|
t1.product_id = t2.product_id and
|
|
|
|
t1.product_type = t2.product_type)
|
2002-10-16 18:05:10 +02:00
|
|
|
where t2.order_id is NULL;
|
2002-10-14 16:04:12 +02:00
|
|
|
order_id product_id product_type
|
|
|
|
3d7ce39b5d4b3e3d22aaafe9b633de51 1206029 3
|
|
|
|
3d7ce39b5d4b3e3d22aaafe9b633de51 5880836 3
|
2002-10-16 18:05:10 +02:00
|
|
|
drop table t1,t2;
|
|
|
|
create table t1 (id int);
|
|
|
|
insert into t1 values (null), (0);
|
|
|
|
create table t2 (id int);
|
|
|
|
insert into t2 values (null);
|
|
|
|
select * from t1, t2 where t1.id = t2.id;
|
2002-10-14 16:04:12 +02:00
|
|
|
id id
|
2002-10-16 18:05:10 +02:00
|
|
|
alter table t1 add key id (id);
|
|
|
|
select * from t1, t2 where t1.id = t2.id;
|
2002-10-14 16:04:12 +02:00
|
|
|
id id
|
2002-10-16 18:05:10 +02:00
|
|
|
drop table t1,t2;
|
2002-11-24 20:39:22 +01:00
|
|
|
create table t1 (
|
|
|
|
id integer,
|
|
|
|
id2 integer not null,
|
|
|
|
index (id),
|
|
|
|
index (id2)
|
|
|
|
);
|
|
|
|
insert into t1 values(null,null),(1,1);
|
2003-04-30 09:07:37 +02:00
|
|
|
Warnings:
|
2004-10-02 21:20:08 +02:00
|
|
|
Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'id2' at row 1
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
NULL 0
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1 where id <=> null;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
NULL 0
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1 where id <=> null or id > 0;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
NULL 0
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1 where id is null or id > 0;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
NULL 0
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1 where id2 <=> null or id2 > 0;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
select * from t1 where id2 is null or id2 > 0;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
delete from t1 where id <=> NULL;
|
|
|
|
select * from t1;
|
2002-11-22 12:35:43 +01:00
|
|
|
id id2
|
|
|
|
1 1
|
2002-11-24 20:39:22 +01:00
|
|
|
drop table t1;
|
2005-07-28 22:31:15 +02:00
|
|
|
CREATE TABLE t1 (a int);
|
|
|
|
CREATE TABLE t2 (a int, b int, INDEX idx(a));
|
|
|
|
CREATE TABLE t3 (b int, INDEX idx(b));
|
2005-07-29 01:04:47 +02:00
|
|
|
CREATE TABLE t4 (b int, INDEX idx(b));
|
2005-07-28 22:31:15 +02:00
|
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
|
|
INSERT INTO t2 VALUES (1, 1), (3, 1);
|
|
|
|
INSERT INTO t3 VALUES
|
|
|
|
(NULL), (NULL), (NULL), (NULL), (NULL),
|
2005-07-29 01:04:47 +02:00
|
|
|
(NULL), (NULL), (NULL), (NULL), (NULL);
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t4 SELECT * FROM t3;
|
|
|
|
INSERT INTO t3 SELECT * FROM t4;
|
|
|
|
INSERT INTO t3 VALUES (2), (3);
|
2005-07-28 22:31:15 +02:00
|
|
|
ANALYZE table t1, t2, t3;
|
|
|
|
Table Op Msg_type Msg_text
|
|
|
|
test.t1 analyze status OK
|
|
|
|
test.t2 analyze status OK
|
|
|
|
test.t3 analyze status OK
|
2005-07-29 01:04:47 +02:00
|
|
|
SELECT COUNT(*) FROM t3;
|
|
|
|
COUNT(*)
|
|
|
|
15972
|
2005-07-28 22:31:15 +02:00
|
|
|
EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
|
|
|
|
LEFT JOIN t3 ON t2.b=t3.b;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
|
|
|
|
1 SIMPLE t2 ref idx idx 5 test.t1.a 1
|
|
|
|
1 SIMPLE t3 ref idx idx 5 test.t2.b 1 Using index
|
2005-07-29 02:53:51 +02:00
|
|
|
FLUSH STATUS ;
|
2005-07-28 22:31:15 +02:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
|
|
|
|
LEFT JOIN t3 ON t2.b=t3.b;
|
|
|
|
a a b b
|
|
|
|
1 1 1 NULL
|
|
|
|
2 NULL NULL NULL
|
|
|
|
3 3 1 NULL
|
|
|
|
4 NULL NULL NULL
|
2005-07-31 13:28:01 +02:00
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
4
|
2005-07-29 01:04:47 +02:00
|
|
|
SHOW STATUS LIKE "handler_read%";
|
|
|
|
Variable_name Value
|
2005-07-29 02:53:51 +02:00
|
|
|
Handler_read_first 0
|
|
|
|
Handler_read_key 6
|
|
|
|
Handler_read_next 2
|
2005-07-29 01:04:47 +02:00
|
|
|
Handler_read_prev 0
|
|
|
|
Handler_read_rnd 0
|
2005-07-29 02:53:51 +02:00
|
|
|
Handler_read_rnd_next 5
|
2005-07-29 01:04:47 +02:00
|
|
|
DROP TABLE t1,t2,t3,t4;
|