~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/null_key.result

  • Committer: Monty Taylor
  • Date: 2008-11-07 00:15:51 UTC
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: monty@inaugust.com-20081107001551-8vxb6sf1ti0i5p09
Cleaned up some headers for PCH.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
drop table if exists t1,t2;
2
 
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
3
 
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);
4
 
explain select * from t1 where a is null;
5
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
6
 
1       SIMPLE  t1      ref     a       a       5       const   3       Using where; Using index
7
 
explain select * from t1 where a is null and b = 2;
8
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
9
 
1       SIMPLE  t1      ref     a,b     a       9       const,const     1       Using where; Using index
10
 
explain select * from t1 where a is null and b = 7;
11
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
12
 
1       SIMPLE  t1      ref     a,b     a       9       const,const     1       Using where; Using index
13
 
explain select * from t1 where a=2 and b = 2;
14
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
15
 
1       SIMPLE  t1      const   a,b     a       9       const,const     1       Using index
16
 
explain select * from t1 where a<=>b limit 2;
17
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
18
 
1       SIMPLE  t1      index   NULL    a       9       NULL    12      Using where; Using index
19
 
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
20
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
21
 
1       SIMPLE  t1      range   a,b     a       9       NULL    3       Using where; Using index
22
 
explain select * from t1 where (a is null or a = 7) and b=7;
23
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
24
 
1       SIMPLE  t1      ref_or_null     a,b     a       9       const,const     2       Using where; Using index
25
 
explain select * from t1 where (a is null or a = 7) and b=7 order by a;
26
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
27
 
1       SIMPLE  t1      ref_or_null     a,b     a       9       const,const     2       Using where; Using index; Using filesort
28
 
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
29
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
30
 
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where; Using index
31
 
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
32
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
33
 
1       SIMPLE  t1      range   a,b     a       9       NULL    3       Using where; Using index
34
 
explain select * from t1 where a > 1 and a < 3 limit 1;
35
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
36
 
1       SIMPLE  t1      range   a       a       5       NULL    1       Using where; Using index
37
 
explain select * from t1 where a > 8 and a < 9;
38
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
39
 
1       SIMPLE  t1      range   a       a       5       NULL    1       Using where; Using index
40
 
select * from t1 where a is null;
41
 
a       b
42
 
NULL    7
43
 
NULL    9
44
 
NULL    9
45
 
select * from t1 where a is null and b = 7;
46
 
a       b
47
 
NULL    7
48
 
select * from t1 where a<=>b limit 2;
49
 
a       b
50
 
1       1
51
 
2       2
52
 
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
53
 
a       b
54
 
1       1
55
 
2       2
56
 
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
57
 
a       b
58
 
NULL    9
59
 
NULL    9
60
 
select * from t1 where (a is null or a = 7) and b=7;
61
 
a       b
62
 
7       7
63
 
NULL    7
64
 
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
65
 
a       b
66
 
NULL    7
67
 
NULL    9
68
 
NULL    9
69
 
select * from t1 where a > 1 and a < 3 limit 1;
70
 
a       b
71
 
2       2
72
 
select * from t1 where a > 8 and a < 9;
73
 
a       b
74
 
create table t2 like t1;
75
 
ERROR HY000: Can't create table 'test.t2' (errno: 138)
76
 
create temporary table t2 like t1;
77
 
show create table t2;
78
 
Table   Create Table
79
 
t2      CREATE TEMPORARY TABLE `t2` (
80
 
  `a` INT DEFAULT NULL,
81
 
  `b` INT NOT NULL,
82
 
  UNIQUE KEY `a` (`a`,`b`),
83
 
  KEY `b` (`b`)
84
 
) ENGINE=MyISAM COLLATE = utf8_general_ci
85
 
insert into t2 select * from t1;
86
 
alter table t1 modify b blob not null, add c int DEFAULT 42 not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10));
87
 
explain select * from t1 where a is null and b = 2;
88
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
89
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
90
 
explain select * from t1 where a is null and b = 2 and c=0;
91
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
92
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
93
 
explain select * from t1 where a is null and b = 7 and c=0;
94
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
95
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
96
 
explain select * from t1 where a=2 and b = 2;
97
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
98
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
99
 
explain select * from t1 where a<=>b limit 2;
100
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
101
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    X       Using where
102
 
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
103
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
104
 
1       SIMPLE  t1      range   a,b     a       5       NULL    X       Using where
105
 
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
106
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
107
 
1       SIMPLE  t1      ref_or_null     a,b     a       5       const   X       Using where
108
 
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
109
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
110
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
111
 
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
112
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
113
 
1       SIMPLE  t1      ref     a,b     a       5       const   X       Using where
114
 
explain select * from t1 where a > 1 and a < 3 limit 1;
115
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
116
 
1       SIMPLE  t1      range   a       a       5       NULL    X       Using where
117
 
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
118
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
119
 
1       SIMPLE  t1      range   a,b     a       5       NULL    X       Using where
120
 
explain select * from t1 where a > 8 and a < 9;
121
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
122
 
1       SIMPLE  t1      range   a       a       5       NULL    X       Using where
123
 
explain select * from t1 where b like "6%";
124
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
125
 
1       SIMPLE  t1      range   b       b       12      NULL    X       Using where
126
 
select * from t1 where a is null;
127
 
a       b       c
128
 
NULL    7       42
129
 
NULL    9       42
130
 
NULL    9       42
131
 
select * from t1 where a is null and b = 7 and c=0;
132
 
a       b       c
133
 
select * from t1 where a<=>b limit 2;
134
 
a       b       c
135
 
1       1       42
136
 
2       2       42
137
 
select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
138
 
a       b       c
139
 
1       1       42
140
 
2       2       42
141
 
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
142
 
a       b       c
143
 
NULL    9       42
144
 
NULL    9       42
145
 
select * from t1 where (a is null or a = 7) and b=7 and c=0;
146
 
a       b       c
147
 
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
148
 
a       b       c
149
 
NULL    7       42
150
 
NULL    9       42
151
 
NULL    9       42
152
 
select * from t1 where b like "6%";
153
 
a       b       c
154
 
6       6       42
155
 
drop table t1;
156
 
drop table t2;
157
 
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
158
 
alter table t1 modify b int null;
159
 
insert into t1 values (7,null), (8,null), (8,7);
160
 
explain select * from t1 where a = 7 and (b=7 or b is null);
161
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
162
 
1       SIMPLE  t1      ref_or_null     a,b     a       10      const,const     2       Using where; Using index
163
 
select * from t1 where a = 7 and (b=7 or b is null);
164
 
a       b
165
 
7       NULL
166
 
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
167
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
168
 
1       SIMPLE  t1      ref_or_null     a,b     a       5       const   2       Using where; Using index
169
 
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
170
 
a       b
171
 
7       NULL
172
 
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
173
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
174
 
1       SIMPLE  t1      ref_or_null     a       a       5       const   2       Using where; Using index
175
 
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
176
 
a       b
177
 
7       NULL
178
 
create table t2 (a int);
179
 
insert into t2 values (7),(8);
180
 
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
181
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
182
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
183
 
1       SIMPLE  t1      ref     a,b     b       5       const   X       Using where
184
 
drop index b on t1;
185
 
explain select * from t2,t1 where t1.a=t2.a and b is null;
186
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
187
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
188
 
1       SIMPLE  t1      ref     a       a       10      test.t2.a,const X       Using where; Using index
189
 
select * from t2,t1 where t1.a=t2.a and b is null;
190
 
a       a       b
191
 
7       7       NULL
192
 
8       8       NULL
193
 
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
194
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
195
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
196
 
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const X       Using where; Using index
197
 
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
198
 
a       a       b
199
 
7       7       NULL
200
 
8       8       7
201
 
8       8       NULL
202
 
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
203
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
204
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
205
 
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const X       Using where; Using index
206
 
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
207
 
a       a       b
208
 
8       8       7
209
 
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
210
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
211
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
212
 
1       SIMPLE  t1      ref_or_null     a       a       5       test.t2.a       X       Using where; Using index
213
 
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
214
 
a       a       b
215
 
7       7       NULL
216
 
8       8       NULL
217
 
8       8       7
218
 
insert into t2 values (null),(6);
219
 
delete from t1 where a=8;
220
 
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
221
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
222
 
1       SIMPLE  t1      system  a       NULL    NULL    NULL    X       
223
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       Using where
224
 
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
225
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
226
 
1       SIMPLE  t1      system  a       NULL    NULL    NULL    X       
227
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       Using where
228
 
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
229
 
a       a       b
230
 
7       7       NULL
231
 
drop table t1,t2;
232
 
CREATE TEMPORARY TABLE t1 (
233
 
id int NOT NULL auto_increment,
234
 
uniq_id int default NULL,
235
 
PRIMARY KEY  (id),
236
 
UNIQUE KEY idx1 (uniq_id)
237
 
) ENGINE=MyISAM;
238
 
CREATE TEMPORARY TABLE t2 (
239
 
id int NOT NULL auto_increment,
240
 
uniq_id int default NULL,
241
 
PRIMARY KEY  (id)
242
 
) ENGINE=MyISAM;
243
 
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
244
 
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
245
 
explain select id from t1 where uniq_id is null;
246
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
247
 
1       SIMPLE  t1      ref     idx1    idx1    5       const   5       Using where
248
 
explain select id from t1 where uniq_id =1;
249
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
250
 
1       SIMPLE  t1      const   idx1    idx1    5       const   1       
251
 
UPDATE t1 SET id=id+100 where uniq_id is null;
252
 
UPDATE t2 SET id=id+100 where uniq_id is null;
253
 
select id from t1 where uniq_id is null;
254
 
id
255
 
101
256
 
102
257
 
105
258
 
106
259
 
109
260
 
110
261
 
select id from t2 where uniq_id is null;
262
 
id
263
 
101
264
 
102
265
 
105
266
 
106
267
 
109
268
 
110
269
 
DELETE FROM t1 WHERE uniq_id IS NULL;
270
 
DELETE FROM t2 WHERE uniq_id IS NULL;
271
 
SELECT * FROM t1 ORDER BY uniq_id, id;
272
 
id      uniq_id
273
 
3       1
274
 
4       2
275
 
7       3
276
 
8       4
277
 
SELECT * FROM t2 ORDER BY uniq_id, id;
278
 
id      uniq_id
279
 
3       1
280
 
4       2
281
 
7       3
282
 
8       4
283
 
DROP table t1,t2;
284
 
CREATE TEMPORARY TABLE `t1` (
285
 
`order_id` char(32) NOT NULL default '',
286
 
`product_id` char(32) NOT NULL default '',
287
 
`product_type` int NOT NULL default '0',
288
 
PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
289
 
) ENGINE=MyISAM;
290
 
CREATE TEMPORARY TABLE `t2` (
291
 
`order_id` char(32) NOT NULL default '',
292
 
`product_id` char(32) NOT NULL default '',
293
 
`product_type` int NOT NULL default '0',
294
 
PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
295
 
) ENGINE=MyISAM;
296
 
INSERT INTO t1 (order_id, product_id, product_type) VALUES
297
 
('3d7ce39b5d4b3e3d22aaafe9b633de51',1206029, 3),
298
 
('3d7ce39b5d4b3e3d22aaafe9b633de51',5880836, 3),
299
 
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
300
 
INSERT INTO t2 (order_id, product_id, product_type) VALUES
301
 
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
302
 
select t1.* from t1
303
 
left join t2 using(order_id, product_id, product_type)
304
 
where t2.order_id=NULL;
305
 
order_id        product_id      product_type
306
 
select t1.* from t1
307
 
left join t2 using(order_id, product_id, product_type)
308
 
where t2.order_id is NULL;
309
 
order_id        product_id      product_type
310
 
3d7ce39b5d4b3e3d22aaafe9b633de51        1206029 3
311
 
3d7ce39b5d4b3e3d22aaafe9b633de51        5880836 3
312
 
drop table t1,t2;
313
 
create table t1 (id int);
314
 
insert into t1 values (null), (0);
315
 
create table t2 (id int);
316
 
insert into t2 values (null);
317
 
select * from t1, t2 where t1.id = t2.id;
318
 
id      id
319
 
alter table t1 add key id (id);
320
 
select * from t1, t2 where t1.id = t2.id;
321
 
id      id
322
 
drop table t1,t2;
323
 
create table t1 (
324
 
id  integer,
325
 
id2 integer not null,
326
 
index (id),
327
 
index (id2)
328
 
);
329
 
insert into t1 values(null,null),(1,1);
330
 
ERROR 23000: Column 'id2' cannot be null
331
 
select * from t1;
332
 
id      id2
333
 
select * from t1 where id <=> null;
334
 
id      id2
335
 
select * from t1 where id <=> null or id > 0;
336
 
id      id2
337
 
select * from t1 where id is null or id > 0;
338
 
id      id2
339
 
select * from t1 where id2 <=> null or id2 > 0;
340
 
id      id2
341
 
select * from t1 where id2 is null or id2 > 0;
342
 
id      id2
343
 
delete from t1 where id <=> NULL;
344
 
select * from t1;
345
 
id      id2
346
 
drop table t1;
347
 
CREATE TABLE t1 (a int);
348
 
CREATE TABLE t2 (a int, b int, INDEX idx(a));
349
 
CREATE TABLE t3 (b int, INDEX idx(b));
350
 
CREATE TABLE t4 (b int, INDEX idx(b));
351
 
INSERT INTO t1 VALUES (1), (2), (3), (4);
352
 
INSERT INTO t2 VALUES (1, 1), (3, 1);
353
 
INSERT INTO t3 VALUES 
354
 
(NULL), (NULL), (NULL), (NULL), (NULL),
355
 
(NULL), (NULL), (NULL), (NULL), (NULL);
356
 
INSERT INTO t4 SELECT * FROM t3;
357
 
INSERT INTO t3 SELECT * FROM t4;
358
 
INSERT INTO t4 SELECT * FROM t3;
359
 
INSERT INTO t3 SELECT * FROM t4;
360
 
INSERT INTO t4 SELECT * FROM t3;
361
 
INSERT INTO t3 SELECT * FROM t4;
362
 
INSERT INTO t4 SELECT * FROM t3;
363
 
INSERT INTO t3 SELECT * FROM t4;
364
 
INSERT INTO t4 SELECT * FROM t3;
365
 
INSERT INTO t3 SELECT * FROM t4;
366
 
INSERT INTO t4 SELECT * FROM t3;
367
 
INSERT INTO t3 SELECT * FROM t4;
368
 
INSERT INTO t4 SELECT * FROM t3;
369
 
INSERT INTO t3 SELECT * FROM t4;
370
 
INSERT INTO t4 SELECT * FROM t3;
371
 
INSERT INTO t3 SELECT * FROM t4;
372
 
INSERT INTO t3 VALUES (2), (3);
373
 
ANALYZE table t1, t2, t3;
374
 
Table   Op      Msg_type        Msg_text
375
 
test.t1 analyze status  OK
376
 
test.t2 analyze status  OK
377
 
test.t3 analyze status  OK
378
 
SELECT COUNT(*) FROM t3;
379
 
COUNT(*)
380
 
15972
381
 
EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
382
 
LEFT JOIN t3 ON t2.b=t3.b;
383
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
384
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    X       
385
 
1       SIMPLE  t2      ref     idx     idx     5       test.t1.a       X       
386
 
1       SIMPLE  t3      ref     idx     idx     5       test.t2.b       X       Using index
387
 
FLUSH STATUS ;
388
 
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
389
 
LEFT JOIN t3 ON t2.b=t3.b;
390
 
a       a       b       b
391
 
1       1       1       NULL
392
 
2       NULL    NULL    NULL
393
 
3       3       1       NULL
394
 
4       NULL    NULL    NULL
395
 
SELECT FOUND_ROWS();
396
 
FOUND_ROWS()
397
 
4
398
 
SHOW STATUS LIKE "handler_read%";
399
 
Variable_name   Value
400
 
Handler_read_first      1
401
 
Handler_read_key        10
402
 
Handler_read_next       2
403
 
Handler_read_prev       0
404
 
Handler_read_rnd        0
405
 
Handler_read_rnd_next   5
406
 
DROP TABLE t1,t2,t3,t4;
407
 
CREATE TABLE t1 (
408
 
a int default NULL,
409
 
b int default NULL,
410
 
KEY a (a,b)
411
 
);
412
 
INSERT INTO t1 VALUES (0,10),(0,11),(0,12);
413
 
CREATE TABLE t2 (
414
 
a int default NULL,
415
 
b int default NULL,
416
 
KEY a (a)
417
 
);
418
 
INSERT INTO t2 VALUES (3,NULL),(3,11),(3,12);
419
 
SELECT * FROM t2 inner join t1 WHERE ( t1.a = 0 OR t1.a IS NULL) AND t2.a = 3 AND t2.b = t1.b;
420
 
a       b       a       b
421
 
3       11      0       11
422
 
3       12      0       12
423
 
drop table t1, t2;
424
 
End of 5.0 tests