~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/range.result

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
drop table if exists t1, t2, t3;
2
2
CREATE TABLE t1 (
3
3
event_date date DEFAULT '0000-00-00' NOT NULL,
4
 
type int(11) DEFAULT '0' NOT NULL,
5
 
event_id int(11) DEFAULT '0' NOT NULL,
 
4
type int DEFAULT '0' NOT NULL,
 
5
event_id int DEFAULT '0' NOT NULL,
6
6
PRIMARY KEY (event_date,type,event_id)
7
7
);
8
8
INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
45
45
1999-07-15      100600  16
46
46
drop table t1;
47
47
CREATE TABLE t1 (
48
 
PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
49
 
YEAR smallint(6) DEFAULT '0' NOT NULL,
50
 
ISSUE smallint(6) DEFAULT '0' NOT NULL,
51
 
CLOSED tinyint(4) DEFAULT '0' NOT NULL,
 
48
PAPER_ID int DEFAULT '0' NOT NULL,
 
49
YEAR int DEFAULT '0' NOT NULL,
 
50
ISSUE int DEFAULT '0' NOT NULL,
 
51
CLOSED int DEFAULT '0' NOT NULL,
52
52
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
53
53
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
54
54
);
81
81
test.t1 check   status  OK
82
82
repair table t1;
83
83
Table   Op      Msg_type        Msg_text
84
 
test.t1 repair  status  OK
 
84
test.t1 repair  note    The storage engine for the table doesn't support repair
85
85
drop table t1;
86
86
CREATE TABLE t1 (
87
 
id int(11) NOT NULL auto_increment,
88
 
parent_id int(11) DEFAULT '0' NOT NULL,
89
 
level tinyint(4) DEFAULT '0' NOT NULL,
 
87
id int NOT NULL auto_increment,
 
88
parent_id int DEFAULT '0' NOT NULL,
 
89
level int DEFAULT '0' NOT NULL,
90
90
PRIMARY KEY (id),
91
91
KEY parent_id (parent_id),
92
92
KEY level (level)
99
99
(19,3,2), (5,1,1), (179,5,2);
100
100
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1;
101
101
id      parent_id       level
 
102
2       1       1
102
103
3       1       1
103
104
4       1       1
104
 
2       1       1
 
105
5       1       1
105
106
6       1       1
106
107
7       1       1
107
 
5       1       1
108
108
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
109
109
id      parent_id       level
110
110
2       1       1
149
149
believe in myself
150
150
drop table t1;
151
151
CREATE TABLE t1 (
152
 
t1ID int(10) unsigned NOT NULL auto_increment,
153
 
art binary(1) NOT NULL default '',
 
152
t1ID int NOT NULL auto_increment,
 
153
art varbinary(1) NOT NULL default '',
154
154
KNR char(5) NOT NULL default '',
155
155
RECHNR char(6) NOT NULL default '',
156
156
POSNR char(2) NOT NULL default '',
221
221
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
222
222
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
223
223
1       SIMPLE  t1      ref     y       y       5       const   1       
224
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using index condition; Using MRR; Using join buffer
 
224
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using MRR; Using join buffer
225
225
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
226
226
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
227
227
1       SIMPLE  t1      ref     y       y       5       const   1       
228
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using index condition; Using MRR; Using join buffer
 
228
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using MRR; Using join buffer
229
229
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
230
230
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
231
231
1       SIMPLE  t1      ref     y       y       5       const   1       
232
 
1       SIMPLE  t2      range   x       x       5       NULL    3       Using index condition; Using MRR; Using join buffer
 
232
1       SIMPLE  t2      range   x       x       5       NULL    3       Using where; Using MRR; Using join buffer
233
233
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
234
234
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
235
235
1       SIMPLE  t1      ref     y       y       5       const   1       
236
 
1       SIMPLE  t2      range   x       x       5       NULL    3       Using index condition; Using MRR; Using join buffer
 
236
1       SIMPLE  t2      range   x       x       5       NULL    3       Using where; Using MRR; Using join buffer
237
237
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
238
238
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
239
239
1       SIMPLE  t1      ref     y       y       5       const   1       
240
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using index condition; Using MRR; Using join buffer
 
240
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using MRR; Using join buffer
241
241
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
242
242
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
243
243
1       SIMPLE  t1      ref     y       y       5       const   1       
244
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using index condition; Using MRR; Using join buffer
 
244
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using MRR; Using join buffer
245
245
explain select count(*) from t1 where x in (1);
246
246
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
247
247
1       SIMPLE  t1      ref     x       x       5       const   1       Using index
249
249
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
250
250
1       SIMPLE  t1      index   x       x       5       NULL    9       Using where; Using index
251
251
drop table t1;
252
 
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
 
252
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
253
253
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
254
 
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
 
254
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
255
255
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
256
256
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
257
257
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
258
258
1       SIMPLE  t2      ref     j1      j1      4       const   1       Using index
259
 
1       SIMPLE  t1      index   i1      i1      4       NULL    7       Using where; Using index; Using join buffer
 
259
1       SIMPLE  t1      range   i1      i1      4       NULL    3       Using where; Using index; Using join buffer
260
260
explain select * from t1 force index(i1), t2 force index(j1) where 
261
261
(t1.key1 <t2.keya + 1) and t2.keya=3;
262
262
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
263
263
1       SIMPLE  t2      ref     j1      j1      4       const   1       Using index
264
 
1       SIMPLE  t1      index   i1      i1      4       NULL    7       Using where; Using index; Using join buffer
 
264
1       SIMPLE  t1      range   i1      i1      4       NULL    3       Using where; Using index; Using join buffer
265
265
DROP TABLE t1,t2;
266
266
CREATE TABLE t1 (
267
 
a int(11) default NULL,
268
 
b int(11) default NULL,
 
267
a int default NULL,
 
268
b int default NULL,
269
269
KEY a (a),
270
270
KEY b (b)
271
271
) ENGINE=MyISAM;
276
276
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
277
277
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
278
278
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
279
 
1       SIMPLE  t1      range   a,b     a       5       NULL    2       Using index condition; Using where; Using MRR
 
279
1       SIMPLE  t1      range   a,b     a       5       NULL    2       Using where; Using MRR
280
280
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
281
281
a       b
282
282
DROP TABLE t1;
305
305
47      1
306
306
DROP TABLE t1;
307
307
CREATE TABLE t1 (
308
 
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
309
 
line int( 5 ) unsigned NOT NULL default '0',
310
 
columnid int( 3 ) unsigned NOT NULL default '0',
311
 
owner int( 3 ) unsigned NOT NULL default '0',
312
 
ordinal int( 3 ) unsigned NOT NULL default '0',
313
 
showid smallint( 6 ) unsigned NOT NULL default '1',
314
 
tableid int( 1 ) unsigned NOT NULL default '1',
315
 
content int( 5 ) unsigned NOT NULL default '188',
 
308
id int NOT NULL AUTO_INCREMENT ,
 
309
line int NOT NULL default '0',
 
310
columnid int NOT NULL default '0',
 
311
owner int NOT NULL default '0',
 
312
ordinal int NOT NULL default '0',
 
313
showid int NOT NULL default '1',
 
314
tableid int NOT NULL default '1',
 
315
content int NOT NULL default '188',
316
316
PRIMARY KEY ( owner, id ) ,
317
317
KEY menu( owner, showid, columnid ) ,
318
318
KEY `COLUMN` ( owner, columnid, line ) ,
325
325
13      13      1       188     1       5       0
326
326
15      15      1       188     1       1       0
327
327
drop table t1;
328
 
create  table t1 (id int(10) primary key);
 
328
create  table t1 (id int primary key);
329
329
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
330
330
select id from t1 where id in (2,5,9) ;
331
331
id
354
354
name char(1) not null,
355
355
uid int not null,
356
356
primary key (id),
357
 
index uid_index (uid));
 
357
index uid_index (uid)) ENGINE=Myisam;
358
358
create table t2 (
359
359
id int not null auto_increment,
360
360
name char(1) not null,
361
361
uid int not null,
362
362
primary key (id),
363
 
index uid_index (uid));
 
363
index uid_index (uid)) engine=myisam;
364
364
insert into t1(id, uid, name) values(1, 0, ' ');
365
365
insert into t1(uid, name) values(0, ' ');
366
366
insert into t2(uid, name) select uid, name from t1;
421
421
test.t2 analyze status  Table is already up to date
422
422
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
423
423
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
424
 
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using index condition; Using MRR
 
424
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using where; Using MRR
425
425
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
426
426
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid > 0;
427
427
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
428
 
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using index condition; Using MRR
 
428
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using where; Using MRR
429
429
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
430
430
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid != 0;
431
431
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
432
 
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using index condition; Using MRR
 
432
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using where; Using MRR
433
433
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
434
434
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid != 0;
435
435
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
436
 
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using index condition; Using MRR
 
436
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using where; Using MRR
437
437
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
438
438
select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
439
439
id      name    uid     id      name    uid
492
492
1025    Y       25      1025    Y       25
493
493
1026    Z       26      1026    Z       26
494
494
drop table t1,t2;
495
 
create table t1 (x bigint unsigned not null);
496
 
insert into t1(x) values (0xfffffffffffffff0);
497
 
insert into t1(x) values (0xfffffffffffffff1);
 
495
create table t1 (x bigint not null);
 
496
insert into t1(x) values (0x0ffffffffffffff0);
 
497
insert into t1(x) values (0x0ffffffffffffff1);
498
498
select * from t1;
499
499
x
500
 
18446744073709551600
501
 
18446744073709551601
 
500
1152921504606846960
 
501
1152921504606846961
502
502
select count(*) from t1 where x>0;
503
503
count(*)
504
504
2
519
519
2
520
520
select count(*) from t1 where x = 18446744073709551601;
521
521
count(*)
522
 
1
 
522
0
523
523
create table t2 (x bigint not null);
524
524
insert into t2(x) values (-16);
525
525
insert into t2(x) values (-15);
547
547
1
548
548
select count(*) from t2 where x = 18446744073709551601;
549
549
count(*)
550
 
0
 
550
1
551
551
drop table t1,t2;
552
 
create table t1 (x bigint unsigned not null primary key) engine=innodb;
553
 
insert into t1(x) values (0xfffffffffffffff0);
554
 
insert into t1(x) values (0xfffffffffffffff1);
 
552
create table t1 (x bigint not null primary key) engine=innodb;
 
553
insert into t1(x) values (0x0ffffffffffffff0);
 
554
insert into t1(x) values (0x0ffffffffffffff1);
555
555
select * from t1;
556
556
x
557
 
18446744073709551600
558
 
18446744073709551601
 
557
1152921504606846960
 
558
1152921504606846961
559
559
select count(*) from t1 where x>0;
560
560
count(*)
561
561
2
576
576
2
577
577
select count(*) from t1 where x = 18446744073709551601;
578
578
count(*)
579
 
1
 
579
0
580
580
drop table t1;
581
 
create table t1 (a bigint unsigned);
 
581
create table t1 (a bigint);
582
582
create index t1i on t1(a);
583
583
insert into t1 select 18446744073709551615;
584
584
insert into t1 select 18446744073709551614;
587
587
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
588
588
select * from t1 where a <> -1;
589
589
a
590
 
18446744073709551614
591
 
18446744073709551615
 
590
-2
592
591
explain select * from t1 where a > -1 or a < -1;
593
592
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
594
593
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
595
594
select * from t1 where a > -1 or a < -1;
596
595
a
597
 
18446744073709551614
598
 
18446744073709551615
 
596
-2
599
597
explain select * from t1 where a > -1;
600
598
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
601
599
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
602
600
select * from t1 where a > -1;
603
601
a
604
 
18446744073709551614
605
 
18446744073709551615
606
602
explain select * from t1 where a < -1;
607
603
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
608
 
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
604
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
609
605
select * from t1 where a < -1;
610
606
a
 
607
-2
611
608
drop table t1;
612
 
set names latin1;
613
 
create table t1 (a char(10), b text, key (a)) character set latin1;
 
609
create table t1 (a char(10), b text, key (a));
614
610
INSERT INTO t1 (a) VALUES
615
611
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
616
612
explain select * from t1 where a='aaa';
617
613
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
618
 
1       SIMPLE  t1      ref     a       a       11      const   2       Using index condition
 
614
1       SIMPLE  t1      ref     a       a       43      const   2       Using where
619
615
explain select * from t1 where a=binary 'aaa';
620
616
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
621
 
1       SIMPLE  t1      range   a       a       11      NULL    2       Using index condition; Using MRR
622
 
explain select * from t1 where a='aaa' collate latin1_bin;
623
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
624
 
1       SIMPLE  t1      range   a       a       11      NULL    2       Using index condition; Using MRR
625
 
explain select * from t1 where a='aaa' collate latin1_german1_ci;
626
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
627
 
1       SIMPLE  t1      ALL     a       NULL    NULL    NULL    9       Using where
 
617
1       SIMPLE  t1      range   a       a       43      NULL    2       Using where; Using MRR
 
618
explain select * from t1 where a='aaa' collate utf8_bin;
 
619
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
620
1       SIMPLE  t1      range   a       a       43      NULL    2       Using where; Using MRR
628
621
drop table t1;
629
622
CREATE TABLE t1 (
630
 
`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
631
 
`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
632
 
`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
633
 
`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
634
 
`FUNCTINT` int(11) NOT NULL default '0',
 
623
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
 
624
`ARG1` char(3) collate utf8_bin NOT NULL default '',
 
625
`ARG2` char(3) collate utf8_bin NOT NULL default '',
 
626
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
 
627
`FUNCTINT` int NOT NULL default '0',
635
628
KEY `VERI_CLNT~2` (`ARG1`)
636
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
629
) ENGINE=InnoDB;
637
630
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
638
631
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
639
632
('001',' 3',' 0','Text 017',0);
647
640
create table t1 (a int);
648
641
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
649
642
CREATE TABLE t2 (
650
 
pk1 int(11) NOT NULL,
651
 
pk2 int(11) NOT NULL,
652
 
pk3 int(11) NOT NULL,
653
 
pk4 int(11) NOT NULL,
 
643
pk1 int NOT NULL,
 
644
pk2 int NOT NULL,
 
645
pk3 int NOT NULL,
 
646
pk4 int NOT NULL,
654
647
filler char(82),
655
648
PRIMARY KEY (pk1,pk2,pk3,pk4)
656
 
) DEFAULT CHARSET=latin1;
 
649
);
657
650
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
658
651
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
659
652
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
669
662
insert into t1 values ('x'), ('xx');
670
663
explain select a from t1 where a > 'x';
671
664
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
672
 
1       SIMPLE  t1      range   a       a       2       NULL    2       Using where
 
665
1       SIMPLE  t1      range   a       a       7       NULL    1       Using where
673
666
select a from t1 where a > 'x';
674
667
a
675
668
xx
676
669
drop table t1;
677
670
CREATE TABLE t1 (
678
 
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
679
 
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
 
671
OXID varchar(32) NOT NULL DEFAULT '',
 
672
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
680
673
OXLEFT int NOT NULL DEFAULT '0',
681
674
OXRIGHT int NOT NULL DEFAULT '0',
682
 
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
 
675
OXROOTID varchar(32) NOT NULL DEFAULT '',
683
676
PRIMARY KEY  (OXID),
684
677
KEY OXNID (OXID),
685
678
KEY OXLEFT (OXLEFT),
686
679
KEY OXRIGHT (OXRIGHT),
687
680
KEY OXROOTID (OXROOTID)
688
 
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
 
681
) ENGINE=MyISAM;
689
682
INSERT INTO t1 VALUES
690
683
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
691
684
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
704
697
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
705
698
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
706
699
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
707
 
1       SIMPLE  v       ref     OXLEFT,OXRIGHT,OXROOTID OXROOTID        34      const   5       Using index condition
 
700
1       SIMPLE  v       ref     OXLEFT,OXRIGHT,OXROOTID OXROOTID        130     const   5       Using where
708
701
1       SIMPLE  s       ALL     OXLEFT  NULL    NULL    NULL    6       Range checked for each record (index map: 0x4)
709
702
SELECT s.oxid FROM t1 v, t1 s 
710
703
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
860
853
drop table t1;
861
854
End of 4.1 tests
862
855
CREATE TABLE t1 (
863
 
id int(11) NOT NULL auto_increment,
 
856
id int NOT NULL auto_increment,
864
857
status varchar(20),
865
858
PRIMARY KEY  (id),
866
859
KEY (status)
878
871
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
879
872
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
880
873
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
881
 
1       SIMPLE  t1      range   status  status  23      NULL    11      Using index condition; Using MRR
 
874
1       SIMPLE  t1      range   status  status  83      NULL    28      Using where; Using index
882
875
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
883
876
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
884
 
1       SIMPLE  t1      range   status  status  23      NULL    11      Using index condition; Using MRR
 
877
1       SIMPLE  t1      range   status  status  83      NULL    28      Using where; Using index
885
878
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
886
879
id      status
887
880
53      C
904
897
60      C
905
898
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
906
899
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
907
 
1       SIMPLE  t1      range   status  status  23      NULL    11      Using where; Using index
 
900
1       SIMPLE  t1      range   status  status  83      NULL    28      Using where; Using index
908
901
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
909
902
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
910
 
1       SIMPLE  t1      range   status  status  23      NULL    11      Using where; Using index
 
903
1       SIMPLE  t1      range   status  status  83      NULL    28      Using where; Using index
911
904
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
912
905
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
913
 
1       SIMPLE  t1      range   status  status  23      NULL    10      Using index condition; Using MRR
 
906
1       SIMPLE  t1      range   status  status  83      NULL    18      Using where; Using index
914
907
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
915
908
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
916
 
1       SIMPLE  t1      range   status  status  23      NULL    10      Using index condition; Using MRR
 
909
1       SIMPLE  t1      range   status  status  83      NULL    18      Using where; Using index
917
910
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
918
911
id      status
919
912
53      C
935
928
59      C
936
929
60      C
937
930
DROP TABLE t1;
938
 
CREATE TABLE  t1 (a int, b int, primary key(a,b));
939
 
INSERT INTO  t1 VALUES
940
 
(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
941
 
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
942
 
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
943
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
944
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    4       Using where; Using index
945
 
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
946
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
947
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    4       Using where; Using index
948
 
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
949
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
950
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    4       Using where; Using index
951
 
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
952
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
953
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    4       Using where; Using index
954
 
SELECT a,b FROM t1 WHERE a < 2 and b=3;
955
 
a       b
956
 
1       3
957
 
SELECT a,b FROM v1 WHERE a < 2 and b=3;
958
 
a       b
959
 
1       3
960
 
DROP VIEW v1;
961
 
DROP TABLE t1;
962
931
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
963
932
INSERT INTO t1 VALUES ('Betty'), ('Anna');
964
933
SELECT * FROM t1;
983
952
a
984
953
2
985
954
DROP TABLE t1;
986
 
create table t1 (a int, b int, primary key(a,b));
987
 
create view v1 as select a, b from t1;
988
 
INSERT INTO `t1` VALUES
989
 
(0,0),(1,0),(2,0),(3,0),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(11,2),(12,2)
990
 
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
991
 
explain select * from t1 where a in (3,4)  and b in (1,2,3);
992
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
993
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 8       NULL    #       Using where; Using index
994
 
explain select * from v1 where a in (3,4)  and b in (1,2,3);
995
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
996
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 8       NULL    #       Using where; Using index
997
 
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
998
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
999
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 8       NULL    #       Using where; Using index
1000
 
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
1001
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1002
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 8       NULL    #       Using where; Using index
1003
 
drop view v1;
1004
 
drop table t1;
1005
955
create table t3 (a int);
1006
956
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1007
 
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
 
957
create table t1 (a varchar(10), filler char(200), key(a));
1008
958
insert into t1 values ('a','');
1009
959
insert into t1 values ('a ','');
1010
960
insert into t1 values ('a  ', '');
1014
964
insert into t2 select * from t1;
1015
965
explain select * from t1 where a between 'a' and 'a ';
1016
966
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1017
 
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
 
967
1       SIMPLE  t1      ref     a       a       43      const   #       Using where
1018
968
explain select * from t1 where a = 'a' or a='a ';
1019
969
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1020
 
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
 
970
1       SIMPLE  t1      ref     a       a       43      const   #       Using where
1021
971
explain select * from t2 where a between 'a' and 'a ';
1022
972
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1023
 
1       SIMPLE  t2      ref     a       a       13      const   #       Using index condition
 
973
1       SIMPLE  t2      ref     a       a       43      const   #       Using where
1024
974
explain select * from t2 where a = 'a' or a='a ';
1025
975
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1026
 
1       SIMPLE  t2      ref     a       a       13      const   #       Using index condition
 
976
1       SIMPLE  t2      ref     a       a       43      const   #       Using where
1027
977
update t1 set a='b' where a<>'a';
1028
978
explain select * from t1 where a not between 'b' and 'b';
1029
979
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1030
 
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
 
980
1       SIMPLE  t1      ALL     a       NULL    NULL    NULL    #       Using where
1031
981
select a, hex(filler) from t1 where a not between 'b' and 'b';
1032
982
a       hex(filler)
1033
 
a       0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 
983
a       
 
984
a       
 
985
a       
1034
986
drop table t1,t2,t3;
1035
 
create table t1 (a int);
1036
 
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1037
 
create table t2 (a int, key(a));
1038
 
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
1039
 
set @a="select * from t2 force index (a) where a NOT IN(0";
1040
 
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
1041
 
count(*)
1042
 
1000
1043
 
set @a=concat(@a, ')');
1044
 
insert into t2 values (11),(13),(15);
1045
 
set @b= concat("explain ", @a);
1046
 
prepare stmt1 from @b;
1047
 
execute stmt1;
1048
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1049
 
1       SIMPLE  t2      index   a       a       5       NULL    1003    Using where; Using index
1050
 
prepare stmt1 from @a;
1051
 
execute stmt1;
1052
 
a
1053
 
11
1054
 
13
1055
 
15
1056
 
drop table t1, t2;
1057
987
CREATE TABLE t1 (
1058
988
id int NOT NULL DEFAULT '0',
1059
989
b int NOT NULL DEFAULT '0',
1071
1001
0       3       4
1072
1002
EXPLAIN  SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1073
1003
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1074
 
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    3       Using index condition; Using where; Using MRR
 
1004
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    2       Using where; Using MRR
1075
1005
EXPLAIN  SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1076
1006
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1077
 
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    3       Using where; Using MRR
 
1007
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    2       Using where; Using MRR
1078
1008
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1079
1009
id      b       c
1080
1010
0       3       4
1103
1033
('A2','2005-12-01 08:00:00',1000);
1104
1034
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1105
1035
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1106
 
1       SIMPLE  t1      ref     PRIMARY PRIMARY 20      const   2       Using index condition
 
1036
1       SIMPLE  t1      ref     PRIMARY PRIMARY 82      const   2       Using where
1107
1037
Warnings:
1108
1038
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1109
1039
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1139
1069
BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
1140
1070
 
1141
1071
CREATE TABLE t1 (
1142
 
id int(11) NOT NULL auto_increment,
 
1072
id int NOT NULL auto_increment,
1143
1073
dateval date default NULL,
1144
1074
PRIMARY KEY  (id),
1145
1075
KEY dateval (dateval)
1151
1081
This must use range access:
1152
1082
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1153
1083
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1154
 
1       SIMPLE  t1      range   dateval dateval 4       NULL    2       Using index condition; Using MRR
 
1084
1       SIMPLE  t1      index   dateval PRIMARY 4       NULL    11      Using where
1155
1085
drop table t1;
1156
1086
CREATE TABLE t1 (
1157
1087
a varchar(32), index (a)
1158
 
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
 
1088
) DEFAULT COLLATE=utf8_bin;
1159
1089
INSERT INTO t1 VALUES
1160
1090
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1161
1091
SELECT a FROM t1 WHERE a='b' OR a='B';
1164
1094
B
1165
1095
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1166
1096
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1167
 
1       SIMPLE  t1      range   a       a       35      NULL    3       Using where; Using index
 
1097
1       SIMPLE  t1      range   a       a       131     NULL    3       Using where; Using index
1168
1098
DROP TABLE t1;
1169
 
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
 
1099
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
1170
1100
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
1171
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256;
1172
 
COUNT(*)
1173
 
5
1174
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256.0;
1175
 
COUNT(*)
1176
 
5
1177
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 255;
 
1101
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
 
1102
COUNT(*)
 
1103
5
 
1104
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
 
1105
COUNT(*)
 
1106
5
 
1107
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
1178
1108
COUNT(*)
1179
1109
4
1180
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
 
1110
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
1181
1111
COUNT(*)
1182
1112
0
1183
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
 
1113
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1184
1114
COUNT(*)
1185
1115
5
1186
1116
DROP TABLE t1;
1187
 
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
 
1117
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1188
1118
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1189
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128;
1190
 
COUNT(*)
1191
 
5
1192
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128.0;
1193
 
COUNT(*)
1194
 
5
1195
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 127;
 
1119
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
 
1120
COUNT(*)
 
1121
5
 
1122
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
 
1123
COUNT(*)
 
1124
5
 
1125
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
1196
1126
COUNT(*)
1197
1127
4
1198
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129;
1199
 
COUNT(*)
1200
 
5
1201
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129.0;
1202
 
COUNT(*)
1203
 
5
1204
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -128;
 
1128
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
 
1129
COUNT(*)
 
1130
5
 
1131
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
 
1132
COUNT(*)
 
1133
5
 
1134
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1205
1135
COUNT(*)
1206
1136
4
1207
1137
DROP TABLE t1;
1208
1138
create table t1 (a int);
1209
1139
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1210
 
create table t2 (a int, b int, filler char(100));
 
1140
create table t2 (a int, b int, filler char(100)) ENGINE=myisam;
1211
1141
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
1212
1142
t1 B, t1 C where A.a < 5;
1213
1143
insert into t2 select 1000, b, 'filler' from t2;
1217
1147
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1218
1148
explain select * from t2 where a=1000 and b<11;
1219
1149
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1220
 
1       SIMPLE  t2      ref     a       a       5       const   502     Using index condition
 
1150
1       SIMPLE  t2      ref     a       a       5       const   502     Using where
1221
1151
drop table t1, t2;
1222
1152
End of 5.1 tests
1223
1153
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));