~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/range.test

  • Committer: Brian Aker
  • Date: 2009-07-11 19:23:04 UTC
  • mfrom: (1089.1.14 merge)
  • Revision ID: brian@gaz-20090711192304-ootijyl5yf9jq9kd
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
 
1
 
2
2
# Problem with range optimizer
3
3
#
4
4
 
7
7
--enable_warnings
8
8
 
9
9
CREATE TABLE t1 (
10
 
  event_date date DEFAULT '0000-00-00' NOT NULL,
11
 
  type int(11) DEFAULT '0' NOT NULL,
12
 
  event_id int(11) DEFAULT '0' NOT NULL,
 
10
  event_date date NULL,
 
11
  type int DEFAULT '0' NOT NULL,
 
12
  event_id int DEFAULT '0' NOT NULL,
13
13
  PRIMARY KEY (event_date,type,event_id)
14
14
);
15
15
 
38
38
drop table t1;
39
39
 
40
40
CREATE TABLE t1 (
41
 
  PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
42
 
  YEAR smallint(6) DEFAULT '0' NOT NULL,
43
 
  ISSUE smallint(6) DEFAULT '0' NOT NULL,
44
 
  CLOSED tinyint(4) DEFAULT '0' NOT NULL,
45
 
  ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
 
41
  PAPER_ID int DEFAULT '0' NOT NULL,
 
42
  YEAR int DEFAULT '0' NOT NULL,
 
43
  ISSUE int DEFAULT '0' NOT NULL,
 
44
  CLOSED int DEFAULT '0' NOT NULL,
 
45
  ISS_DATE date,
46
46
  PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
47
47
);
48
48
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
62
62
                      (3,1999,35,0,'1999-07-12');
63
63
select YEAR,ISSUE from t1 where PAPER_ID=3 and (YEAR>1999 or (YEAR=1999 and ISSUE>28))  order by YEAR,ISSUE;
64
64
check table t1;
65
 
repair table t1;
66
65
drop table t1;
67
66
 
68
67
CREATE TABLE t1 (
69
 
  id int(11) NOT NULL auto_increment,
70
 
  parent_id int(11) DEFAULT '0' NOT NULL,
71
 
  level tinyint(4) DEFAULT '0' NOT NULL,
 
68
  id int NOT NULL auto_increment,
 
69
  parent_id int DEFAULT '0' NOT NULL,
 
70
  level int DEFAULT '0' NOT NULL,
72
71
  PRIMARY KEY (id),
73
72
  KEY parent_id (parent_id),
74
73
  KEY level (level)
117
116
#
118
117
 
119
118
CREATE TABLE t1 (
120
 
  t1ID int(10) unsigned NOT NULL auto_increment,
121
 
  art binary(1) NOT NULL default '',
 
119
  t1ID int NOT NULL auto_increment,
 
120
  art varbinary(1) NOT NULL default '',
122
121
  KNR char(5) NOT NULL default '',
123
122
  RECHNR char(6) NOT NULL default '',
124
123
  POSNR char(2) NOT NULL default '',
197
196
#
198
197
# bug #1172: "Force index" option caused server crash
199
198
#
200
 
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
 
199
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
201
200
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
202
 
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
 
201
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
203
202
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
204
203
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
205
204
explain select * from t1 force index(i1), t2 force index(j1) where 
211
210
# selective
212
211
 
213
212
CREATE TABLE t1 (
214
 
  a int(11) default NULL,
215
 
  b int(11) default NULL,
 
213
  a int default NULL,
 
214
  b int default NULL,
216
215
  KEY a (a),
217
216
  KEY b (b)
218
217
) ENGINE=MyISAM;
262
261
#
263
262
 
264
263
CREATE TABLE t1 (
265
 
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
266
 
line int( 5 ) unsigned NOT NULL default '0',
267
 
columnid int( 3 ) unsigned NOT NULL default '0',
268
 
owner int( 3 ) unsigned NOT NULL default '0',
269
 
ordinal int( 3 ) unsigned NOT NULL default '0',
270
 
showid smallint( 6 ) unsigned NOT NULL default '1',
271
 
tableid int( 1 ) unsigned NOT NULL default '1',
272
 
content int( 5 ) unsigned NOT NULL default '188',
 
264
id int NOT NULL AUTO_INCREMENT ,
 
265
line int NOT NULL default '0',
 
266
columnid int NOT NULL default '0',
 
267
owner int NOT NULL default '0',
 
268
ordinal int NOT NULL default '0',
 
269
showid int NOT NULL default '1',
 
270
tableid int NOT NULL default '1',
 
271
content int NOT NULL default '188',
273
272
PRIMARY KEY ( owner, id ) ,
274
273
KEY menu( owner, showid, columnid ) ,
275
274
KEY `COLUMN` ( owner, columnid, line ) ,
286
285
# test for a bug with in() and unique key
287
286
#
288
287
 
289
 
create  table t1 (id int(10) primary key);
 
288
create  table t1 (id int primary key);
290
289
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
291
290
 
292
291
select id from t1 where id in (2,5,9) ;
313
312
  name char(1) not null,
314
313
  uid int not null,
315
314
  primary key (id),
316
 
  index uid_index (uid));
 
315
  index uid_index (uid)) ENGINE=Myisam;
317
316
  
318
317
create table t2 (
319
318
  id int not null auto_increment,
320
319
  name char(1) not null,
321
320
  uid int not null,
322
321
  primary key (id),
323
 
  index uid_index (uid));
 
322
  index uid_index (uid)) engine=myisam;
324
323
  
325
324
insert into t1(id, uid, name) values(1, 0, ' ');
326
325
insert into t1(uid, name) values(0, ' ');
392
391
 
393
392
# Fix for bug#4488 
394
393
#
395
 
create table t1 (x bigint unsigned not null);
396
 
insert into t1(x) values (0xfffffffffffffff0);
397
 
insert into t1(x) values (0xfffffffffffffff1);
 
394
create table t1 (x bigint not null);
 
395
insert into t1(x) values (0x0ffffffffffffff0);
 
396
insert into t1(x) values (0x0ffffffffffffff1);
398
397
select * from t1;
399
398
select count(*) from t1 where x>0;
400
399
select count(*) from t1 where x=0;
419
418
drop table t1,t2;
420
419
 
421
420
--disable_warnings
422
 
create table t1 (x bigint unsigned not null primary key) engine=innodb;
 
421
create table t1 (x bigint not null primary key) engine=innodb;
423
422
--enable_warnings
424
 
insert into t1(x) values (0xfffffffffffffff0);
425
 
insert into t1(x) values (0xfffffffffffffff1);
 
423
insert into t1(x) values (0x0ffffffffffffff0);
 
424
insert into t1(x) values (0x0ffffffffffffff1);
426
425
select * from t1;
427
426
select count(*) from t1 where x>0;
428
427
select count(*) from t1 where x=0;
435
434
drop table t1;
436
435
 
437
436
#
438
 
# Bug #11185 incorrect comparison of unsigned int to signed constant
 
437
# Bug #11185 incorrect comparison of int to signed constant
439
438
#
440
 
create table t1 (a bigint unsigned);
 
439
create table t1 (a bigint);
441
440
create index t1i on t1(a);
442
441
insert into t1 select 18446744073709551615;
443
442
insert into t1 select 18446744073709551614;
457
456
# Bug #6045: Binary Comparison regression in MySQL 4.1
458
457
# Binary searches didn't use a case insensitive index.
459
458
#
460
 
set names latin1;
461
 
create table t1 (a char(10), b text, key (a)) character set latin1;
 
459
create table t1 (a char(10), b text, key (a));
462
460
INSERT INTO t1 (a) VALUES
463
461
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
464
462
# all these three can be optimized
465
463
explain select * from t1 where a='aaa';
466
464
explain select * from t1 where a=binary 'aaa';
467
 
explain select * from t1 where a='aaa' collate latin1_bin;
468
 
# this one cannot:
469
 
explain select * from t1 where a='aaa' collate latin1_german1_ci;
 
465
explain select * from t1 where a='aaa' collate utf8_bin;
470
466
drop table t1;
471
467
 
472
468
# Test for BUG#9348 "result for WHERE A AND (B OR C) differs from WHERE a AND (C OR B)"
473
469
--disable_warnings
474
470
CREATE TABLE t1 (
475
 
  `CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
476
 
  `ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
477
 
  `ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
478
 
  `FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
479
 
  `FUNCTINT` int(11) NOT NULL default '0',
 
471
  `CLIENT` char(3) collate utf8_bin NOT NULL default '000',
 
472
  `ARG1` char(3) collate utf8_bin NOT NULL default '',
 
473
  `ARG2` char(3) collate utf8_bin NOT NULL default '',
 
474
  `FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
 
475
  `FUNCTINT` int NOT NULL default '0',
480
476
  KEY `VERI_CLNT~2` (`ARG1`)
481
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
477
) ENGINE=InnoDB;
482
478
--enable_warnings
483
479
 
484
480
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
496
492
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
497
493
 
498
494
CREATE TABLE t2 (
499
 
  pk1 int(11) NOT NULL,
500
 
  pk2 int(11) NOT NULL,
501
 
  pk3 int(11) NOT NULL,
502
 
  pk4 int(11) NOT NULL,
 
495
  pk1 int NOT NULL,
 
496
  pk2 int NOT NULL,
 
497
  pk3 int NOT NULL,
 
498
  pk4 int NOT NULL,
503
499
  filler char(82),
504
500
  PRIMARY KEY (pk1,pk2,pk3,pk4)
505
 
) DEFAULT CHARSET=latin1;
 
501
);
506
502
 
507
503
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
508
504
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
530
526
#
531
527
 
532
528
CREATE TABLE t1 (
533
 
  OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
534
 
  OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
 
529
  OXID varchar(32) NOT NULL DEFAULT '',
 
530
  OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
535
531
  OXLEFT int NOT NULL DEFAULT '0',
536
532
  OXRIGHT int NOT NULL DEFAULT '0',
537
 
  OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
 
533
  OXROOTID varchar(32) NOT NULL DEFAULT '',
538
534
  PRIMARY KEY  (OXID),
539
535
  KEY OXNID (OXID),
540
536
  KEY OXLEFT (OXLEFT),
541
537
  KEY OXRIGHT (OXRIGHT),
542
538
  KEY OXROOTID (OXROOTID)
543
 
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
 
539
) ENGINE=MyISAM;
544
540
 
545
541
INSERT INTO t1 VALUES
546
542
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
719
715
#
720
716
 
721
717
CREATE TABLE t1 (
722
 
  id int(11) NOT NULL auto_increment,
 
718
  id int NOT NULL auto_increment,
723
719
  status varchar(20),
724
720
  PRIMARY KEY  (id),
725
721
  KEY (status)
755
751
DROP TABLE t1;
756
752
 
757
753
#
758
 
# Test for bug #10031: range to be used over a view
759
 
#
760
 
 
761
 
CREATE TABLE  t1 (a int, b int, primary key(a,b));
762
 
 
763
 
INSERT INTO  t1 VALUES
764
 
  (1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
765
 
 
766
 
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
767
 
 
768
 
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
769
 
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
770
 
 
771
 
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
772
 
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
773
 
 
774
 
SELECT a,b FROM t1 WHERE a < 2 and b=3;
775
 
SELECT a,b FROM v1 WHERE a < 2 and b=3; 
776
 
 
777
 
DROP VIEW v1;
778
 
DROP TABLE t1;
779
 
 
780
 
#
781
754
# Bug #11853: DELETE statement with a NOT (LIKE/<=>) where condition
782
755
#             for an indexed attribute              
783
756
#             
800
773
 
801
774
DROP TABLE t1;
802
775
 
803
 
#
804
 
# BUG#13317: range optimization doesn't work for IN over VIEW.
805
 
#
806
 
create table t1 (a int, b int, primary key(a,b));
807
 
create view v1 as select a, b from t1;
808
 
 
809
 
INSERT INTO `t1` VALUES
810
 
(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)
811
 
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
812
 
 
813
 
--replace_column 9 #
814
 
explain select * from t1 where a in (3,4)  and b in (1,2,3);
815
 
--replace_column 9 #
816
 
explain select * from v1 where a in (3,4)  and b in (1,2,3);
817
 
--replace_column 9 #
818
 
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
819
 
--replace_column 9 #
820
 
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
821
 
 
822
 
drop view v1;
823
 
drop table t1;
824
 
 
825
776
# BUG#13455: 
826
777
create table t3 (a int);
827
778
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
828
779
 
829
 
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
 
780
create table t1 (a varchar(10), filler char(200), key(a));
830
781
insert into t1 values ('a','');
831
782
insert into t1 values ('a ','');
832
783
insert into t1 values ('a  ', '');
854
805
drop table t1,t2,t3;
855
806
 
856
807
#
857
 
# BUG#21282
858
 
#
859
 
create table t1 (a int);
860
 
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
861
 
create table t2 (a int, key(a));
862
 
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
863
 
 
864
 
set @a="select * from t2 force index (a) where a NOT IN(0";
865
 
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
866
 
set @a=concat(@a, ')');
867
 
 
868
 
insert into t2 values (11),(13),(15);
869
 
 
870
 
set @b= concat("explain ", @a);
871
 
 
872
 
prepare stmt1 from @b;
873
 
execute stmt1;
874
 
 
875
 
prepare stmt1 from @a;
876
 
execute stmt1;
877
 
 
878
 
drop table t1, t2;
879
 
 
880
 
#
881
808
# Bug #18165: range access for BETWEEN with a constant for the first argument 
882
809
#
883
810
 
912
839
 
913
840
CREATE TABLE t1 (                                      
914
841
  item char(20) NOT NULL default '',                          
915
 
  started datetime NOT NULL default '0000-00-00 00:00:00', 
 
842
  started datetime, 
916
843
  price decimal(16,3) NOT NULL default '0.000',                 
917
844
  PRIMARY KEY (item,started)                     
918
845
) ENGINE=MyISAM;   
923
850
('A1','2005-12-12 08:00:00',3000),
924
851
('A2','2005-12-01 08:00:00',1000);
925
852
 
926
 
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
927
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
928
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
929
 
 
930
 
DROP INDEX `PRIMARY` ON t1;
931
 
 
932
 
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
933
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
934
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
 
853
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
 
854
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
 
855
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
 
856
 
 
857
# Disabling for now, since it fails.  Likely due to only currently
 
858
# checking for bad datetimes on string conversions...
 
859
#
 
860
#DROP INDEX `PRIMARY` ON t1;
 
861
 
 
862
#EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
 
863
#SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
 
864
#SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
935
865
 
936
866
DROP TABLE t1;
937
867
 
939
869
--echo BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
940
870
--echo
941
871
CREATE TABLE t1 (
942
 
  id int(11) NOT NULL auto_increment,
 
872
  id int NOT NULL auto_increment,
943
873
  dateval date default NULL,
944
874
  PRIMARY KEY  (id),
945
875
  KEY dateval (dateval)
962
892
 
963
893
CREATE TABLE t1 (
964
894
  a varchar(32), index (a)
965
 
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
 
895
) DEFAULT COLLATE=utf8_bin;
966
896
 
967
897
INSERT INTO t1 VALUES
968
898
  ('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
977
907
#
978
908
 
979
909
# test UNSIGNED. only occurs when indexed.
980
 
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
 
910
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
981
911
 
982
912
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
983
913
 
984
914
# test upper bound
985
915
# count 5
986
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256;
987
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256.0;
 
916
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
 
917
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
988
918
# count 4
989
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 255;
 
919
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
990
920
 
991
921
# show we don't fiddle with lower bound on UNSIGNED
992
922
# count 0
993
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
 
923
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
994
924
# count 5
995
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
 
925
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
996
926
 
997
927
DROP TABLE t1;
998
928
 
999
929
 
1000
930
# test signed. only occurs when index.
1001
 
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
 
931
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1002
932
 
1003
933
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1004
934
 
1005
935
# test upper bound
1006
936
# count 5
1007
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128;
1008
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128.0;
 
937
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
 
938
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1009
939
# count 4
1010
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 127;
 
940
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
1011
941
 
1012
942
# test lower bound
1013
943
# count 5
1014
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129;
1015
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129.0;
 
944
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
 
945
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1016
946
# count 4
1017
 
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -128;
 
947
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1018
948
 
1019
949
DROP TABLE t1;
1020
950
 
1025
955
create table t1 (a int);
1026
956
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1027
957
 
1028
 
create table t2 (a int, b int, filler char(100));
 
958
create table t2 (a int, b int, filler char(100)) ENGINE=myisam;
1029
959
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
1030
960
t1 B, t1 C where A.a < 5;
1031
961