~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Check null keys
3
4
--disable_warnings
5
drop table if exists t1,t2;
6
--enable_warnings
7
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
8
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
1 by brian
clean slate
9
insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6);
10
explain select * from t1 where a is null;
11
explain select * from t1 where a is null and b = 2;
12
explain select * from t1 where a is null and b = 7;
13
explain select * from t1 where a=2 and b = 2;
14
explain select * from t1 where a<=>b limit 2;
15
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
16
explain select * from t1 where (a is null or a = 7) and b=7;
17
explain select * from t1 where (a is null or a = 7) and b=7 order by a;
18
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
19
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
20
explain select * from t1 where a > 1 and a < 3 limit 1;
21
explain select * from t1 where a > 8 and a < 9;
22
select * from t1 where a is null;
23
select * from t1 where a is null and b = 7;
24
select * from t1 where a<=>b limit 2;
25
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
26
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
27
select * from t1 where (a is null or a = 7) and b=7;
28
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
29
select * from t1 where a > 1 and a < 3 limit 1;
30
select * from t1 where a > 8 and a < 9;
31
create table t2 like t1;
32
insert into t2 select * from t1;
33
alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10));
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
34
# @TODO Should this be a MyISAM-specific test or not?
35
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
36
--replace_column 9 X
1 by brian
clean slate
37
explain select * from t1 where a is null and b = 2;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
38
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
39
--replace_column 9 X
1 by brian
clean slate
40
explain select * from t1 where a is null and b = 2 and c=0;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
41
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
42
--replace_column 9 X
1 by brian
clean slate
43
explain select * from t1 where a is null and b = 7 and c=0;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
44
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
45
--replace_column 9 X
1 by brian
clean slate
46
explain select * from t1 where a=2 and b = 2;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
47
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
48
--replace_column 9 X
1 by brian
clean slate
49
explain select * from t1 where a<=>b limit 2;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
50
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
51
--replace_column 9 X
1 by brian
clean slate
52
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
53
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
54
--replace_column 9 X
1 by brian
clean slate
55
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
56
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
57
--replace_column 9 X
1 by brian
clean slate
58
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
59
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
60
--replace_column 9 X
1 by brian
clean slate
61
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
62
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
63
--replace_column 9 X
1 by brian
clean slate
64
explain select * from t1 where a > 1 and a < 3 limit 1;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
65
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
66
--replace_column 9 X
1 by brian
clean slate
67
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
68
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
69
--replace_column 9 X
1 by brian
clean slate
70
explain select * from t1 where a > 8 and a < 9;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
71
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
72
--replace_column 9 X
1 by brian
clean slate
73
explain select * from t1 where b like "6%";
74
select * from t1 where a is null;
75
select * from t1 where a is null and b = 7 and c=0;
76
select * from t1 where a<=>b limit 2;
77
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
78
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
79
select * from t1 where (a is null or a = 7) and b=7 and c=0;
80
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
81
select * from t1 where b like "6%";
82
83
#
84
# Test ref_or_null optimization
85
#
86
drop table t1;
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
87
# @TODO Bug in the following RENAME...changing it out for now.
88
# rename table t2 to t1;
89
drop table t2;
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
90
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
1 by brian
clean slate
91
alter table t1 modify b int null;
92
insert into t1 values (7,null), (8,null), (8,7);
93
explain select * from t1 where a = 7 and (b=7 or b is null);
94
select * from t1 where a = 7 and (b=7 or b is null);
95
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
96
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
97
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
98
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
99
create table t2 (a int);
100
insert into t2 values (7),(8);
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
101
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
102
--replace_column 9 X
1 by brian
clean slate
103
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
104
drop index b on t1;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
105
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
106
--replace_column 9 X
1 by brian
clean slate
107
explain select * from t2,t1 where t1.a=t2.a and b is null;
108
select * from t2,t1 where t1.a=t2.a and b is null;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
109
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
110
--replace_column 9 X
1 by brian
clean slate
111
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
112
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
113
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
114
--replace_column 9 X
1 by brian
clean slate
115
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
116
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
117
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
118
--replace_column 9 X
1 by brian
clean slate
119
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
120
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
121
insert into t2 values (null),(6);
122
delete from t1 where a=8;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
123
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
124
--replace_column 9 X
1 by brian
clean slate
125
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
685.4.32 by Jay Pipes
Ignore 9th column in EXPLAIN output for InnoDB table (rows are inaccurate)
126
# Ignore "rows" in output -- inaccurate for InnoDB
730 by jay
Forgot to --record the damn null_key test after adding regex-replaces for the InnoDB rows output in EXPLAIN
127
--replace_column 9 X
1 by brian
clean slate
128
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
129
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
130
drop table t1,t2;
131
132
#
133
# The following failed for Matt Loschert
134
#
135
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
136
CREATE TEMPORARY TABLE t1 (
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
137
  id int NOT NULL auto_increment,
138
  uniq_id int default NULL,
1 by brian
clean slate
139
  PRIMARY KEY  (id),
140
  UNIQUE KEY idx1 (uniq_id)
141
) ENGINE=MyISAM;
142
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
143
CREATE TEMPORARY TABLE t2 (
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
144
  id int NOT NULL auto_increment,
145
  uniq_id int default NULL,
1 by brian
clean slate
146
  PRIMARY KEY  (id)
147
) ENGINE=MyISAM;
148
149
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
150
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
151
152
#
153
# Check IS NULL optimization
154
#
155
explain select id from t1 where uniq_id is null;
156
explain select id from t1 where uniq_id =1;
157
#
158
# Check updates
159
#
160
UPDATE t1 SET id=id+100 where uniq_id is null;
161
UPDATE t2 SET id=id+100 where uniq_id is null;
162
select id from t1 where uniq_id is null;
163
select id from t2 where uniq_id is null;
164
#
165
# Delete all records from each table where the uniq_id field is null
166
#
167
DELETE FROM t1 WHERE uniq_id IS NULL;
168
DELETE FROM t2 WHERE uniq_id IS NULL;
169
#
170
# Select what is left -- notice the difference
171
#
172
SELECT * FROM t1 ORDER BY uniq_id, id;
173
SELECT * FROM t2 ORDER BY uniq_id, id;
174
DROP table t1,t2;
175
176
#
177
# This crashed MySQL 3.23.47
178
#
179
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
180
CREATE TEMPORARY TABLE `t1` (
1 by brian
clean slate
181
  `order_id` char(32) NOT NULL default '',
182
  `product_id` char(32) NOT NULL default '',
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
183
  `product_type` int NOT NULL default '0',
1 by brian
clean slate
184
  PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
185
) ENGINE=MyISAM;
1063.9.18 by Stewart Smith
null_key for MyISAM temp only: use temp myisam tables
186
CREATE TEMPORARY TABLE `t2` (
1 by brian
clean slate
187
  `order_id` char(32) NOT NULL default '',
188
  `product_id` char(32) NOT NULL default '',
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
189
  `product_type` int NOT NULL default '0',
1 by brian
clean slate
190
  PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
191
) ENGINE=MyISAM;
192
INSERT INTO t1 (order_id, product_id, product_type) VALUES
193
('3d7ce39b5d4b3e3d22aaafe9b633de51',1206029, 3),
194
('3d7ce39b5d4b3e3d22aaafe9b633de51',5880836, 3),
195
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
196
INSERT INTO t2 (order_id, product_id, product_type) VALUES
197
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
198
199
select t1.* from t1
200
left join t2 using(order_id, product_id, product_type)
201
where t2.order_id=NULL;
202
select t1.* from t1
203
left join t2 using(order_id, product_id, product_type)
204
where t2.order_id is NULL;
205
drop table t1,t2;
206
207
#
208
# The last select returned wrong results in 3.23.52
209
#
210
211
create table t1 (id int);
212
insert into t1 values (null), (0);
213
create table t2 (id int);
214
insert into t2 values (null);
215
select * from t1, t2 where t1.id = t2.id;
216
alter table t1 add key id (id);
217
select * from t1, t2 where t1.id = t2.id;
218
drop table t1,t2;
219
220
#
221
# Check bug when doing <=> NULL on an indexed null field
222
#
223
224
create table t1 (
225
  id  integer,
226
  id2 integer not null,
227
  index (id),
228
  index (id2)
229
);
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
230
--error 1048
1 by brian
clean slate
231
insert into t1 values(null,null),(1,1);
232
select * from t1;
233
select * from t1 where id <=> null;
234
select * from t1 where id <=> null or id > 0;
235
select * from t1 where id is null or id > 0;
236
select * from t1 where id2 <=> null or id2 > 0;
237
select * from t1 where id2 is null or id2 > 0;
238
delete from t1 where id <=> NULL;
239
select * from t1;
240
drop table t1;
241
242
#
243
# Test for bug #12144: optimizations for key access with null keys 
244
#                      used for outer joins
245
#
246
247
CREATE TABLE t1 (a int);
248
CREATE TABLE t2 (a int, b int, INDEX idx(a));
249
CREATE TABLE t3 (b int, INDEX idx(b));
250
CREATE TABLE t4 (b int, INDEX idx(b));
251
INSERT INTO t1 VALUES (1), (2), (3), (4);
252
INSERT INTO t2 VALUES (1, 1), (3, 1);
253
INSERT INTO t3 VALUES 
254
  (NULL), (NULL), (NULL), (NULL), (NULL),
255
  (NULL), (NULL), (NULL), (NULL), (NULL);
256
INSERT INTO t4 SELECT * FROM t3;
257
INSERT INTO t3 SELECT * FROM t4;
258
INSERT INTO t4 SELECT * FROM t3;
259
INSERT INTO t3 SELECT * FROM t4;
260
INSERT INTO t4 SELECT * FROM t3;
261
INSERT INTO t3 SELECT * FROM t4;
262
INSERT INTO t4 SELECT * FROM t3;
263
INSERT INTO t3 SELECT * FROM t4;
264
INSERT INTO t4 SELECT * FROM t3;
265
INSERT INTO t3 SELECT * FROM t4;
266
INSERT INTO t4 SELECT * FROM t3;
267
INSERT INTO t3 SELECT * FROM t4;
268
INSERT INTO t4 SELECT * FROM t3;
269
INSERT INTO t3 SELECT * FROM t4;
270
INSERT INTO t4 SELECT * FROM t3;
271
INSERT INTO t3 SELECT * FROM t4;
272
INSERT INTO t3 VALUES (2), (3);
273
274
ANALYZE table t1, t2, t3;
275
276
SELECT COUNT(*) FROM t3;
277
685.4.25 by Jay Pipes
Ignore rows in EXPLAIN output for InnoDB - they are inaccurate
278
# Ignore the 9th column (rows in EXPLAIN output - inaccurate in InnoDB)
731 by jay
Had a --regex-replace by accident. Should have been --replace_column call. Only showed up in make test, not running single test, because InnoDB key numbers were different with multiple test running.
279
--replace_column 9 X
1 by brian
clean slate
280
EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
281
                                             LEFT JOIN t3 ON t2.b=t3.b;
282
FLUSH STATUS ;
283
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
284
                                     LEFT JOIN t3 ON t2.b=t3.b;
285
SELECT FOUND_ROWS();
286
SHOW STATUS LIKE "handler_read%";
287
288
DROP TABLE t1,t2,t3,t4;
289
# End of 4.1 tests
290
291
#
292
# BUG#34945 "ref_or_null queries that are null_rejecting and have a null value crash mysql"
293
# 
294
CREATE TABLE t1 (
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
295
  a int default NULL,
296
  b int default NULL,
1 by brian
clean slate
297
  KEY a (a,b)
298
);
299
INSERT INTO t1 VALUES (0,10),(0,11),(0,12);
300
301
CREATE TABLE t2 (
685.4.17 by Jay Pipes
Fixes null_key.test. Mostly differences in EXPLAIN output which may be looked at later. Also, adds exception check for NULL values in multi-row INSERT
302
  a int default NULL,
303
  b int default NULL,
1 by brian
clean slate
304
  KEY a (a)
305
);
306
INSERT INTO t2 VALUES (3,NULL),(3,11),(3,12);
307
308
SELECT * FROM t2 inner join t1 WHERE ( t1.a = 0 OR t1.a IS NULL) AND t2.a = 3 AND t2.b = t1.b;
309
310
drop table t1, t2;
311
-- echo End of 5.0 tests
312