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