~drizzle-trunk/drizzle/development

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