~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/null_key.result

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

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