~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/join_outer.test

  • Committer: Monty
  • Date: 2008-10-02 05:41:33 UTC
  • mfrom: (398.1.10 codestyle)
  • Revision ID: mordred@scylla.inaugust.com-20081002054133-tyxv5bmqpazfaqqi
Merged up to 408 of stdint-includes-fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
CREATE TABLE t1 (
10
10
  grp int default NULL,
11
 
  a bigint default NULL,
 
11
  a bigint unsigned default NULL,
12
12
  c char(10) NOT NULL default ''
13
 
);
 
13
) ENGINE=MyISAM;
14
14
INSERT INTO t1 VALUES (1,1,'a'),(2,2,'b'),(2,3,'c'),(3,4,'E'),(3,5,'C'),(3,6,'D'),(NULL,NULL,'');
15
 
create table t2 (id int, a bigint not null, c char(10), d int, primary key (a));
 
15
create table t2 (id int, a bigint unsigned not null, c char(10), d int, primary key (a));
16
16
insert into t2 values (1,1,"a",1),(3,4,"A",4),(3,5,"B",5),(3,6,"C",6),(4,7,"D",7);
17
17
 
18
18
select t1.*,t2.* from t1 JOIN t2 where t1.a=t2.a;
28
28
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id=3;
29
29
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id is null;
30
30
 
31
 
--replace_column 9 #
32
31
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
33
 
--replace_column 9 #
34
32
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
35
33
 
36
34
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);
37
35
 
38
36
# The next query should rearange the left joins to get this to work
39
 
--error ER_BAD_FIELD_ERROR
 
37
--error 1054
40
38
explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
41
 
--error ER_BAD_FIELD_ERROR
 
39
--error 1054
42
40
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
43
41
 
44
42
# The next query should give an error in MySQL
45
 
--error ER_BAD_FIELD_ERROR
 
43
--error 1054
46
44
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
47
45
 
48
46
# Test of inner join
57
55
#
58
56
 
59
57
CREATE TABLE t1 (
60
 
 usr_id INT NOT NULL,
61
 
 uniq_id INT NOT NULL AUTO_INCREMENT,
62
 
        start_num INT NOT NULL DEFAULT 1,
63
 
        increment INT NOT NULL DEFAULT 1,
 
58
 usr_id INT unsigned NOT NULL,
 
59
 uniq_id INT unsigned NOT NULL AUTO_INCREMENT,
 
60
        start_num INT unsigned NOT NULL DEFAULT 1,
 
61
        increment INT unsigned NOT NULL DEFAULT 1,
64
62
 PRIMARY KEY (uniq_id),
65
63
 INDEX usr_uniq_idx (usr_id, uniq_id),
66
64
 INDEX uniq_usr_idx (uniq_id, usr_id)
67
65
);
68
66
CREATE TABLE t2 (
69
 
 id INT NOT NULL DEFAULT 0,
70
 
 usr2_id INT NOT NULL DEFAULT 0,
71
 
 max INT NOT NULL DEFAULT 0,
72
 
 c_amount INT NOT NULL DEFAULT 0,
73
 
 d_max INT NOT NULL DEFAULT 0,
74
 
 d_num INT NOT NULL DEFAULT 0,
75
 
 orig_time INT NOT NULL DEFAULT 0,
76
 
 c_time INT NOT NULL DEFAULT 0,
 
67
 id INT unsigned NOT NULL DEFAULT 0,
 
68
 usr2_id INT unsigned NOT NULL DEFAULT 0,
 
69
 max INT unsigned NOT NULL DEFAULT 0,
 
70
 c_amount INT unsigned NOT NULL DEFAULT 0,
 
71
 d_max INT unsigned NOT NULL DEFAULT 0,
 
72
 d_num INT unsigned NOT NULL DEFAULT 0,
 
73
 orig_time INT unsigned NOT NULL DEFAULT 0,
 
74
 c_time INT unsigned NOT NULL DEFAULT 0,
77
75
 active ENUM ("no","yes") NOT NULL,
78
76
 PRIMARY KEY (id,usr2_id),
79
77
 INDEX id_idx (id),
217
215
#
218
216
 
219
217
CREATE TABLE t1 (
220
 
  id int NOT NULL auto_increment,
 
218
  id int unsigned NOT NULL auto_increment,
221
219
  name char(60) DEFAULT '' NOT NULL,
222
220
  PRIMARY KEY (id)
223
221
);
226
224
INSERT INTO t1 VALUES (3,'Thimble Smith');
227
225
 
228
226
CREATE TABLE t2 (
229
 
  id int NOT NULL auto_increment,
230
 
  owner int DEFAULT '0' NOT NULL,
 
227
  id int unsigned NOT NULL auto_increment,
 
228
  owner int unsigned DEFAULT '0' NOT NULL,
231
229
  name char(60),
232
230
  PRIMARY KEY (id)
233
231
);
294
292
insert into t4 values (1,1);
295
293
insert into t5 values (1,1);
296
294
 
297
 
--error ER_BAD_FIELD_ERROR
 
295
--error 1054
298
296
explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23;
299
297
 
300
298
drop table t1,t2,t3,t4,t5;
344
342
insert into t2 values (7, 'green');
345
343
select * from t1;
346
344
select * from t2;
347
 
--sorted_result
348
345
select * from t2 natural join t1;
349
 
--sorted_result
350
346
select t2.count, t1.name from t2 natural join t1;
351
 
--sorted_result
352
347
select t2.count, t1.name from t2 inner join t1 using (color);
353
348
drop table t1;
354
349
drop table t2;
419
414
#
420
415
# Test problem with LEFT JOIN
421
416
 
422
 
create table t1 (fooID int auto_increment, primary key (fooID));
423
 
create table t2 (fooID int not null, barID int not null, primary key (fooID,barID));
 
417
create table t1 (fooID int unsigned auto_increment, primary key (fooID));
 
418
create table t2 (fooID int unsigned not null, barID int unsigned not null, primary key (fooID,barID));
424
419
insert into t1 (fooID) values (10),(20),(30);
425
420
insert into t2 values (10,1),(20,2),(30,3);
426
421
explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30;
481
476
# Test for BUG#5088
482
477
 
483
478
create table t1 (
484
 
  match_id int not null auto_increment,
485
 
  home int default '0',
 
479
  match_id int unsigned not null auto_increment,
 
480
  home int unsigned default '0',
486
481
  unique key match_id (match_id),
487
482
  key match_id_2 (match_id)
488
483
);
490
485
insert into t1 values("1", "2");
491
486
 
492
487
create table t2 (
493
 
  player_id int default '0',
494
 
  match_1_h int default '0',
 
488
  player_id int unsigned default '0',
 
489
  match_1_h int unsigned default '0',
495
490
  key player_id (player_id)
496
491
);
497
492
 
542
537
 
543
538
drop table t1, t2;
544
539
 
545
 
CREATE TEMPORARY TABLE t1 (
 
540
CREATE TABLE t1 (
546
541
  ts_id bigint default NULL,
547
542
  inst_id int default NULL,
548
543
  flag_name varchar(64) default NULL,
550
545
  UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
551
546
) ENGINE=MyISAM;
552
547
 
553
 
CREATE TEMPORARY TABLE t2 (
 
548
CREATE TABLE t2 (
554
549
  ts_id bigint default NULL,
555
550
  inst_id int default NULL,
556
551
  flag_name varchar(64) default NULL,
576
571
DROP TABLE t1,t2;
577
572
 
578
573
CREATE TABLE t1 (
579
 
  id int NOT NULL auto_increment,
580
 
  text_id int default NULL,
 
574
  id int unsigned NOT NULL auto_increment,
 
575
  text_id int unsigned default NULL,
581
576
  PRIMARY KEY  (id)
582
577
);
583
578
 
674
669
#
675
670
# BUG#10162 - ON is merged with WHERE, left join is convered to a regular join
676
671
#
677
 
create table t1 (gid int not null, x int not null, y int not null, art int not null, primary key  (gid,x,y));
 
672
create table t1 (gid int unsigned not null, x int not null, y int not null, art int not null, primary key  (gid,x,y));
678
673
insert t1 values (1, -5, -8, 2), (1, 2, 2, 1), (1, 1, 1, 1);
679
 
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));
 
674
create table t2 (gid int unsigned not null, x int not null, y int not null, id int not null, primary key  (gid,id,x,y), key id (id));
680
675
insert t2 values (1, -5, -8, 1), (1, 1, 1, 1), (1, 2, 2, 1);
681
 
create table t3 ( set_id int not null, id int not null, name char(12) not null, primary key  (id,set_id));
 
676
create table t3 ( set_id int unsigned not null, id int unsigned not null, name char(12) not null, primary key  (id,set_id));
682
677
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');
683
678
explain select name from t1 left join t2 on t1.x = t2.x and t1.y = t2.y
684
679
left join t3 on t1.art = t3.id where t2.id =1 and t2.x = -5 and t2.y =-8
798
793
 
799
794
flush status;
800
795
SELECT t1.id, a FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.b IS NULL;
801
 
--replace_column 2 #
802
796
show status like 'Handler_read%';
803
797
 
804
798
DROP TABLE t1,t2;