~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/range.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, t3;
2
2
CREATE TABLE t1 (
3
 
event_date date NULL,
4
 
type int DEFAULT '0' NOT NULL,
5
 
event_id int DEFAULT '0' NOT NULL,
 
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,
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 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
 
ISS_DATE date,
 
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,
 
52
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
53
53
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
54
54
);
55
55
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
79
79
check table t1;
80
80
Table   Op      Msg_type        Msg_text
81
81
test.t1 check   status  OK
 
82
repair table t1;
 
83
Table   Op      Msg_type        Msg_text
 
84
test.t1 repair  status  OK
82
85
drop table t1;
83
86
CREATE TABLE t1 (
84
 
id int NOT NULL auto_increment,
85
 
parent_id int DEFAULT '0' NOT NULL,
86
 
level int DEFAULT '0' NOT NULL,
 
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
90
PRIMARY KEY (id),
88
91
KEY parent_id (parent_id),
89
92
KEY level (level)
96
99
(19,3,2), (5,1,1), (179,5,2);
97
100
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1;
98
101
id      parent_id       level
99
 
2       1       1
100
102
3       1       1
101
103
4       1       1
102
 
5       1       1
 
104
2       1       1
103
105
6       1       1
104
106
7       1       1
 
107
5       1       1
105
108
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
106
109
id      parent_id       level
107
110
2       1       1
145
148
aString
146
149
believe in myself
147
150
drop table t1;
148
 
CREATE TEMPORARY TABLE t1 (
149
 
t1ID int NOT NULL auto_increment,
150
 
art varbinary(1) NOT NULL default '',
 
151
CREATE TABLE t1 (
 
152
t1ID int(10) unsigned NOT NULL auto_increment,
 
153
art binary(1) NOT NULL default '',
151
154
KNR char(5) NOT NULL default '',
152
155
RECHNR char(6) NOT NULL default '',
153
156
POSNR char(2) NOT NULL default '',
217
220
update t1 set y=x;
218
221
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
219
222
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
220
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
221
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using join buffer
 
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
222
225
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
223
226
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
224
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
225
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using join buffer
 
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
226
229
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
227
230
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
228
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
229
 
1       SIMPLE  t2      range   x       x       5       NULL    3       Using where; Using join buffer
 
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
230
233
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
231
234
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
232
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
233
 
1       SIMPLE  t2      range   x       x       5       NULL    3       Using where; Using join buffer
 
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
234
237
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
235
238
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
236
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
237
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using join buffer
 
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
238
241
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
239
242
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
240
 
1       SIMPLE  t1      ref     y       y       5       const   1       Using where
241
 
1       SIMPLE  t2      range   x       x       5       NULL    2       Using where; Using join buffer
 
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
242
245
explain select count(*) from t1 where x in (1);
243
246
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
244
 
1       SIMPLE  t1      ref     x       x       5       const   1       Using where; Using index
 
247
1       SIMPLE  t1      ref     x       x       5       const   1       Using index
245
248
explain select count(*) from t1 where x in (1,2);
246
249
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
247
250
1       SIMPLE  t1      index   x       x       5       NULL    9       Using where; Using index
248
251
drop table t1;
249
 
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
 
252
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
250
253
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
251
 
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
 
254
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
252
255
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
253
256
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
254
257
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
260
263
1       SIMPLE  t2      ref     j1      j1      4       const   1       Using index
261
264
1       SIMPLE  t1      index   i1      i1      4       NULL    7       Using where; Using index; Using join buffer
262
265
DROP TABLE t1,t2;
263
 
CREATE TEMPORARY TABLE t1 (
264
 
a int default NULL,
265
 
b int default NULL,
 
266
CREATE TABLE t1 (
 
267
a int(11) default NULL,
 
268
b int(11) default NULL,
266
269
KEY a (a),
267
270
KEY b (b)
268
271
) ENGINE=MyISAM;
273
276
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
274
277
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
275
278
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
276
 
1       SIMPLE  t1      range   a,b     a       5       NULL    2       Using where
 
279
1       SIMPLE  t1      range   a,b     a       5       NULL    2       Using index condition; Using where; Using MRR
277
280
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
278
281
a       b
279
282
DROP TABLE t1;
301
304
15      1
302
305
47      1
303
306
DROP TABLE t1;
304
 
CREATE TEMPORARY TABLE t1 (
305
 
id int NOT NULL AUTO_INCREMENT ,
306
 
line int NOT NULL default '0',
307
 
columnid int NOT NULL default '0',
308
 
owner int NOT NULL default '0',
309
 
ordinal int NOT NULL default '0',
310
 
showid int NOT NULL default '1',
311
 
tableid int NOT NULL default '1',
312
 
content int NOT NULL default '188',
 
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',
313
316
PRIMARY KEY ( owner, id ) ,
314
317
KEY menu( owner, showid, columnid ) ,
315
318
KEY `COLUMN` ( owner, columnid, line ) ,
322
325
13      13      1       188     1       5       0
323
326
15      15      1       188     1       1       0
324
327
drop table t1;
325
 
create  table t1 (id int primary key);
 
328
create  table t1 (id int(10) primary key);
326
329
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
327
330
select id from t1 where id in (2,5,9) ;
328
331
id
415
418
analyze table t1,t2;
416
419
Table   Op      Msg_type        Msg_text
417
420
test.t1 analyze status  OK
418
 
test.t2 analyze status  OK
 
421
test.t2 analyze status  Table is already up to date
419
422
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
420
423
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
421
 
1       SIMPLE  #       range   uid_index       uid_index       4       #       #       Using where
422
 
1       SIMPLE  #       ref     uid_index       uid_index       4       #       #       
 
424
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using index condition; Using MRR
 
425
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
423
426
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid > 0;
424
427
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
425
 
1       SIMPLE  #       range   uid_index       uid_index       4       #       #       Using where
426
 
1       SIMPLE  #       ref     uid_index       uid_index       4       #       #       
 
428
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    112     Using index condition; Using MRR
 
429
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
427
430
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid != 0;
428
431
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
429
 
1       SIMPLE  #       range   uid_index       uid_index       4       #       #       Using where
430
 
1       SIMPLE  #       ref     uid_index       uid_index       4       #       #       
 
432
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using index condition; Using MRR
 
433
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
431
434
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid != 0;
432
435
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
433
 
1       SIMPLE  #       range   uid_index       uid_index       4       #       #       Using where
434
 
1       SIMPLE  #       ref     uid_index       uid_index       4       #       #       
 
436
1       SIMPLE  t1      range   uid_index       uid_index       4       NULL    113     Using index condition; Using MRR
 
437
1       SIMPLE  t2      ref     uid_index       uid_index       4       test.t1.uid     38      
435
438
select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
436
439
id      name    uid     id      name    uid
437
440
1001    A       1       1001    A       1
489
492
1025    Y       25      1025    Y       25
490
493
1026    Z       26      1026    Z       26
491
494
drop table t1,t2;
492
 
create table t1 (x bigint not null);
493
 
insert into t1(x) values (0x0ffffffffffffff0);
494
 
insert into t1(x) values (0x0ffffffffffffff1);
 
495
create table t1 (x bigint unsigned not null);
 
496
insert into t1(x) values (0xfffffffffffffff0);
 
497
insert into t1(x) values (0xfffffffffffffff1);
495
498
select * from t1;
496
499
x
497
 
1152921504606846960
498
 
1152921504606846961
 
500
18446744073709551600
 
501
18446744073709551601
499
502
select count(*) from t1 where x>0;
500
503
count(*)
501
504
2
516
519
2
517
520
select count(*) from t1 where x = 18446744073709551601;
518
521
count(*)
519
 
0
 
522
1
520
523
create table t2 (x bigint not null);
521
524
insert into t2(x) values (-16);
522
525
insert into t2(x) values (-15);
544
547
1
545
548
select count(*) from t2 where x = 18446744073709551601;
546
549
count(*)
547
 
1
 
550
0
548
551
drop table t1,t2;
549
 
create table t1 (x bigint not null primary key) engine=innodb;
550
 
insert into t1(x) values (0x0ffffffffffffff0);
551
 
insert into t1(x) values (0x0ffffffffffffff1);
 
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
555
select * from t1;
553
556
x
554
 
1152921504606846960
555
 
1152921504606846961
 
557
18446744073709551600
 
558
18446744073709551601
556
559
select count(*) from t1 where x>0;
557
560
count(*)
558
561
2
573
576
2
574
577
select count(*) from t1 where x = 18446744073709551601;
575
578
count(*)
576
 
0
 
579
1
577
580
drop table t1;
578
 
create table t1 (a bigint);
 
581
create table t1 (a bigint unsigned);
579
582
create index t1i on t1(a);
580
583
insert into t1 select 18446744073709551615;
581
584
insert into t1 select 18446744073709551614;
584
587
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
585
588
select * from t1 where a <> -1;
586
589
a
587
 
-2
 
590
18446744073709551614
 
591
18446744073709551615
588
592
explain select * from t1 where a > -1 or a < -1;
589
593
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
590
594
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
591
595
select * from t1 where a > -1 or a < -1;
592
596
a
593
 
-2
 
597
18446744073709551614
 
598
18446744073709551615
594
599
explain select * from t1 where a > -1;
595
600
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
596
601
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
597
602
select * from t1 where a > -1;
598
603
a
 
604
18446744073709551614
 
605
18446744073709551615
599
606
explain select * from t1 where a < -1;
600
607
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
601
 
1       SIMPLE  t1      index   t1i     t1i     9       NULL    2       Using where; Using index
 
608
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
602
609
select * from t1 where a < -1;
603
610
a
604
 
-2
605
611
drop table t1;
606
 
create table t1 (a char(10), b text, key (a));
 
612
set names latin1;
 
613
create table t1 (a char(10), b text, key (a)) character set latin1;
607
614
INSERT INTO t1 (a) VALUES
608
615
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
609
616
explain select * from t1 where a='aaa';
610
617
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
611
 
1       SIMPLE  t1      ref     a       a       43      const   2       Using where
 
618
1       SIMPLE  t1      ref     a       a       11      const   2       Using index condition
612
619
explain select * from t1 where a=binary 'aaa';
613
620
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
614
 
1       SIMPLE  t1      range   a       a       43      NULL    2       Using where
615
 
explain select * from t1 where a='aaa' collate utf8_bin;
616
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
617
 
1       SIMPLE  t1      range   a       a       43      NULL    2       Using where
 
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
618
628
drop table t1;
619
629
CREATE TABLE t1 (
620
 
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
621
 
`ARG1` char(3) collate utf8_bin NOT NULL default '',
622
 
`ARG2` char(3) collate utf8_bin NOT NULL default '',
623
 
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
624
 
`FUNCTINT` int NOT NULL default '0',
 
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',
625
635
KEY `VERI_CLNT~2` (`ARG1`)
626
 
) ENGINE=InnoDB;
 
636
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
627
637
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
628
638
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
629
639
('001',' 3',' 0','Text 017',0);
637
647
create table t1 (a int);
638
648
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
639
649
CREATE TABLE t2 (
640
 
pk1 int NOT NULL,
641
 
pk2 int NOT NULL,
642
 
pk3 int NOT NULL,
643
 
pk4 int NOT NULL,
 
650
pk1 int(11) NOT NULL,
 
651
pk2 int(11) NOT NULL,
 
652
pk3 int(11) NOT NULL,
 
653
pk4 int(11) NOT NULL,
644
654
filler char(82),
645
655
PRIMARY KEY (pk1,pk2,pk3,pk4)
646
 
);
 
656
) DEFAULT CHARSET=latin1;
647
657
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
648
658
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
649
659
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
659
669
insert into t1 values ('x'), ('xx');
660
670
explain select a from t1 where a > 'x';
661
671
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
662
 
1       SIMPLE  t1      range   a       a       7       NULL    2       Using where
 
672
1       SIMPLE  t1      range   a       a       2       NULL    2       Using where
663
673
select a from t1 where a > 'x';
664
674
a
665
675
xx
666
676
drop table t1;
667
677
CREATE TABLE t1 (
668
 
OXID varchar(32) NOT NULL DEFAULT '',
669
 
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
 
678
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
 
679
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
670
680
OXLEFT int NOT NULL DEFAULT '0',
671
681
OXRIGHT int NOT NULL DEFAULT '0',
672
 
OXROOTID varchar(32) NOT NULL DEFAULT '',
 
682
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
673
683
PRIMARY KEY  (OXID),
674
684
KEY OXNID (OXID),
675
685
KEY OXLEFT (OXLEFT),
676
686
KEY OXRIGHT (OXRIGHT),
677
687
KEY OXROOTID (OXROOTID)
678
 
);
 
688
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
679
689
INSERT INTO t1 VALUES
680
690
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
681
691
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
694
704
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
695
705
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
696
706
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
697
 
1       SIMPLE  #       ALL     OXLEFT  NULL    NULL    #       #       Range checked for each record (index map: 0x4)
698
 
1       SIMPLE  #       ALL     OXLEFT,OXRIGHT,OXROOTID NULL    NULL    #       #       Using where
 
707
1       SIMPLE  v       ref     OXLEFT,OXRIGHT,OXROOTID OXROOTID        34      const   5       Using index condition
 
708
1       SIMPLE  s       ALL     OXLEFT  NULL    NULL    NULL    6       Range checked for each record (index map: 0x4)
699
709
SELECT s.oxid FROM t1 v, t1 s 
700
710
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
701
711
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
850
860
drop table t1;
851
861
End of 4.1 tests
852
862
CREATE TABLE t1 (
853
 
id int NOT NULL auto_increment,
 
863
id int(11) NOT NULL auto_increment,
854
864
status varchar(20),
855
865
PRIMARY KEY  (id),
856
866
KEY (status)
868
878
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
869
879
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
870
880
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
871
 
1       SIMPLE  t1      range   status  status  83      NULL    10      Using where; Using index
 
881
1       SIMPLE  t1      range   status  status  23      NULL    11      Using index condition; Using MRR
872
882
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
873
883
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
874
 
1       SIMPLE  t1      range   status  status  83      NULL    10      Using where; Using index
 
884
1       SIMPLE  t1      range   status  status  23      NULL    11      Using index condition; Using MRR
875
885
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
876
886
id      status
877
887
53      C
894
904
60      C
895
905
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
896
906
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
897
 
1       SIMPLE  t1      range   status  status  83      NULL    10      Using where; Using index
 
907
1       SIMPLE  t1      range   status  status  23      NULL    11      Using where; Using index
898
908
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
899
909
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
900
 
1       SIMPLE  t1      range   status  status  83      NULL    10      Using where; Using index
 
910
1       SIMPLE  t1      range   status  status  23      NULL    11      Using where; Using index
901
911
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
902
912
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
903
 
1       SIMPLE  t1      range   status  status  83      NULL    9       Using where; Using index
 
913
1       SIMPLE  t1      range   status  status  23      NULL    10      Using index condition; Using MRR
904
914
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
905
915
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
906
 
1       SIMPLE  t1      range   status  status  83      NULL    9       Using where; Using index
 
916
1       SIMPLE  t1      range   status  status  23      NULL    10      Using index condition; Using MRR
907
917
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
908
918
id      status
909
919
53      C
925
935
59      C
926
936
60      C
927
937
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;
928
962
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
929
963
INSERT INTO t1 VALUES ('Betty'), ('Anna');
930
964
SELECT * FROM t1;
949
983
a
950
984
2
951
985
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;
952
1005
create table t3 (a int);
953
1006
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
954
 
create table t1 (a varchar(10), filler char(200), key(a));
 
1007
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
955
1008
insert into t1 values ('a','');
956
1009
insert into t1 values ('a ','');
957
1010
insert into t1 values ('a  ', '');
961
1014
insert into t2 select * from t1;
962
1015
explain select * from t1 where a between 'a' and 'a ';
963
1016
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
964
 
1       SIMPLE  #       ref     a       a       43      #       #       Using where
 
1017
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
965
1018
explain select * from t1 where a = 'a' or a='a ';
966
1019
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
967
 
1       SIMPLE  #       ref     a       a       43      #       #       Using where
 
1020
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
968
1021
explain select * from t2 where a between 'a' and 'a ';
969
1022
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
970
 
1       SIMPLE  #       ref     a       a       43      #       #       Using where
 
1023
1       SIMPLE  t2      ref     a       a       13      const   #       Using index condition
971
1024
explain select * from t2 where a = 'a' or a='a ';
972
1025
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
973
 
1       SIMPLE  #       ref     a       a       43      #       #       Using where
 
1026
1       SIMPLE  t2      ref     a       a       13      const   #       Using index condition
974
1027
update t1 set a='b' where a<>'a';
975
1028
explain select * from t1 where a not between 'b' and 'b';
976
1029
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
977
 
1       SIMPLE  #       #       #       #       #       #       #       Using where
 
1030
1       SIMPLE  t1      range   a       a       13      NULL    #       Using index condition; Using MRR
978
1031
select a, hex(filler) from t1 where a not between 'b' and 'b';
979
1032
a       hex(filler)
980
 
a       
981
 
a       
982
 
a       
 
1033
a       0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
983
1034
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;
984
1057
CREATE TABLE t1 (
985
1058
id int NOT NULL DEFAULT '0',
986
1059
b int NOT NULL DEFAULT '0',
998
1071
0       3       4
999
1072
EXPLAIN  SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1000
1073
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1001
 
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    2       Using where
 
1074
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    3       Using index condition; Using where; Using MRR
1002
1075
EXPLAIN  SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1003
1076
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1004
 
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    2       Using where
 
1077
1       SIMPLE  t1      range   idx1,idx2       idx2    4       NULL    3       Using where; Using MRR
1005
1078
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1006
1079
id      b       c
1007
1080
0       3       4
1017
1090
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1018
1091
1       SIMPLE  t1      ALL     idx1,idx2       NULL    NULL    NULL    10      Using where
1019
1092
DROP TABLE t1;
1020
 
CREATE TEMPORARY TABLE t1 (                                      
 
1093
CREATE TABLE t1 (                                      
1021
1094
item char(20) NOT NULL default '',                          
1022
 
started datetime, 
 
1095
started datetime NOT NULL default '0000-00-00 00:00:00', 
1023
1096
price decimal(16,3) NOT NULL default '0.000',                 
1024
1097
PRIMARY KEY (item,started)                     
1025
1098
) ENGINE=MyISAM;
1028
1101
('A1','2005-11-15 00:00:00',2000),
1029
1102
('A1','2005-12-12 08:00:00',3000),
1030
1103
('A2','2005-12-01 08:00:00',1000);
1031
 
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
1032
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1033
 
1       SIMPLE  #       range   PRIMARY PRIMARY 90      #       #       Using where
1034
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
1035
 
item    started price
1036
 
A1      2005-11-01 08:00:00     1000.000
1037
 
A1      2005-11-15 00:00:00     2000.000
 
1104
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
 
1105
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
 
1107
Warnings:
 
1108
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
 
1109
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
 
1110
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
 
1111
item    started price
 
1112
A1      2005-11-01 08:00:00     1000.000
 
1113
A1      2005-11-15 00:00:00     2000.000
 
1114
Warnings:
 
1115
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
 
1116
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
 
1117
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
 
1118
item    started price
 
1119
A1      2005-11-01 08:00:00     1000.000
 
1120
A1      2005-11-15 00:00:00     2000.000
 
1121
DROP INDEX `PRIMARY` ON t1;
 
1122
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
 
1123
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1124
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       Using where
 
1125
Warnings:
 
1126
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
 
1127
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
 
1128
item    started price
 
1129
A1      2005-11-01 08:00:00     1000.000
 
1130
A1      2005-11-15 00:00:00     2000.000
 
1131
Warnings:
 
1132
Warning 1292    Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1038
1133
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1039
1134
item    started price
1040
1135
A1      2005-11-01 08:00:00     1000.000
1044
1139
BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
1045
1140
 
1046
1141
CREATE TABLE t1 (
1047
 
id int NOT NULL auto_increment,
 
1142
id int(11) NOT NULL auto_increment,
1048
1143
dateval date default NULL,
1049
1144
PRIMARY KEY  (id),
1050
1145
KEY dateval (dateval)
1056
1151
This must use range access:
1057
1152
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1058
1153
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1059
 
1       SIMPLE  t1      index   dateval PRIMARY 4       NULL    11      Using where
 
1154
1       SIMPLE  t1      range   dateval dateval 4       NULL    2       Using index condition; Using MRR
1060
1155
drop table t1;
1061
1156
CREATE TABLE t1 (
1062
1157
a varchar(32), index (a)
1063
 
) DEFAULT COLLATE=utf8_bin;
 
1158
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
1064
1159
INSERT INTO t1 VALUES
1065
1160
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1066
1161
SELECT a FROM t1 WHERE a='b' OR a='B';
1069
1164
B
1070
1165
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1071
1166
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1072
 
1       SIMPLE  t1      range   a       a       131     NULL    3       Using where; Using index
 
1167
1       SIMPLE  t1      range   a       a       35      NULL    3       Using where; Using index
1073
1168
DROP TABLE t1;
1074
 
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
 
1169
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
1075
1170
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
1076
 
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
1077
 
COUNT(*)
1078
 
5
1079
 
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
1080
 
COUNT(*)
1081
 
5
1082
 
SELECT COUNT(*) FROM t1 WHERE f1 < 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;
1083
1178
COUNT(*)
1084
1179
4
1085
 
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
 
1180
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
1086
1181
COUNT(*)
1087
1182
0
1088
 
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
 
1183
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
1089
1184
COUNT(*)
1090
1185
5
1091
1186
DROP TABLE t1;
1092
 
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
 
1187
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
1093
1188
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1094
 
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
1095
 
COUNT(*)
1096
 
5
1097
 
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1098
 
COUNT(*)
1099
 
5
1100
 
SELECT COUNT(*) FROM t1 WHERE f1 < 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;
1101
1196
COUNT(*)
1102
1197
4
1103
 
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
1104
 
COUNT(*)
1105
 
5
1106
 
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1107
 
COUNT(*)
1108
 
5
1109
 
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
 
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;
1110
1205
COUNT(*)
1111
1206
4
1112
1207
DROP TABLE t1;
1120
1215
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1121
1216
Z
1122
1217
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1123
 
create temporary table t2e like t2;
1124
 
alter table t2e engine=myisam;
1125
 
insert into t2e select * from t2;
1126
 
analyze table t2e;
1127
 
Table   Op      Msg_type        Msg_text
1128
 
test.t2e        analyze note    The storage engine for the table doesn't support analyze
1129
 
explain select * from t2e where a=1000 and b<11;
 
1218
explain select * from t2 where a=1000 and b<11;
1130
1219
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1131
 
1       SIMPLE  t2e     ref     a       a       5       const   11      Using where
 
1220
1       SIMPLE  t2      ref     a       a       5       const   502     Using index condition
1132
1221
drop table t1, t2;
1133
1222
End of 5.1 tests
1134
1223
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));