~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/null_key.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
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;
 
2
create table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
3
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
4
explain select * from t1 where a is null;
5
5
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
72
72
select * from t1 where a > 8 and a < 9;
73
73
a       b
74
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
85
75
insert into t2 select * from t1;
86
76
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));
87
77
explain select * from t1 where a is null and b = 2;
88
78
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
 
79
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where
90
80
explain select * from t1 where a is null and b = 2 and c=0;
91
81
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
 
82
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where
93
83
explain select * from t1 where a is null and b = 7 and c=0;
94
84
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
 
85
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where
96
86
explain select * from t1 where a=2 and b = 2;
97
87
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
 
88
1       SIMPLE  t1      ref     a,b     a       5       const   1       Using where
99
89
explain select * from t1 where a<=>b limit 2;
100
90
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
 
91
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    12      Using where
102
92
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
103
93
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
 
94
1       SIMPLE  t1      range   a,b     a       5       NULL    5       Using where
105
95
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
106
96
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
 
97
1       SIMPLE  t1      ref_or_null     a,b     a       5       const   4       Using where
108
98
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
109
99
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
 
100
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where
111
101
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
112
102
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
 
103
1       SIMPLE  t1      ref     a,b     a       5       const   3       Using where
114
104
explain select * from t1 where a > 1 and a < 3 limit 1;
115
105
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
 
106
1       SIMPLE  t1      range   a       a       5       NULL    1       Using where
117
107
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
118
108
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
 
109
1       SIMPLE  t1      range   a,b     a       5       NULL    4       Using where
120
110
explain select * from t1 where a > 8 and a < 9;
121
111
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
 
112
1       SIMPLE  t1      range   a       a       5       NULL    1       Using where
123
113
explain select * from t1 where b like "6%";
124
114
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
 
115
1       SIMPLE  t1      range   b       b       12      NULL    1       Using where
126
116
select * from t1 where a is null;
127
117
a       b       c
128
118
NULL    7       0
156
146
a       b       c
157
147
6       6       0
158
148
drop table t1;
159
 
drop table t2;
160
 
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
 
149
rename table t2 to t1;
161
150
alter table t1 modify b int null;
162
151
insert into t1 values (7,null), (8,null), (8,7);
163
152
explain select * from t1 where a = 7 and (b=7 or b is null);
165
154
1       SIMPLE  t1      ref_or_null     a,b     a       10      const,const     2       Using index
166
155
select * from t1 where a = 7 and (b=7 or b is null);
167
156
a       b
 
157
7       7
168
158
7       NULL
169
159
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
170
160
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
171
 
1       SIMPLE  t1      ref_or_null     a,b     a       5       const   2       Using where; Using index
 
161
1       SIMPLE  t1      ref_or_null     a,b     a       5       const   4       Using where; Using index
172
162
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
173
163
a       b
174
164
7       NULL
 
165
7       7
 
166
NULL    7
175
167
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
176
168
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
177
 
1       SIMPLE  t1      ref_or_null     a       a       5       const   2       Using index
 
169
1       SIMPLE  t1      ref_or_null     a       a       5       const   5       Using index
178
170
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
179
171
a       b
180
172
7       NULL
 
173
7       7
 
174
NULL    7
 
175
NULL    9
 
176
NULL    9
181
177
create table t2 (a int);
182
178
insert into t2 values (7),(8);
183
179
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
184
180
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
185
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
186
 
1       SIMPLE  t1      ref     a,b     b       5       const   X       Using where
 
181
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    2       
 
182
1       SIMPLE  t1      ref     a,b     a       10      test.t2.a,const 2       Using where; Using index
187
183
drop index b on t1;
188
184
explain select * from t2,t1 where t1.a=t2.a and b is null;
189
185
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
190
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
191
 
1       SIMPLE  t1      ref     a       a       10      test.t2.a,const X       Using where; Using index
 
186
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    2       
 
187
1       SIMPLE  t1      ref     a       a       10      test.t2.a,const 2       Using where; Using index
192
188
select * from t2,t1 where t1.a=t2.a and b is null;
193
189
a       a       b
194
190
7       7       NULL
195
191
8       8       NULL
196
192
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
197
193
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
198
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
199
 
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const X       Using index
 
194
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    2       
 
195
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const 4       Using index
200
196
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
201
197
a       a       b
 
198
7       7       7
202
199
7       7       NULL
203
200
8       8       7
204
201
8       8       NULL
205
202
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
206
203
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
207
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
208
 
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const X       Using index
 
204
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    2       
 
205
1       SIMPLE  t1      ref_or_null     a       a       10      test.t2.a,const 4       Using index
209
206
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
210
207
a       a       b
 
208
7       7       7
 
209
7       NULL    7
211
210
8       8       7
 
211
8       NULL    7
212
212
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
213
213
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
214
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       
215
 
1       SIMPLE  t1      ref_or_null     a       a       5       test.t2.a       X       Using where; Using index
 
214
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    2       
 
215
1       SIMPLE  t1      ref_or_null     a       a       5       test.t2.a       4       Using where; Using index
216
216
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
217
217
a       a       b
218
218
7       7       NULL
 
219
7       7       7
 
220
7       NULL    7
219
221
8       8       NULL
220
222
8       8       7
 
223
8       NULL    7
221
224
insert into t2 values (null),(6);
222
225
delete from t1 where a=8;
223
226
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
224
227
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
225
 
1       SIMPLE  t1      system  a       NULL    NULL    NULL    X       
226
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       Using where
 
228
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    4       
 
229
1       SIMPLE  t1      ref_or_null     a       a       5       test.t2.a       4       Using index
227
230
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
228
231
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
229
 
1       SIMPLE  t1      system  a       NULL    NULL    NULL    X       
230
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    X       Using where
 
232
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    4       
 
233
1       SIMPLE  t1      ref_or_null     a       a       5       test.t2.a       4       Using where; Using index
231
234
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
232
235
a       a       b
233
236
7       7       NULL
 
237
7       7       7
 
238
7       NULL    7
 
239
8       NULL    7
 
240
NULL    NULL    7
 
241
NULL    NULL    9
 
242
NULL    NULL    9
 
243
6       6       6
 
244
6       NULL    7
234
245
drop table t1,t2;
235
 
CREATE TEMPORARY TABLE t1 (
236
 
id int NOT NULL auto_increment,
237
 
uniq_id int default NULL,
 
246
CREATE TABLE t1 (
 
247
id int(10) unsigned NOT NULL auto_increment,
 
248
uniq_id int(10) unsigned default NULL,
238
249
PRIMARY KEY  (id),
239
250
UNIQUE KEY idx1 (uniq_id)
240
251
) ENGINE=MyISAM;
241
 
CREATE TEMPORARY TABLE t2 (
242
 
id int NOT NULL auto_increment,
243
 
uniq_id int default NULL,
 
252
CREATE TABLE t2 (
 
253
id int(10) unsigned NOT NULL auto_increment,
 
254
uniq_id int(10) unsigned default NULL,
244
255
PRIMARY KEY  (id)
245
256
) ENGINE=MyISAM;
246
257
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
247
258
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
248
259
explain select id from t1 where uniq_id is null;
249
260
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
250
 
1       SIMPLE  t1      ref     idx1    idx1    5       const   5       Using where
 
261
1       SIMPLE  t1      ref     idx1    idx1    5       const   5       Using index condition
251
262
explain select id from t1 where uniq_id =1;
252
263
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
253
264
1       SIMPLE  t1      const   idx1    idx1    5       const   1       
284
295
7       3
285
296
8       4
286
297
DROP table t1,t2;
287
 
CREATE TEMPORARY TABLE `t1` (
 
298
CREATE TABLE `t1` (
288
299
`order_id` char(32) NOT NULL default '',
289
300
`product_id` char(32) NOT NULL default '',
290
 
`product_type` int NOT NULL default '0',
 
301
`product_type` int(11) NOT NULL default '0',
291
302
PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
292
303
) ENGINE=MyISAM;
293
 
CREATE TEMPORARY TABLE `t2` (
 
304
CREATE TABLE `t2` (
294
305
`order_id` char(32) NOT NULL default '',
295
306
`product_id` char(32) NOT NULL default '',
296
 
`product_type` int NOT NULL default '0',
 
307
`product_type` int(11) NOT NULL default '0',
297
308
PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
298
309
) ENGINE=MyISAM;
299
310
INSERT INTO t1 (order_id, product_id, product_type) VALUES
330
341
index (id2)
331
342
);
332
343
insert into t1 values(null,null),(1,1);
333
 
ERROR 23000: Column 'id2' cannot be null
 
344
Warnings:
 
345
Warning 1048    Column 'id2' cannot be null
334
346
select * from t1;
335
347
id      id2
 
348
NULL    0
 
349
1       1
336
350
select * from t1 where id <=> null;
337
351
id      id2
 
352
NULL    0
338
353
select * from t1 where id <=> null or id > 0;
339
354
id      id2
 
355
NULL    0
 
356
1       1
340
357
select * from t1 where id is null or id > 0;
341
358
id      id2
 
359
NULL    0
 
360
1       1
342
361
select * from t1 where id2 <=> null or id2 > 0;
343
362
id      id2
 
363
1       1
344
364
select * from t1 where id2 is null or id2 > 0;
345
365
id      id2
 
366
1       1
346
367
delete from t1 where id <=> NULL;
347
368
select * from t1;
348
369
id      id2
 
370
1       1
349
371
drop table t1;
350
372
CREATE TABLE t1 (a int);
351
373
CREATE TABLE t2 (a int, b int, INDEX idx(a));
384
406
EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
385
407
LEFT JOIN t3 ON t2.b=t3.b;
386
408
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
387
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    X       
388
 
1       SIMPLE  t2      ref     idx     idx     5       test.t1.a       X       
389
 
1       SIMPLE  t3      ref     idx     idx     5       test.t2.b       X       Using index
 
409
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       
 
410
1       SIMPLE  t2      ref     idx     idx     5       test.t1.a       1       
 
411
1       SIMPLE  t3      ref     idx     idx     5       test.t2.b       1       Using index
390
412
FLUSH STATUS ;
391
413
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
392
414
LEFT JOIN t3 ON t2.b=t3.b;
400
422
4
401
423
SHOW STATUS LIKE "handler_read%";
402
424
Variable_name   Value
403
 
Handler_read_first      1
404
 
Handler_read_key        10
 
425
Handler_read_first      0
 
426
Handler_read_key        6
405
427
Handler_read_next       2
406
428
Handler_read_prev       0
407
429
Handler_read_rnd        0
408
430
Handler_read_rnd_next   5
409
431
DROP TABLE t1,t2,t3,t4;
410
432
CREATE TABLE t1 (
411
 
a int default NULL,
412
 
b int default NULL,
 
433
a int(11) default NULL,
 
434
b int(11) default NULL,
413
435
KEY a (a,b)
414
436
);
415
437
INSERT INTO t1 VALUES (0,10),(0,11),(0,12);
416
438
CREATE TABLE t2 (
417
 
a int default NULL,
418
 
b int default NULL,
 
439
a int(11) default NULL,
 
440
b int(11) default NULL,
419
441
KEY a (a)
420
442
);
421
443
INSERT INTO t2 VALUES (3,NULL),(3,11),(3,12);