~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/r/join.result

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1,t2,t3;
 
2
CREATE TABLE t1 (S1 INT);
 
3
CREATE TABLE t2 (S1 INT);
 
4
INSERT INTO t1 VALUES (1);
 
5
INSERT INTO t2 VALUES (2);
 
6
SELECT * FROM t1 JOIN t2;
 
7
S1      S1
 
8
1       2
 
9
SELECT * FROM t1 INNER JOIN t2;
 
10
S1      S1
 
11
1       2
 
12
SELECT * from t1 JOIN t2 USING (S1);
 
13
S1
 
14
SELECT * FROM t1 INNER JOIN t2 USING (S1);
 
15
S1
 
16
SELECT * from t1 CROSS JOIN t2;
 
17
S1      S1
 
18
1       2
 
19
SELECT * from t1 LEFT JOIN t2 USING(S1);
 
20
S1
 
21
1
 
22
SELECT * from t1 LEFT JOIN t2 ON(t2.S1=2);
 
23
S1      S1
 
24
1       2
 
25
SELECT * from t1 RIGHT JOIN t2 USING(S1);
 
26
S1
 
27
2
 
28
SELECT * from t1 RIGHT JOIN t2 ON(t1.S1=1);
 
29
S1      S1
 
30
1       2
 
31
drop table t1,t2;
 
32
create table t1 (id int primary key);
 
33
create table t2 (id int);
 
34
insert into t1 values (75);
 
35
insert into t1 values (79);
 
36
insert into t1 values (78);
 
37
insert into t1 values (77);
 
38
replace into t1 values (76);
 
39
replace into t1 values (76);
 
40
insert into t1 values (104);
 
41
insert into t1 values (103);
 
42
insert into t1 values (102);
 
43
insert into t1 values (101);
 
44
insert into t1 values (105);
 
45
insert into t1 values (106);
 
46
insert into t1 values (107);
 
47
insert into t2 values (107),(75),(1000);
 
48
select t1.id, t2.id from t1, t2 where t2.id = t1.id;
 
49
id      id
 
50
107     107
 
51
75      75
 
52
select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t1.id;
 
53
id      count(t2.id)
 
54
75      1
 
55
107     1
 
56
select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t2.id;
 
57
id      count(t2.id)
 
58
75      1
 
59
107     1
 
60
select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
 
61
id      id
 
62
NULL    75
 
63
explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
 
64
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
65
1       SIMPLE  t1      const   PRIMARY NULL    NULL    NULL    1       Impossible ON condition
 
66
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    3       Using where
 
67
explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0;
 
68
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
69
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
70
drop table t1,t2;
 
71
CREATE TABLE t1 (
 
72
id int NOT NULL auto_increment,
 
73
token varchar(100) DEFAULT '' NOT NULL,
 
74
count int DEFAULT '0' NOT NULL,
 
75
qty int,
 
76
phone char(1) DEFAULT '' NOT NULL,
 
77
timestamp datetime,
 
78
PRIMARY KEY (id),
 
79
KEY token (token(15)),
 
80
KEY timestamp (timestamp),
 
81
UNIQUE token_2 (token(75),count,phone)
 
82
);
 
83
INSERT INTO t1 VALUES (21,'e45703b64de71482360de8fec94c3ade',3,7800,'n','1999-12-23 17:22:21');
 
84
INSERT INTO t1 VALUES (22,'e45703b64de71482360de8fec94c3ade',4,5000,'y','1999-12-23 17:22:21');
 
85
INSERT INTO t1 VALUES (18,'346d1cb63c89285b2351f0ca4de40eda',3,13200,'b','1999-12-23 11:58:04');
 
86
INSERT INTO t1 VALUES (17,'ca6ddeb689e1b48a04146b1b5b6f936a',4,15000,'b','1999-12-23 11:36:53');
 
87
INSERT INTO t1 VALUES (16,'ca6ddeb689e1b48a04146b1b5b6f936a',3,13200,'b','1999-12-23 11:36:53');
 
88
INSERT INTO t1 VALUES (26,'a71250b7ed780f6ef3185bfffe027983',5,1500,'b','1999-12-27 09:44:24');
 
89
INSERT INTO t1 VALUES (24,'4d75906f3c37ecff478a1eb56637aa09',3,5400,'y','1999-12-23 17:29:12');
 
90
INSERT INTO t1 VALUES (25,'4d75906f3c37ecff478a1eb56637aa09',4,6500,'y','1999-12-23 17:29:12');
 
91
INSERT INTO t1 VALUES (27,'a71250b7ed780f6ef3185bfffe027983',3,6200,'b','1999-12-27 09:44:24');
 
92
INSERT INTO t1 VALUES (28,'a71250b7ed780f6ef3185bfffe027983',3,5400,'y','1999-12-27 09:44:36');
 
93
INSERT INTO t1 VALUES (29,'a71250b7ed780f6ef3185bfffe027983',4,17700,'b','1999-12-27 09:45:05');
 
94
CREATE TABLE t2 (
 
95
id int NOT NULL auto_increment,
 
96
category int DEFAULT '0' NOT NULL,
 
97
county int DEFAULT '0' NOT NULL,
 
98
state int DEFAULT '0' NOT NULL,
 
99
phones int DEFAULT '0' NOT NULL,
 
100
nophones int DEFAULT '0' NOT NULL,
 
101
PRIMARY KEY (id),
 
102
KEY category (category,county,state)
 
103
);
 
104
INSERT INTO t2 VALUES (3,2,11,12,5400,7800);
 
105
INSERT INTO t2 VALUES (4,2,25,12,6500,11200);
 
106
INSERT INTO t2 VALUES (5,1,37,6,10000,12000);
 
107
select a.id, b.category as catid, b.state as stateid, b.county as countyid from t1 a, t2 b ignore index (primary) where (a.token ='a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id);
 
108
id      catid   stateid countyid
 
109
27      2       12      11
 
110
28      2       12      11
 
111
29      2       12      25
 
112
26      1       6       37
 
113
select a.id, b.category as catid, b.state as stateid, b.county as
 
114
countyid from t1 a, t2 b where (a.token =
 
115
'a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id) order by a.id;
 
116
id      catid   stateid countyid
 
117
26      1       6       37
 
118
27      2       12      11
 
119
28      2       12      11
 
120
29      2       12      25
 
121
drop table t1, t2;
 
122
create table t1 (a int primary key);
 
123
insert into t1 values(1),(2);
 
124
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
 
125
a
 
126
1
 
127
2
 
128
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
 
129
ERROR HY000: Too many tables; Drizzle can only use XX tables in a join
 
130
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
 
131
a
 
132
1
 
133
2
 
134
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
 
135
ERROR HY000: Too many tables; Drizzle can only use XX tables in a join
 
136
drop table t1;
 
137
CREATE TEMPORARY TABLE t1 (
 
138
a int NOT NULL,
 
139
b int NOT NULL,
 
140
PRIMARY KEY  (a,b)
 
141
) ENGINE=MyISAM;
 
142
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(2,3);
 
143
CREATE TEMPORARY TABLE t2 (
 
144
a int default NULL
 
145
) ENGINE=MyISAM;
 
146
INSERT INTO t2 VALUES (2),(3);
 
147
SELECT t1.a,t2.a,b FROM t1,t2 WHERE t1.a=t2.a AND (t1.a=1 OR t1.a=2) AND b>=1 AND b<=3;
 
148
a       a       b
 
149
2       2       3
 
150
DROP TABLE t1, t2;
 
151
CREATE TABLE t1 (d DATE);
 
152
CREATE TABLE t2 (d DATE);
 
153
INSERT INTO t1 (d) VALUES ('2001-08-01'),(NULL);
 
154
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL;
 
155
d
 
156
2001-08-01
 
157
NULL
 
158
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE d IS NULL;
 
159
d
 
160
NULL
 
161
SELECT * from t1 WHERE t1.d IS NULL;
 
162
d
 
163
NULL
 
164
SELECT * FROM t1 WHERE 1/0 IS NULL;
 
165
d
 
166
2001-08-01
 
167
NULL
 
168
Warnings:
 
169
Error   1365    Division by 0
 
170
Error   1365    Division by 0
 
171
Error   1365    Division by 0
 
172
DROP TABLE t1,t2;
 
173
CREATE TABLE t1 (
 
174
Document_ID varchar(50) NOT NULL default '',
 
175
Contractor_ID varchar(6) NOT NULL default '',
 
176
Language_ID char(3) NOT NULL default '',
 
177
Expiration_Date datetime default NULL,
 
178
Publishing_Date datetime default NULL,
 
179
Title text,
 
180
Column_ID varchar(50) NOT NULL default '',
 
181
PRIMARY KEY  (Language_ID,Document_ID,Contractor_ID)
 
182
);
 
183
INSERT INTO t1 VALUES ('xep80','1','ger','2001-12-31 20:00:00','2001-11-12 10:58:00','Kartenbestellung - jetzt auch online','anle'),('','999998','',NULL,NULL,NULL,'');
 
184
CREATE TABLE t2 (
 
185
Contractor_ID char(6) NOT NULL default '',
 
186
Language_ID char(3) NOT NULL default '',
 
187
Document_ID char(50) NOT NULL default '',
 
188
CanRead char(1) default NULL,
 
189
Customer_ID int NOT NULL default '0',
 
190
PRIMARY KEY  (Contractor_ID,Language_ID,Document_ID,Customer_ID)
 
191
);
 
192
INSERT INTO t2 VALUES ('5','ger','xep80','1',999999),('1','ger','xep80','1',999999);
 
193
CREATE TABLE t3 (
 
194
Language_ID char(3) NOT NULL default '',
 
195
Column_ID char(50) NOT NULL default '',
 
196
Contractor_ID char(6) NOT NULL default '',
 
197
CanRead char(1) default NULL,
 
198
Active char(1) default NULL,
 
199
PRIMARY KEY  (Language_ID,Column_ID,Contractor_ID)
 
200
);
 
201
INSERT INTO t3 VALUES ('ger','home','1','1','1'),('ger','Test','1','0','0'),('ger','derclu','1','0','0'),('ger','clubne','1','0','0'),('ger','philos','1','0','0'),('ger','clubko','1','0','0'),('ger','clubim','1','1','1'),('ger','progra','1','0','0'),('ger','progvo','1','0','0'),('ger','progsp','1','0','0'),('ger','progau','1','0','0'),('ger','progku','1','0','0'),('ger','progss','1','0','0'),('ger','nachl','1','0','0'),('ger','mitgli','1','0','0'),('ger','mitsu','1','0','0'),('ger','mitbus','1','0','0'),('ger','ergmar','1','1','1'),('ger','home','4','1','1'),('ger','derclu','4','1','1'),('ger','clubne','4','0','0'),('ger','philos','4','1','1'),('ger','clubko','4','1','1'),('ger','clubim','4','1','1'),('ger','progra','4','1','1'),('ger','progvo','4','1','1'),('ger','progsp','4','1','1'),('ger','progau','4','0','0'),('ger','progku','4','1','1'),('ger','progss','4','1','1'),('ger','nachl','4','1','1'),('ger','mitgli','4','0','0'),('ger','mitsu','4','0','0'),('ger','mitbus','4','0','0'),('ger','ergmar','4','1','1'),('ger','progra2','1','0','0'),('ger','archiv','4','1','1'),('ger','anmeld','4','1','1'),('ger','thema','4','1','1'),('ger','edito','4','1','1'),('ger','madis','4','1','1'),('ger','enma','4','1','1'),('ger','madis','1','1','1'),('ger','enma','1','1','1'),('ger','vorsch','4','0','0'),('ger','veranst','4','0','0'),('ger','anle','4','1','1'),('ger','redak','4','1','1'),('ger','nele','4','1','1'),('ger','aukt','4','1','1'),('ger','callcenter','4','1','1'),('ger','anle','1','0','0');
 
202
delete from t1 where Contractor_ID='999998';
 
203
insert into t1 (Contractor_ID) Values ('999998');
 
204
SELECT DISTINCT COUNT(t1.Title) FROM t1,
 
205
t2, t3 WHERE 
 
206
t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND 
 
207
t1.Language_ID='ger' AND '2001-12-21 23:14:24' >= 
 
208
Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND 
 
209
t1.Document_ID = t2.Document_ID AND 
 
210
t1.Language_ID = t2.Language_ID AND 
 
211
t1.Contractor_ID = t2.Contractor_ID AND ( 
 
212
t2.Customer_ID = '4'  OR 
 
213
t2.Customer_ID = '999999'  OR 
 
214
t2.Customer_ID = '1' )AND t2.CanRead 
 
215
= '1'  AND t1.Column_ID=t3.Column_ID AND 
 
216
t1.Language_ID=t3.Language_ID AND ( 
 
217
t3.Contractor_ID = '4'  OR 
 
218
t3.Contractor_ID = '999999'  OR 
 
219
t3.Contractor_ID = '1') AND 
 
220
t3.CanRead='1' AND t3.Active='1';
 
221
COUNT(t1.Title)
 
222
1
 
223
SELECT DISTINCT COUNT(t1.Title) FROM t1,
 
224
t2, t3 WHERE 
 
225
t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND 
 
226
t1.Language_ID='ger' AND '2001-12-21 23:14:24' >= 
 
227
Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND 
 
228
t1.Document_ID = t2.Document_ID AND 
 
229
t1.Language_ID = t2.Language_ID AND 
 
230
t1.Contractor_ID = t2.Contractor_ID AND ( 
 
231
t2.Customer_ID = '4'  OR 
 
232
t2.Customer_ID = '999999'  OR 
 
233
t2.Customer_ID = '1' )AND t2.CanRead 
 
234
= '1'  AND t1.Column_ID=t3.Column_ID AND 
 
235
t1.Language_ID=t3.Language_ID AND ( 
 
236
t3.Contractor_ID = '4'  OR 
 
237
t3.Contractor_ID = '999999'  OR 
 
238
t3.Contractor_ID = '1') AND 
 
239
t3.CanRead='1' AND t3.Active='1';
 
240
COUNT(t1.Title)
 
241
1
 
242
drop table t1,t2,t3;
 
243
CREATE TEMPORARY TABLE t1 (
 
244
t1_id int default NULL,
 
245
t2_id int default NULL,
 
246
type enum('Cost','Percent') default NULL,
 
247
cost_unit enum('Cost','Unit') default NULL,
 
248
min_value double default NULL,
 
249
max_value double default NULL,
 
250
t3_id int default NULL,
 
251
item_id int default NULL
 
252
) ENGINE=MyISAM;
 
253
INSERT INTO t1 VALUES (12,5,'Percent','Cost',-1,0,-1,-1),(14,4,'Percent','Cost',-1,0,-1,-1),(18,5,'Percent','Cost',-1,0,-1,-1),(19,4,'Percent','Cost',-1,0,-1,-1),(20,5,'Percent','Cost',100,-1,22,291),(21,5,'Percent','Cost',100,-1,18,291),(22,1,'Percent','Cost',100,-1,6,291),(23,1,'Percent','Cost',100,-1,21,291),(24,1,'Percent','Cost',100,-1,9,291),(25,1,'Percent','Cost',100,-1,4,291),(26,1,'Percent','Cost',100,-1,20,291),(27,4,'Percent','Cost',100,-1,7,202),(28,1,'Percent','Cost',50,-1,-1,137),(29,2,'Percent','Cost',100,-1,4,354),(30,2,'Percent','Cost',100,-1,9,137),(93,2,'Cost','Cost',-1,10000000,-1,-1);
 
254
CREATE TEMPORARY TABLE t2 (
 
255
id int NOT NULL auto_increment,
 
256
name varchar(255) default NULL,
 
257
PRIMARY KEY  (id)
 
258
) ENGINE=MyISAM;
 
259
INSERT INTO t2 VALUES (1,'s1'),(2,'s2'),(3,'s3'),(4,'s4'),(5,'s5');
 
260
select t1.*, t2.*  from t1, t2 where t2.id=t1.t2_id limit 2;
 
261
t1_id   t2_id   type    cost_unit       min_value       max_value       t3_id   item_id id      name
 
262
22      1       Percent Cost    100     -1      6       291     1       s1
 
263
23      1       Percent Cost    100     -1      21      291     1       s1
 
264
drop table t1,t2;
 
265
CREATE TEMPORARY TABLE t1 (
 
266
siteid varchar(25) NOT NULL default '',
 
267
emp_id varchar(30) NOT NULL default '',
 
268
rate_code varchar(10) default NULL,
 
269
UNIQUE KEY site_emp (siteid,emp_id),
 
270
KEY siteid (siteid)
 
271
) ENGINE=MyISAM;
 
272
INSERT INTO t1 VALUES ('rivercats','psmith','cust'), ('rivercats','KWalker','cust');
 
273
CREATE TEMPORARY TABLE t2 (
 
274
siteid varchar(25) NOT NULL default '',
 
275
rate_code varchar(10) NOT NULL default '',
 
276
base_rate float NOT NULL default '0',
 
277
PRIMARY KEY  (siteid,rate_code)
 
278
) ENGINE=MyISAM;
 
279
INSERT INTO t2 VALUES ('rivercats','cust',20);
 
280
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats';
 
281
rate_code       base_rate
 
282
cust    20
 
283
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith';
 
284
rate_code       base_rate
 
285
cust    20
 
286
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND siteid = 'rivercats';
 
287
rate_code       base_rate
 
288
cust    20
 
289
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE siteid = 'rivercats' AND emp.emp_id = 'psmith';
 
290
rate_code       base_rate
 
291
cust    20
 
292
drop table t1,t2;
 
293
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, Value1 VARCHAR(255));
 
294
CREATE TABLE t2 (ID INTEGER NOT NULL PRIMARY KEY, Value2 VARCHAR(255));
 
295
INSERT INTO t1 VALUES (1, 'A');
 
296
INSERT INTO t2 VALUES (1, 'B');
 
297
SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND (Value1 = 'A' AND Value2 <> 'B');
 
298
ID      Value1  Value2
 
299
SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND Value1 = 'A' AND Value2 <> 'B';
 
300
ID      Value1  Value2
 
301
SELECT * FROM t1 NATURAL JOIN t2 WHERE (Value1 = 'A' AND Value2 <> 'B') AND 1;
 
302
ID      Value1  Value2
 
303
drop table t1,t2;
 
304
CREATE TABLE t1 (a int);
 
305
CREATE TABLE t2 (b int);
 
306
CREATE TABLE t3 (c int);
 
307
SELECT * FROM t1 NATURAL JOIN t2 NATURAL JOIN t3;
 
308
a       b       c
 
309
DROP TABLE t1, t2, t3;
 
310
create table t1 (i int);
 
311
create table t2 (i int);
 
312
create table t3 (i int);
 
313
insert into t1 values(1),(2);
 
314
insert into t2 values(2),(3);
 
315
insert into t3 values (2),(4);
 
316
select * from t1 natural left join t2;
 
317
i
 
318
1
 
319
2
 
320
select * from t1 left join t2 on (t1.i=t2.i);
 
321
i       i
 
322
1       NULL
 
323
2       2
 
324
select * from t1 natural left join t2 natural left join t3;
 
325
i
 
326
1
 
327
2
 
328
select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i);
 
329
i       i       i
 
330
1       NULL    NULL
 
331
2       2       2
 
332
select * from t3 natural right join t2;
 
333
i
 
334
2
 
335
3
 
336
select * from t3 right join t2 on (t3.i=t2.i);
 
337
i       i
 
338
2       2
 
339
NULL    3
 
340
select * from t3 natural right join t2 natural right join t1;
 
341
i
 
342
1
 
343
2
 
344
select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i);
 
345
i       i       i
 
346
NULL    NULL    1
 
347
2       2       2
 
348
select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i;
 
349
i       i
 
350
1       2
 
351
1       3
 
352
2       2
 
353
2       3
 
354
select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
 
355
i       i       i
 
356
1       2       2
 
357
1       3       NULL
 
358
2       2       2
 
359
2       3       NULL
 
360
select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i;
 
361
i       i       i
 
362
1       2       2
 
363
1       3       NULL
 
364
2       2       2
 
365
2       3       NULL
 
366
select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
 
367
i       i       i
 
368
1       2       2
 
369
1       3       NULL
 
370
2       2       2
 
371
2       3       NULL
 
372
select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i;
 
373
i       i
 
374
1       4
 
375
1       2
 
376
2       4
 
377
2       2
 
378
select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
 
379
i       i       i
 
380
1       NULL    4
 
381
1       2       2
 
382
2       NULL    4
 
383
2       2       2
 
384
select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i;
 
385
i       i       i
 
386
1       NULL    4
 
387
1       2       2
 
388
2       NULL    4
 
389
2       2       2
 
390
select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
 
391
i       i       i
 
392
1       NULL    4
 
393
1       2       2
 
394
2       NULL    4
 
395
2       2       2
 
396
drop table t1,t2,t3;
 
397
CREATE TABLE t1 (a int, b int default 0, c int default 1);
 
398
INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
 
399
INSERT INTO t1 (a) SELECT a + 8 FROM t1;
 
400
INSERT INTO t1 (a) SELECT a + 16 FROM t1;
 
401
CREATE TABLE t2 (a int, d int, e int default 0);
 
402
INSERT INTO t2 (a, d) VALUES (1,1),(2,2),(3,3),(4,4);
 
403
INSERT INTO t2 (a, d) SELECT a+4, a+4 FROM t2;
 
404
INSERT INTO t2 (a, d) SELECT a+8, a+8 FROM t2;
 
405
EXPLAIN
 
406
SELECT STRAIGHT_JOIN t2.e FROM t1,t2 WHERE t2.d=1 AND t1.b=t2.e
 
407
ORDER BY t1.b, t1.c;
 
408
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
409
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    32      Using temporary; Using filesort
 
410
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    16      Using where; Using join buffer
 
411
SELECT STRAIGHT_JOIN t2.e FROM t1,t2 WHERE t2.d=1 AND t1.b=t2.e
 
412
ORDER BY t1.b, t1.c;
 
413
e
 
414
0
 
415
0
 
416
0
 
417
0
 
418
0
 
419
0
 
420
0
 
421
0
 
422
0
 
423
0
 
424
0
 
425
0
 
426
0
 
427
0
 
428
0
 
429
0
 
430
0
 
431
0
 
432
0
 
433
0
 
434
0
 
435
0
 
436
0
 
437
0
 
438
0
 
439
0
 
440
0
 
441
0
 
442
0
 
443
0
 
444
0
 
445
0
 
446
DROP TABLE t1,t2;
 
447
create table t1 (c int, b int);
 
448
create table t2 (a int, b int);
 
449
create table t3 (b int, c int);
 
450
create table t4 (y int, c int);
 
451
create table t5 (y int, z int);
 
452
create table t6 (a int, c int);
 
453
insert into t1 values (10,1);
 
454
insert into t1 values (3 ,1);
 
455
insert into t1 values (3 ,2);
 
456
insert into t2 values (2, 1);
 
457
insert into t3 values (1, 3);
 
458
insert into t3 values (1,10);
 
459
insert into t4 values (11,3);
 
460
insert into t4 values (2, 3);
 
461
insert into t5 values (11,4);
 
462
insert into t6 values (2, 3);
 
463
select * from t1 natural join t2;
 
464
b       c       a
 
465
1       10      2
 
466
1       3       2
 
467
select * from t1 natural join t2;
 
468
b       c       a
 
469
1       10      2
 
470
1       3       2
 
471
select b as a, c as b, a as c from t1 natural join t2;
 
472
a       b       c
 
473
1       10      2
 
474
1       3       2
 
475
select a as c, c as b, b as a from t1 natural join t2;
 
476
c       b       a
 
477
2       10      1
 
478
2       3       1
 
479
select t1.c, t1.b, t2.a from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
 
480
c       b       a
 
481
3       1       2
 
482
3       2       2
 
483
select t1.c as b, t1.b as a, t2.a as c
 
484
from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
 
485
b       a       c
 
486
3       1       2
 
487
3       2       2
 
488
select * from t1 natural join (t2 natural join t3);
 
489
c       b       a
 
490
10      1       2
 
491
3       1       2
 
492
select * from (t1 natural join t2) natural join (t3 natural join t4);
 
493
b       c       a       y
 
494
1       3       2       11
 
495
1       3       2       2
 
496
select * from (t1 natural join t2) natural left join (t3 natural join t4);
 
497
b       c       a       y
 
498
1       10      2       NULL
 
499
1       3       2       11
 
500
1       3       2       2
 
501
select * from (t3 natural join t4) natural right join (t1 natural join t2);
 
502
b       c       a       y
 
503
1       10      2       NULL
 
504
1       3       2       11
 
505
1       3       2       2
 
506
select * from (t1 natural left join t2) natural left join (t3 natural left join t4);
 
507
b       c       a       y
 
508
1       10      2       NULL
 
509
1       3       2       11
 
510
1       3       2       2
 
511
2       3       NULL    NULL
 
512
select * from (t4 natural right join t3) natural right join (t2 natural right join t1);
 
513
b       c       a       y
 
514
1       10      2       NULL
 
515
1       3       2       11
 
516
1       3       2       2
 
517
2       3       NULL    NULL
 
518
select * from t1 natural join t2 natural join t3 natural join t4;
 
519
c       b       a       y
 
520
3       1       2       11
 
521
3       1       2       2
 
522
select * from ((t1 natural join t2) natural join t3) natural join t4;
 
523
c       b       a       y
 
524
3       1       2       11
 
525
3       1       2       2
 
526
select * from t1 natural join (t2 natural join (t3 natural join t4));
 
527
c       b       a       y
 
528
3       1       2       11
 
529
3       1       2       2
 
530
select * from t5 natural right join (t4 natural right join ((t2 natural right join t1) natural right join t3));
 
531
y       c       b       a       z
 
532
11      3       1       2       4
 
533
2       3       1       2       NULL
 
534
NULL    10      1       2       NULL
 
535
select * from (t1 natural join t2), (t3 natural join t4);
 
536
b       c       a       c       b       y
 
537
1       10      2       3       1       11
 
538
1       10      2       3       1       2
 
539
1       3       2       3       1       11
 
540
1       3       2       3       1       2
 
541
select * from t5 natural join ((t1 natural join t2), (t3 natural join t4));
 
542
y       z       b       c       a       c       b
 
543
11      4       1       10      2       3       1
 
544
11      4       1       3       2       3       1
 
545
select * from  ((t1 natural join t2),  (t3 natural join t4)) natural join t5;
 
546
y       b       c       a       c       b       z
 
547
11      1       10      2       3       1       4
 
548
11      1       3       2       3       1       4
 
549
select * from t5 natural join ((t1 natural join t2) cross join (t3 natural join t4));
 
550
y       z       b       c       a       c       b
 
551
11      4       1       10      2       3       1
 
552
11      4       1       3       2       3       1
 
553
select * from  ((t1 natural join t2) cross join (t3 natural join t4)) natural join t5;
 
554
y       b       c       a       c       b       z
 
555
11      1       10      2       3       1       4
 
556
11      1       3       2       3       1       4
 
557
select * from (t1 join t2 using (b)) join (t3 join t4 using (c)) using (c);
 
558
c       b       a       b       y
 
559
3       1       2       1       11
 
560
3       1       2       1       2
 
561
select * from (t1 join t2 using (b)) natural join (t3 join t4 using (c));
 
562
b       c       a       y
 
563
1       3       2       11
 
564
1       3       2       2
 
565
select a,b,c from (t1 natural join t2) natural join (t3 natural join t4)
 
566
where b + 1 = y or b + 10 = y group by b,c,a having min(b) < max(y) order by a;
 
567
a       b       c
 
568
2       1       3
 
569
select * from (t1 natural join t2) natural left join (t3 natural join t4)
 
570
where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y;
 
571
b       c       a       y
 
572
1       3       2       2
 
573
1       3       2       11
 
574
select * from (t3 natural join t4) natural right join (t1 natural join t2)
 
575
where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y;
 
576
b       c       a       y
 
577
1       3       2       2
 
578
1       3       2       11
 
579
select * from t1 natural join t2 where t1.c > t2.a;
 
580
b       c       a
 
581
1       10      2
 
582
1       3       2
 
583
select * from t1 natural join t2 where t1.b > t2.b;
 
584
b       c       a
 
585
select * from t1 natural left join (t4 natural join t5) where t5.z is not NULL;
 
586
c       b       y       z
 
587
3       1       11      4
 
588
3       2       11      4
 
589
select * from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
 
590
c       b       a       b       y       c
 
591
3       1       2       1       2       3
 
592
3       2       2       1       2       3
 
593
select * from (t2 join t4 on b + 1 = y) join t1 on t1.c = t4.c;
 
594
a       b       y       c       c       b
 
595
2       1       2       3       3       1
 
596
2       1       2       3       3       2
 
597
select * from t1 natural join (t2 join t4 on b + 1 = y);
 
598
c       b       a       y
 
599
3       1       2       2
 
600
select * from (t1 cross join t2) join (t3 cross join t4) on (a < y and t2.b < t3.c);
 
601
c       b       a       b       b       c       y       c
 
602
10      1       2       1       1       3       11      3
 
603
10      1       2       1       1       10      11      3
 
604
3       1       2       1       1       3       11      3
 
605
3       1       2       1       1       10      11      3
 
606
3       2       2       1       1       3       11      3
 
607
3       2       2       1       1       10      11      3
 
608
select * from (t1, t2) join (t3, t4) on (a < y and t2.b < t3.c);
 
609
c       b       a       b       b       c       y       c
 
610
10      1       2       1       1       3       11      3
 
611
10      1       2       1       1       10      11      3
 
612
3       1       2       1       1       3       11      3
 
613
3       1       2       1       1       10      11      3
 
614
3       2       2       1       1       3       11      3
 
615
3       2       2       1       1       10      11      3
 
616
select * from (t1 natural join t2) join (t3 natural join t4) on a = y;
 
617
b       c       a       c       b       y
 
618
1       10      2       3       1       2
 
619
1       3       2       3       1       2
 
620
select * from ((t3 join (t1 join t2 on c > a) on t3.b < t2.a) join t4 on y > t1.c) join t5 on z = t1.b + 3;
 
621
b       c       c       b       a       b       y       c       y       z
 
622
1       3       10      1       2       1       11      3       11      4
 
623
1       10      10      1       2       1       11      3       11      4
 
624
1       3       3       1       2       1       11      3       11      4
 
625
1       10      3       1       2       1       11      3       11      4
 
626
select * from t1 natural join t2 where t1.b > 0;
 
627
b       c       a
 
628
1       10      2
 
629
1       3       2
 
630
select * from t1 natural join (t4 natural join t5) where t4.y > 7;
 
631
c       b       y       z
 
632
3       1       11      4
 
633
3       2       11      4
 
634
select * from (t4 natural join t5) natural join t1 where t4.y > 7;
 
635
c       y       z       b
 
636
3       11      4       1
 
637
3       11      4       2
 
638
select * from t1 natural left join (t4 natural join t5) where t4.y > 7;
 
639
c       b       y       z
 
640
3       1       11      4
 
641
3       2       11      4
 
642
select * from (t4 natural join t5) natural right join t1 where t4.y > 7;
 
643
c       b       y       z
 
644
3       1       11      4
 
645
3       2       11      4
 
646
select * from (t1 natural join t2) join (t3 natural join t4) on t1.b = t3.b;
 
647
b       c       a       c       b       y
 
648
1       10      2       3       1       11
 
649
1       10      2       3       1       2
 
650
1       3       2       3       1       11
 
651
1       3       2       3       1       2
 
652
select t1.*, t2.* from t1 natural join t2;
 
653
c       b       a       b
 
654
10      1       2       1
 
655
3       1       2       1
 
656
select t1.*, t2.*, t3.*, t4.* from (t1 natural join t2) natural join (t3 natural join t4);
 
657
c       b       a       b       b       c       y       c
 
658
3       1       2       1       1       3       11      3
 
659
3       1       2       1       1       3       2       3
 
660
select * from (select * from t1 natural join t2) as t12
 
661
natural join
 
662
(select * from t3 natural join t4) as t34;
 
663
b       c       a       y
 
664
1       3       2       11
 
665
1       3       2       2
 
666
select * from (select * from t1 natural join t2) as t12
 
667
natural left join
 
668
(select * from t3 natural join t4) as t34;
 
669
b       c       a       y
 
670
1       10      2       NULL
 
671
1       3       2       11
 
672
1       3       2       2
 
673
select * from (select * from t3 natural join t4) as t34
 
674
natural right join
 
675
(select * from t1 natural join t2) as t12;
 
676
b       c       a       y
 
677
1       10      2       NULL
 
678
1       3       2       11
 
679
1       3       2       2
 
680
select * from t1 natural join (t3 cross join t4);
 
681
ERROR 23000: Column 'c' in from clause is ambiguous
 
682
select * from (t3 cross join t4) natural join t1;
 
683
ERROR 23000: Column 'c' in from clause is ambiguous
 
684
select * from t1 join (t2, t3) using (b);
 
685
ERROR 23000: Column 'b' in from clause is ambiguous
 
686
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
 
687
ERROR 23000: Column 'c' in from clause is ambiguous
 
688
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
 
689
ERROR 23000: Column 'c' in from clause is ambiguous
 
690
select * from t6 natural join ((t1 natural join t2),  (t3 natural join t4));
 
691
ERROR 23000: Column 'c' in from clause is ambiguous
 
692
select * from (t1 join t2 on t1.b=t2.b) natural join (t3 natural join t4);
 
693
ERROR 23000: Column 'b' in from clause is ambiguous
 
694
select * from  (t3 natural join t4) natural join (t1 join t2 on t1.b=t2.b);
 
695
ERROR 23000: Column 'b' in from clause is ambiguous
 
696
select * from (t3 join (t4 natural join t5) on (b < z))
 
697
natural join
 
698
(t1 natural join t2);
 
699
ERROR 23000: Column 'c' in from clause is ambiguous
 
700
select * from (t1 natural join t2) natural join (t3 join (t4 natural join t5) on (b < z));
 
701
ERROR 23000: Column 'c' in from clause is ambiguous
 
702
drop table t1;
 
703
drop table t2;
 
704
drop table t3;
 
705
drop table t4;
 
706
drop table t5;
 
707
drop table t6;
 
708
create table t1 (a1 int, a2 int);
 
709
create table t2 (a1 int, b int);
 
710
create table t3 (c1 int, c2 int);
 
711
create table t4 (c2 int);
 
712
insert into t1 values (1,1);
 
713
insert into t2 values (1,1);
 
714
insert into t3 values (1,1);
 
715
insert into t4 values (1);
 
716
select * from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
 
717
c2      a1      a2      b       c1
 
718
1       1       1       1       1
 
719
select * from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
 
720
c2      c1      a1      a2      b
 
721
1       1       1       1       1
 
722
select a2 from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
 
723
a2
 
724
1
 
725
select a2 from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
 
726
a2
 
727
1
 
728
select a2 from ((t1 join t2 using (a1)) join t3 on b=c1) join t4 using (c2);
 
729
a2
 
730
1
 
731
select a2 from ((t1 natural join t2) join t3 on b=c1) natural join t4;
 
732
a2
 
733
1
 
734
drop table t1,t2,t3,t4;
 
735
create table t1 (c int, b int);
 
736
create table t2 (a int, b int);
 
737
create table t3 (b int, c int);
 
738
create table t4 (y int, c int);
 
739
create table t5 (y int, z int);
 
740
insert into t1 values (3,2);
 
741
insert into t2 values (1,2);
 
742
insert into t3 values (2,3);
 
743
insert into t4 values (1,3);
 
744
insert into t5 values (1,4);
 
745
select * from ((t3 natural join (t1 natural join t2)) natural join t4)
 
746
natural join t5;
 
747
y       c       b       a       z
 
748
1       3       2       1       4
 
749
drop table t1, t2, t3, t4, t5;
 
750
create table t1 (a int, b int);
 
751
insert into t1 values 
 
752
(NULL, 1),
 
753
(NULL, 2),
 
754
(NULL, 3),
 
755
(NULL, 4);
 
756
create table t2 (a int not null, primary key(a));
 
757
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
758
create table t3 (a int not null, primary key(a));
 
759
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
760
flush status;
 
761
select * from t1, t2, t3 where t3.a=t1.a and t2.a=t1.b;
 
762
a       b       a       a
 
763
explain select * from t1, t2, t3 where t3.a=t1.a and t2.a=t1.b;
 
764
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
765
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       
 
766
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.b       1       Using index
 
767
1       SIMPLE  t3      eq_ref  PRIMARY PRIMARY 4       test.t1.a       1       Using index
 
768
We expect rnd_next=5, and read_key must be 0 because of short-cutting:
 
769
show status like 'Handler_read%';
 
770
Variable_name   Value
 
771
Handler_read_first      #
 
772
Handler_read_key        #
 
773
Handler_read_next       #
 
774
Handler_read_prev       #
 
775
Handler_read_rnd        #
 
776
Handler_read_rnd_next   #
 
777
drop table t1, t2, t3;
 
778
create table t1 (a int);
 
779
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
780
create table t2 (a int, b int, filler char(100), key(a), key(b));
 
781
create table t3 (a int, b int, filler char(100), key(a), key(b));
 
782
insert into t2 
 
783
select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C;
 
784
insert into t3 select * from t2 where a < 800;
 
785
drop table t1, t2, t3;
 
786
create table t1 (a int);
 
787
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
788
create table t2 (a int, b int, primary key(a));
 
789
insert into t2 select @v:=A.a+10*B.a, @v  from t1 A, t1 B;
 
790
explain select * from t1;
 
791
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
792
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    10      
 
793
show status like '%cost%';
 
794
Variable_name   Value
 
795
Last_query_cost #
 
796
select 'The cost of accessing t1 (dont care if it changes' '^';
 
797
The cost of accessing t1 (dont care if it changes
 
798
The cost of accessing t1 (dont care if it changes^
 
799
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
 
800
Z
 
801
vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv
 
802
explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b;
 
803
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
804
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    10      
 
805
1       SIMPLE  A       eq_ref  PRIMARY PRIMARY 4       test.t1.a       1       
 
806
1       SIMPLE  B       eq_ref  PRIMARY PRIMARY 4       test.A.b        1       
 
807
show status like '%cost%';
 
808
Variable_name   Value
 
809
Last_query_cost #
 
810
select '^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error' Z;
 
811
Z
 
812
^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error
 
813
drop table t1, t2;
 
814
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
 
815
CREATE TABLE t2 (c INT PRIMARY KEY, d INT);
 
816
INSERT INTO t1 VALUES(1,NULL),(2,NULL),(3,NULL),(4,NULL);
 
817
INSERT INTO t1 SELECT a + 4, b FROM t1;
 
818
INSERT INTO t1 SELECT a + 8, b FROM t1;
 
819
INSERT INTO t1 SELECT a + 16, b FROM t1;
 
820
INSERT INTO t1 SELECT a + 32, b FROM t1;
 
821
INSERT INTO t1 SELECT a + 64, b FROM t1;
 
822
INSERT INTO t2 SELECT a, b FROM t1;
 
823
EXPLAIN SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a LIMIT 2;
 
824
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
825
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    2       
 
826
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.b       1       
 
827
EXPLAIN SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a LIMIT 2;
 
828
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
829
1       SIMPLE  t1      index   PRIMARY PRIMARY 4       NULL    2       
 
830
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.a       1       
 
831
SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a LIMIT 2;
 
832
a       b       c       d
 
833
SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a LIMIT 2;
 
834
a       b       c       d
 
835
1       NULL    1       NULL
 
836
2       NULL    2       NULL
 
837
EXPLAIN SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a;
 
838
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
839
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    128     Using filesort
 
840
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.b       1       
 
841
EXPLAIN SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a;
 
842
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
843
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    128     Using filesort
 
844
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.a       1       
 
845
SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a;
 
846
a       b       c       d
 
847
SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a;
 
848
a       b       c       d
 
849
1       NULL    1       NULL
 
850
2       NULL    2       NULL
 
851
3       NULL    3       NULL
 
852
4       NULL    4       NULL
 
853
5       NULL    5       NULL
 
854
6       NULL    6       NULL
 
855
7       NULL    7       NULL
 
856
8       NULL    8       NULL
 
857
9       NULL    9       NULL
 
858
10      NULL    10      NULL
 
859
11      NULL    11      NULL
 
860
12      NULL    12      NULL
 
861
13      NULL    13      NULL
 
862
14      NULL    14      NULL
 
863
15      NULL    15      NULL
 
864
16      NULL    16      NULL
 
865
17      NULL    17      NULL
 
866
18      NULL    18      NULL
 
867
19      NULL    19      NULL
 
868
20      NULL    20      NULL
 
869
21      NULL    21      NULL
 
870
22      NULL    22      NULL
 
871
23      NULL    23      NULL
 
872
24      NULL    24      NULL
 
873
25      NULL    25      NULL
 
874
26      NULL    26      NULL
 
875
27      NULL    27      NULL
 
876
28      NULL    28      NULL
 
877
29      NULL    29      NULL
 
878
30      NULL    30      NULL
 
879
31      NULL    31      NULL
 
880
32      NULL    32      NULL
 
881
33      NULL    33      NULL
 
882
34      NULL    34      NULL
 
883
35      NULL    35      NULL
 
884
36      NULL    36      NULL
 
885
37      NULL    37      NULL
 
886
38      NULL    38      NULL
 
887
39      NULL    39      NULL
 
888
40      NULL    40      NULL
 
889
41      NULL    41      NULL
 
890
42      NULL    42      NULL
 
891
43      NULL    43      NULL
 
892
44      NULL    44      NULL
 
893
45      NULL    45      NULL
 
894
46      NULL    46      NULL
 
895
47      NULL    47      NULL
 
896
48      NULL    48      NULL
 
897
49      NULL    49      NULL
 
898
50      NULL    50      NULL
 
899
51      NULL    51      NULL
 
900
52      NULL    52      NULL
 
901
53      NULL    53      NULL
 
902
54      NULL    54      NULL
 
903
55      NULL    55      NULL
 
904
56      NULL    56      NULL
 
905
57      NULL    57      NULL
 
906
58      NULL    58      NULL
 
907
59      NULL    59      NULL
 
908
60      NULL    60      NULL
 
909
61      NULL    61      NULL
 
910
62      NULL    62      NULL
 
911
63      NULL    63      NULL
 
912
64      NULL    64      NULL
 
913
65      NULL    65      NULL
 
914
66      NULL    66      NULL
 
915
67      NULL    67      NULL
 
916
68      NULL    68      NULL
 
917
69      NULL    69      NULL
 
918
70      NULL    70      NULL
 
919
71      NULL    71      NULL
 
920
72      NULL    72      NULL
 
921
73      NULL    73      NULL
 
922
74      NULL    74      NULL
 
923
75      NULL    75      NULL
 
924
76      NULL    76      NULL
 
925
77      NULL    77      NULL
 
926
78      NULL    78      NULL
 
927
79      NULL    79      NULL
 
928
80      NULL    80      NULL
 
929
81      NULL    81      NULL
 
930
82      NULL    82      NULL
 
931
83      NULL    83      NULL
 
932
84      NULL    84      NULL
 
933
85      NULL    85      NULL
 
934
86      NULL    86      NULL
 
935
87      NULL    87      NULL
 
936
88      NULL    88      NULL
 
937
89      NULL    89      NULL
 
938
90      NULL    90      NULL
 
939
91      NULL    91      NULL
 
940
92      NULL    92      NULL
 
941
93      NULL    93      NULL
 
942
94      NULL    94      NULL
 
943
95      NULL    95      NULL
 
944
96      NULL    96      NULL
 
945
97      NULL    97      NULL
 
946
98      NULL    98      NULL
 
947
99      NULL    99      NULL
 
948
100     NULL    100     NULL
 
949
101     NULL    101     NULL
 
950
102     NULL    102     NULL
 
951
103     NULL    103     NULL
 
952
104     NULL    104     NULL
 
953
105     NULL    105     NULL
 
954
106     NULL    106     NULL
 
955
107     NULL    107     NULL
 
956
108     NULL    108     NULL
 
957
109     NULL    109     NULL
 
958
110     NULL    110     NULL
 
959
111     NULL    111     NULL
 
960
112     NULL    112     NULL
 
961
113     NULL    113     NULL
 
962
114     NULL    114     NULL
 
963
115     NULL    115     NULL
 
964
116     NULL    116     NULL
 
965
117     NULL    117     NULL
 
966
118     NULL    118     NULL
 
967
119     NULL    119     NULL
 
968
120     NULL    120     NULL
 
969
121     NULL    121     NULL
 
970
122     NULL    122     NULL
 
971
123     NULL    123     NULL
 
972
124     NULL    124     NULL
 
973
125     NULL    125     NULL
 
974
126     NULL    126     NULL
 
975
127     NULL    127     NULL
 
976
128     NULL    128     NULL
 
977
DROP TABLE IF EXISTS t1,t2;
 
978
End of 5.0 tests.