~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/pbxt/join.result

  • Committer: Jay Pipes
  • Date: 2010-03-09 20:02:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1339.
  • Revision ID: jpipes@serialcoder-20100309200229-dfrliy4fads9vyf4
Fixes Bug #535296 by only incrementing ha_commit_count when its a normal transaction commit.

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