~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/range.test

  • Committer: Monty Taylor
  • Date: 2008-09-14 22:10:23 UTC
  • mto: This revision was merged to the branch mainline in revision 388.
  • Revision ID: monty@inaugust.com-20080914221023-otz8vuui590zp5yf
Got rid of libsqlcommon and some surious defines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Problem with range optimizer
3
 
#
4
 
 
5
 
--disable_warnings
6
 
drop table if exists t1, t2, t3;
7
 
--enable_warnings
8
 
 
9
 
CREATE TABLE t1 (
10
 
  event_date date DEFAULT '0000-00-00' NOT NULL,
11
 
  type int DEFAULT '0' NOT NULL,
12
 
  event_id int DEFAULT '0' NOT NULL,
13
 
  PRIMARY KEY (event_date,type,event_id)
14
 
);
15
 
 
16
 
INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
17
 
('1999-07-13',100600,0), ('1999-07-13',100600,4), ('1999-07-13',100600,26),
18
 
('1999-07-14',100600,10), ('1999-07-15',100600,16), ('1999-07-15',100800,45),
19
 
('1999-07-15',101000,47), ('1999-07-16',100800,46), ('1999-07-20',100600,5),
20
 
('1999-07-20',100600,27), ('1999-07-21',100600,11), ('1999-07-22',100600,17),
21
 
('1999-07-23',100100,39), ('1999-07-24',100100,39), ('1999-07-24',100500,40),
22
 
('1999-07-25',100100,39), ('1999-07-27',100600,1), ('1999-07-27',100600,6),
23
 
('1999-07-27',100600,28), ('1999-07-28',100600,12), ('1999-07-29',100500,41),
24
 
('1999-07-29',100600,18), ('1999-07-30',100500,41), ('1999-07-31',100500,41),
25
 
('1999-08-01',100700,34), ('1999-08-03',100600,7), ('1999-08-03',100600,29),
26
 
('1999-08-04',100600,13), ('1999-08-05',100500,42), ('1999-08-05',100600,19),
27
 
('1999-08-06',100500,42), ('1999-08-07',100500,42), ('1999-08-08',100500,42),
28
 
('1999-08-10',100600,2), ('1999-08-10',100600,9), ('1999-08-10',100600,30),
29
 
('1999-08-11',100600,14), ('1999-08-12',100600,20), ('1999-08-17',100500,8),
30
 
('1999-08-17',100600,31), ('1999-08-18',100600,15), ('1999-08-19',100600,22),
31
 
('1999-08-24',100600,3), ('1999-08-24',100600,32), ('1999-08-27',100500,43),
32
 
('1999-08-31',100600,33), ('1999-09-17',100100,37), ('1999-09-18',100100,37),
33
 
('1999-09-19',100100,37), ('2000-12-18',100700,38);
34
 
 
35
 
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
36
 
explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
37
 
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099;
38
 
drop table t1;
39
 
 
40
 
CREATE TABLE t1 (
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 DEFAULT '0000-00-00' NOT NULL,
46
 
  PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
47
 
);
48
 
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
49
 
                      (1,1999,222,0,'1999-03-23'), (3,1999,33,0,'1999-07-12'),
50
 
                      (3,1999,32,0,'1999-07-12'), (3,1999,31,0,'1999-07-12'),
51
 
                      (3,1999,30,0,'1999-07-12'), (3,1999,29,0,'1999-07-12'),
52
 
                      (3,1999,28,0,'1999-07-12'), (1,1999,40,1,'1999-05-01'),
53
 
                      (1,1999,41,1,'1999-05-01'), (1,1999,42,1,'1999-05-01'),
54
 
                      (1,1999,46,1,'1999-05-01'), (1,1999,47,1,'1999-05-01'),
55
 
                      (1,1999,48,1,'1999-05-01'), (1,1999,49,1,'1999-05-01'),
56
 
                      (1,1999,50,0,'1999-05-01'), (1,1999,51,0,'1999-05-01'),
57
 
                      (1,1999,200,0,'1999-06-28'), (1,1999,52,0,'1999-06-28'),
58
 
                      (1,1999,53,0,'1999-06-28'), (1,1999,54,0,'1999-06-28'),
59
 
                      (1,1999,55,0,'1999-06-28'), (1,1999,56,0,'1999-07-01'),
60
 
                      (1,1999,57,0,'1999-07-01'), (1,1999,58,0,'1999-07-01'),
61
 
                      (1,1999,59,0,'1999-07-01'), (1,1999,60,0,'1999-07-01'),
62
 
                      (3,1999,35,0,'1999-07-12');
63
 
select YEAR,ISSUE from t1 where PAPER_ID=3 and (YEAR>1999 or (YEAR=1999 and ISSUE>28))  order by YEAR,ISSUE;
64
 
check table t1;
65
 
repair table t1;
66
 
drop table t1;
67
 
 
68
 
CREATE TABLE t1 (
69
 
  id int NOT NULL auto_increment,
70
 
  parent_id int DEFAULT '0' NOT NULL,
71
 
  level int DEFAULT '0' NOT NULL,
72
 
  PRIMARY KEY (id),
73
 
  KEY parent_id (parent_id),
74
 
  KEY level (level)
75
 
);
76
 
INSERT INTO t1 VALUES (1,0,0), (3,1,1), (4,1,1), (8,2,2), (9,2,2), (17,3,2),
77
 
(22,4,2), (24,4,2), (28,5,2), (29,5,2), (30,5,2), (31,6,2), (32,6,2), (33,6,2),
78
 
(203,7,2), (202,7,2), (20,3,2), (157,0,0), (193,5,2), (40,7,2), (2,1,1),
79
 
(15,2,2), (6,1,1), (34,6,2), (35,6,2), (16,3,2), (7,1,1), (36,7,2), (18,3,2),
80
 
(26,5,2), (27,5,2), (183,4,2), (38,7,2), (25,5,2), (37,7,2), (21,4,2),
81
 
(19,3,2), (5,1,1), (179,5,2);
82
 
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1;
83
 
# The following select returned 0 rows in 3.23.8
84
 
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
85
 
drop table t1;
86
 
 
87
 
#
88
 
# Testing of bug in range optimizer with many key parts and > and <
89
 
#
90
 
 
91
 
create table t1(
92
 
                Satellite               varchar(25)     not null,
93
 
                SensorMode              varchar(25)     not null,
94
 
                FullImageCornersUpperLeftLongitude      double  not null,
95
 
                FullImageCornersUpperRightLongitude     double  not null,
96
 
                FullImageCornersUpperRightLatitude      double  not null,
97
 
                FullImageCornersLowerRightLatitude      double  not null,
98
 
                index two (Satellite, SensorMode, FullImageCornersUpperLeftLongitude, FullImageCornersUpperRightLongitude, FullImageCornersUpperRightLatitude, FullImageCornersLowerRightLatitude));
99
 
 
100
 
insert into t1 values("OV-3","PAN1",91,-92,40,50);
101
 
insert into t1 values("OV-4","PAN1",91,-92,40,50);
102
 
 
103
 
select * from t1 where t1.Satellite = "OV-3" and t1.SensorMode = "PAN1" and t1.FullImageCornersUpperLeftLongitude > -90.000000 and t1.FullImageCornersUpperRightLongitude < -82.000000;
104
 
drop table t1;
105
 
 
106
 
create table t1 ( aString char(100) not null default "", key aString (aString(10)) );
107
 
insert t1 (aString) values ( "believe in myself" ), ( "believe" ), ("baaa" ), ( "believe in love");
108
 
select * from t1 where aString < "believe in myself" order by aString;
109
 
select * from t1 where aString > "believe in love" order by aString;
110
 
alter table t1 drop key aString;
111
 
select * from t1 where aString < "believe in myself" order by aString;
112
 
select * from t1 where aString > "believe in love" order by aString;
113
 
drop table t1;
114
 
 
115
 
#
116
 
# Problem with binary strings
117
 
#
118
 
 
119
 
CREATE TABLE t1 (
120
 
  t1ID int NOT NULL auto_increment,
121
 
  art varbinary(1) NOT NULL default '',
122
 
  KNR char(5) NOT NULL default '',
123
 
  RECHNR char(6) NOT NULL default '',
124
 
  POSNR char(2) NOT NULL default '',
125
 
  ARTNR char(10) NOT NULL default '',
126
 
  TEX char(70) NOT NULL default '',
127
 
  PRIMARY KEY  (t1ID),
128
 
  KEY IdxArt (art),
129
 
  KEY IdxKnr (KNR),
130
 
  KEY IdxArtnr (ARTNR)
131
 
) ENGINE=MyISAM;
132
 
 
133
 
INSERT INTO t1 (art) VALUES ('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
134
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
135
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
136
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
137
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
138
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
139
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
140
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
141
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
142
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
143
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
144
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
145
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
146
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
147
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
148
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
149
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
150
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
151
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
152
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
153
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
154
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
155
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
156
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
157
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
158
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
159
 
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
160
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
161
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
162
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
163
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
164
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
165
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
166
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
167
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
168
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
169
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
170
 
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j');
171
 
select count(*) from t1 where upper(art) = 'J';
172
 
select count(*) from t1 where art = 'J' or art = 'j';
173
 
select count(*) from t1 where art = 'j' or art = 'J';
174
 
select count(*) from t1 where art = 'j';
175
 
select count(*) from t1 where art = 'J';
176
 
drop table t1;
177
 
#
178
 
# BETWEEN problems
179
 
#
180
 
create table t1 (x int, y int, index(x), index(y));
181
 
insert into t1 (x) values (1),(2),(3),(4),(5),(6),(7),(8),(9);
182
 
update t1 set y=x;
183
 
# between with only one end fixed
184
 
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
185
 
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
186
 
# between with both expressions on both ends
187
 
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
188
 
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
189
 
# equation propagation
190
 
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
191
 
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
192
 
# testing IN
193
 
explain select count(*) from t1 where x in (1);
194
 
explain select count(*) from t1 where x in (1,2);
195
 
drop table t1;
196
 
 
197
 
#
198
 
# bug #1172: "Force index" option caused server crash
199
 
#
200
 
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
201
 
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
202
 
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
203
 
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
204
 
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
205
 
explain select * from t1 force index(i1), t2 force index(j1) where 
206
 
 (t1.key1 <t2.keya + 1) and t2.keya=3;
207
 
DROP TABLE t1,t2;
208
 
 
209
 
#
210
 
# bug #1724: use RANGE on more selective column instead of REF on less
211
 
# selective
212
 
 
213
 
CREATE TABLE t1 (
214
 
  a int default NULL,
215
 
  b int default NULL,
216
 
  KEY a (a),
217
 
  KEY b (b)
218
 
) ENGINE=MyISAM;
219
 
 
220
 
 
221
 
INSERT INTO t1 VALUES
222
 
(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(10,2),
223
 
(13,2),(14,2),(15,2),(16,2),(17,3),(17,3),(16,3),(17,3),(19,3),(20,3),
224
 
(21,4),(22,5),(23,5),(24,5),(25,5),(26,5),(30,5),(31,5),(32,5),(33,5),
225
 
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
226
 
 
227
 
# we expect that optimizer will choose index on A
228
 
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
229
 
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
230
 
DROP TABLE t1;
231
 
 
232
 
#
233
 
# Test problem with range optimzer and sub ranges
234
 
#
235
 
 
236
 
CREATE TABLE t1 (a int, b int, c int, INDEX (c,a,b));
237
 
INSERT INTO t1 VALUES (1,0,0),(1,0,0),(1,0,0);
238
 
INSERT INTO t1 VALUES (0,1,0),(0,1,0),(0,1,0);
239
 
# -- First reports 3; second reports 6
240
 
SELECT COUNT(*) FROM t1 WHERE (c=0 and a=1) or (c=0 and b=1);
241
 
SELECT COUNT(*) FROM t1 WHERE (c=0 and b=1) or (c=0 and a=1);
242
 
DROP TABLE t1;
243
 
 
244
 
#
245
 
# Test problem with range optimization over overlapping ranges (#2448)
246
 
#
247
 
 
248
 
CREATE TABLE t1 ( a int not null, b int not null, INDEX ab(a,b) );
249
 
INSERT INTO t1 VALUES (47,1), (70,1), (15,1), (15, 4);
250
 
SELECT * FROM t1
251
 
WHERE
252
 
(
253
 
    ( b =1 AND a BETWEEN 14 AND 21 ) OR
254
 
    ( b =2 AND a BETWEEN 16 AND 18 ) OR
255
 
    ( b =3 AND a BETWEEN 15 AND 19 ) OR
256
 
    (a BETWEEN 19 AND 47)
257
 
);
258
 
DROP TABLE t1;
259
 
 
260
 
#
261
 
# Test of problem with IN on many different keyparts. (Bug #4157)
262
 
#
263
 
 
264
 
CREATE TABLE t1 (
265
 
id int NOT NULL AUTO_INCREMENT ,
266
 
line int NOT NULL default '0',
267
 
columnid int NOT NULL default '0',
268
 
owner int NOT NULL default '0',
269
 
ordinal int NOT NULL default '0',
270
 
showid int NOT NULL default '1',
271
 
tableid int NOT NULL default '1',
272
 
content int NOT NULL default '188',
273
 
PRIMARY KEY ( owner, id ) ,
274
 
KEY menu( owner, showid, columnid ) ,
275
 
KEY `COLUMN` ( owner, columnid, line ) ,
276
 
KEY `LINES` ( owner, tableid, content, id ) ,
277
 
KEY recount( owner, line ) 
278
 
) ENGINE = MYISAM;
279
 
 
280
 
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
281
 
 
282
 
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
283
 
drop table t1;
284
 
 
285
 
#
286
 
# test for a bug with in() and unique key
287
 
#
288
 
 
289
 
create  table t1 (id int primary key);
290
 
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
291
 
 
292
 
select id from t1 where id in (2,5,9) ;
293
 
select id from t1 where id=2 or id=5 or id=9 ;
294
 
drop table t1;
295
 
create table t1 ( id1 int not null, id2 int not null, idnull int null, c char(20), primary key (id1,id2));
296
 
insert into t1 values (0,1,NULL,"aaa"), (1,1,NULL,"aaa"), (2,1,NULL,"aaa"),
297
 
                      (3,1,NULL,"aaa"), (4,1,NULL,"aaa"), (5,1,NULL,"aaa"),
298
 
                      (6,1,NULL,"aaa"), (7,1,NULL,"aaa"), (8,1,NULL,"aaa"),
299
 
                      (9,1,NULL,"aaa"), (10,1,NULL,"aaa"), (11,1,NULL,"aaa"),
300
 
                      (12,1,NULL,"aaa"), (13,1,NULL,"aaa"), (14,1,NULL,"aaa"),
301
 
                      (15,1,NULL,"aaa"), (16,1,NULL,"aaa"), (17,1,NULL,"aaa"),
302
 
                      (18,1,NULL,"aaa"), (19,1,NULL,"aaa"), (20,1,NULL,"aaa");
303
 
select a.id1, b.idnull from t1 as a, t1 as b where a.id2=1 and a.id1=1 and b.id1=a.idnull order by b.id2 desc limit 1;
304
 
drop table t1;
305
 
 
306
 
 
307
 
#
308
 
# Problem with optimizing !=
309
 
#
310
 
 
311
 
create table t1 (
312
 
  id int not null auto_increment,
313
 
  name char(1) not null,
314
 
  uid int not null,
315
 
  primary key (id),
316
 
  index uid_index (uid)) ENGINE=Myisam;
317
 
  
318
 
create table t2 (
319
 
  id int not null auto_increment,
320
 
  name char(1) not null,
321
 
  uid int not null,
322
 
  primary key (id),
323
 
  index uid_index (uid)) engine=myisam;
324
 
  
325
 
insert into t1(id, uid, name) values(1, 0, ' ');
326
 
insert into t1(uid, name) values(0, ' ');
327
 
 
328
 
insert into t2(uid, name) select uid, name from t1;
329
 
insert into t1(uid, name) select uid, name from t2;
330
 
insert into t2(uid, name) select uid, name from t1;
331
 
insert into t1(uid, name) select uid, name from t2;
332
 
insert into t2(uid, name) select uid, name from t1;
333
 
insert into t1(uid, name) select uid, name from t2;
334
 
insert into t2(uid, name) select uid, name from t1;
335
 
insert into t1(uid, name) select uid, name from t2;
336
 
insert into t2(uid, name) select uid, name from t1;
337
 
insert into t1(uid, name) select uid, name from t2;
338
 
insert into t2(uid, name) select uid, name from t1;
339
 
insert into t2(uid, name) select uid, name from t1;
340
 
insert into t2(uid, name) select uid, name from t1;
341
 
insert into t2(uid, name) select uid, name from t1;
342
 
insert into t1(uid, name) select uid, name from t2;
343
 
 
344
 
delete from t2;
345
 
insert into t2(uid, name) values 
346
 
  (1, CHAR(64+1)),
347
 
  (2, CHAR(64+2)),
348
 
  (3, CHAR(64+3)),
349
 
  (4, CHAR(64+4)),
350
 
  (5, CHAR(64+5)),
351
 
  (6, CHAR(64+6)),
352
 
  (7, CHAR(64+7)),
353
 
  (8, CHAR(64+8)),
354
 
  (9, CHAR(64+9)),
355
 
  (10, CHAR(64+10)),
356
 
  (11, CHAR(64+11)),
357
 
  (12, CHAR(64+12)),
358
 
  (13, CHAR(64+13)),
359
 
  (14, CHAR(64+14)),
360
 
  (15, CHAR(64+15)),
361
 
  (16, CHAR(64+16)),
362
 
  (17, CHAR(64+17)),
363
 
  (18, CHAR(64+18)),
364
 
  (19, CHAR(64+19)),
365
 
  (20, CHAR(64+20)),
366
 
  (21, CHAR(64+21)),
367
 
  (22, CHAR(64+22)),
368
 
  (23, CHAR(64+23)),
369
 
  (24, CHAR(64+24)),
370
 
  (25, CHAR(64+25)),
371
 
  (26, CHAR(64+26));
372
 
 
373
 
insert into t1(uid, name) select uid, name from t2 order by uid;
374
 
 
375
 
delete from t2;
376
 
insert into t2(id, uid, name) select id, uid, name from t1;
377
 
 
378
 
select count(*) from t1;  
379
 
select count(*) from t2;
380
 
 
381
 
analyze table t1,t2;
382
 
 
383
 
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
384
 
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid > 0;
385
 
explain select * from t1, t2  where t1.uid=t2.uid AND t1.uid != 0;
386
 
explain select * from t1, t2  where t1.uid=t2.uid AND t2.uid != 0;
387
 
 
388
 
select * from t1, t2  where t1.uid=t2.uid AND t1.uid > 0;
389
 
select * from t1, t2  where t1.uid=t2.uid AND t1.uid != 0;
390
 
 
391
 
drop table t1,t2;
392
 
 
393
 
# Fix for bug#4488 
394
 
#
395
 
create table t1 (x bigint not null);
396
 
insert into t1(x) values (0x0ffffffffffffff0);
397
 
insert into t1(x) values (0x0ffffffffffffff1);
398
 
select * from t1;
399
 
select count(*) from t1 where x>0;
400
 
select count(*) from t1 where x=0;
401
 
select count(*) from t1 where x<0;
402
 
select count(*) from t1 where x < -16;
403
 
select count(*) from t1 where x = -16;
404
 
select count(*) from t1 where x > -16;
405
 
select count(*) from t1 where x = 18446744073709551601;
406
 
 
407
 
 
408
 
create table t2 (x bigint not null);
409
 
insert into t2(x) values (-16);
410
 
insert into t2(x) values (-15);
411
 
select * from t2;
412
 
select count(*) from t2 where x>0;
413
 
select count(*) from t2 where x=0;
414
 
select count(*) from t2 where x<0;
415
 
select count(*) from t2 where x < -16;
416
 
select count(*) from t2 where x = -16;
417
 
select count(*) from t2 where x > -16;
418
 
select count(*) from t2 where x = 18446744073709551601;
419
 
drop table t1,t2;
420
 
 
421
 
--disable_warnings
422
 
create table t1 (x bigint not null primary key) engine=innodb;
423
 
--enable_warnings
424
 
insert into t1(x) values (0x0ffffffffffffff0);
425
 
insert into t1(x) values (0x0ffffffffffffff1);
426
 
select * from t1;
427
 
select count(*) from t1 where x>0;
428
 
select count(*) from t1 where x=0;
429
 
select count(*) from t1 where x<0;
430
 
select count(*) from t1 where x < -16;
431
 
select count(*) from t1 where x = -16;
432
 
select count(*) from t1 where x > -16;
433
 
select count(*) from t1 where x = 18446744073709551601;
434
 
 
435
 
drop table t1;
436
 
 
437
 
#
438
 
# Bug #11185 incorrect comparison of int to signed constant
439
 
#
440
 
create table t1 (a bigint);
441
 
create index t1i on t1(a);
442
 
insert into t1 select 18446744073709551615;
443
 
insert into t1 select 18446744073709551614;
444
 
 
445
 
explain select * from t1 where a <> -1;
446
 
select * from t1 where a <> -1;
447
 
explain select * from t1 where a > -1 or a < -1;
448
 
select * from t1 where a > -1 or a < -1;
449
 
explain select * from t1 where a > -1;
450
 
select * from t1 where a > -1;
451
 
explain select * from t1 where a < -1;
452
 
select * from t1 where a < -1;
453
 
 
454
 
drop table t1;
455
 
 
456
 
#
457
 
# Bug #6045: Binary Comparison regression in MySQL 4.1
458
 
# Binary searches didn't use a case insensitive index.
459
 
#
460
 
create table t1 (a char(10), b text, key (a));
461
 
INSERT INTO t1 (a) VALUES
462
 
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
463
 
# all these three can be optimized
464
 
explain select * from t1 where a='aaa';
465
 
explain select * from t1 where a=binary 'aaa';
466
 
explain select * from t1 where a='aaa' collate utf8_bin;
467
 
drop table t1;
468
 
 
469
 
# Test for BUG#9348 "result for WHERE A AND (B OR C) differs from WHERE a AND (C OR B)"
470
 
--disable_warnings
471
 
CREATE TABLE t1 (
472
 
  `CLIENT` char(3) collate utf8_bin NOT NULL default '000',
473
 
  `ARG1` char(3) collate utf8_bin NOT NULL default '',
474
 
  `ARG2` char(3) collate utf8_bin NOT NULL default '',
475
 
  `FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
476
 
  `FUNCTINT` int NOT NULL default '0',
477
 
  KEY `VERI_CLNT~2` (`ARG1`)
478
 
) ENGINE=InnoDB;
479
 
--enable_warnings
480
 
 
481
 
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
482
 
  ('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
483
 
  ('001',' 3',' 0','Text 017',0);
484
 
 
485
 
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 1' OR ARG1 != ' 2');
486
 
 
487
 
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 2' OR ARG1 != ' 1');
488
 
drop table t1;
489
 
 
490
 
# BUG#16168: Wrong range optimizer results, "Use_count: Wrong count ..."
491
 
#            warnings in server stderr.
492
 
create table t1 (a int);
493
 
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
494
 
 
495
 
CREATE TABLE t2 (
496
 
  pk1 int NOT NULL,
497
 
  pk2 int NOT NULL,
498
 
  pk3 int NOT NULL,
499
 
  pk4 int NOT NULL,
500
 
  filler char(82),
501
 
  PRIMARY KEY (pk1,pk2,pk3,pk4)
502
 
);
503
 
 
504
 
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
505
 
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
506
 
  (2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
507
 
  (2621, 2635, 14, 0,'filler'), (2621, 2635, 1000015, 0,'filler');
508
 
 
509
 
SELECT * FROM t2
510
 
WHERE ((((pk4 =0) AND (pk1 =2621) AND (pk2 =2635)))
511
 
OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635))))
512
 
) AND (pk3 >=1000000);
513
 
drop table t1, t2;
514
 
 
515
 
#
516
 
# Bug #20732: Partial index and long sjis search with '>' fails sometimes
517
 
#
518
 
 
519
 
create table t1(a char(2), key(a(1)));
520
 
insert into t1 values ('x'), ('xx');
521
 
explain select a from t1 where a > 'x';
522
 
select a from t1 where a > 'x';
523
 
drop table t1;
524
 
 
525
 
#
526
 
# Bug #24776: assertion abort for 'range checked for each record' 
527
 
#
528
 
 
529
 
CREATE TABLE t1 (
530
 
  OXID varchar(32) NOT NULL DEFAULT '',
531
 
  OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
532
 
  OXLEFT int NOT NULL DEFAULT '0',
533
 
  OXRIGHT int NOT NULL DEFAULT '0',
534
 
  OXROOTID varchar(32) NOT NULL DEFAULT '',
535
 
  PRIMARY KEY  (OXID),
536
 
  KEY OXNID (OXID),
537
 
  KEY OXLEFT (OXLEFT),
538
 
  KEY OXRIGHT (OXRIGHT),
539
 
  KEY OXROOTID (OXROOTID)
540
 
) ENGINE=MyISAM;
541
 
 
542
 
INSERT INTO t1 VALUES
543
 
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
544
 
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
545
 
 'd8c4177d09f8b11f5.52725521'),
546
 
('d8c4177d206a333d2.74422679','d8c4177d09f8b11f5.52725521',4,5,
547
 
 'd8c4177d09f8b11f5.52725521'),
548
 
('d8c4177d225791924.30714720','d8c4177d09f8b11f5.52725521',6,7,
549
 
 'd8c4177d09f8b11f5.52725521'),
550
 
('d8c4177d2380fc201.39666693','d8c4177d09f8b11f5.52725521',8,9,
551
 
 'd8c4177d09f8b11f5.52725521'),
552
 
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
553
 
 'd8c4177d09f8b11f5.52725521');
554
 
 
555
 
EXPLAIN
556
 
SELECT s.oxid FROM t1 v, t1 s 
557
 
  WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
558
 
        v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
559
 
        s.oxleft > v.oxleft AND s.oxleft < v.oxright;
560
 
 
561
 
SELECT s.oxid FROM t1 v, t1 s 
562
 
  WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
563
 
        v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
564
 
        s.oxleft > v.oxleft AND s.oxleft < v.oxright;
565
 
 
566
 
DROP TABLE t1;
567
 
 
568
 
# BUG#26624 high mem usage (crash) in range optimizer (depends on order of fields in where)
569
 
create table t1 (
570
 
  c1  char(10), c2  char(10), c3  char(10), c4  char(10),
571
 
  c5  char(10), c6  char(10), c7  char(10), c8  char(10),
572
 
  c9  char(10), c10 char(10), c11 char(10), c12 char(10),
573
 
  c13 char(10), c14 char(10), c15 char(10), c16 char(10),
574
 
  index(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,c13,c14,c15,c16)
575
 
);
576
 
insert into t1 (c1) values ('1'),('1'),('1'),('1');
577
 
 
578
 
# This must run without crash and fast:
579
 
select * from t1 where
580
 
     c1 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
581
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
582
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
583
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
584
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4",
585
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
586
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
587
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
588
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
589
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
590
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
591
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
592
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
593
 
 and c2 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
594
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
595
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
596
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
597
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
598
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
599
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
600
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
601
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
602
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
603
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
604
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
605
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
606
 
 and c3 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
607
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
608
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
609
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
610
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
611
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
612
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
613
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
614
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
615
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
616
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
617
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
618
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
619
 
 and c4 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
620
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
621
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
622
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
623
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
624
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5", 
625
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
626
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
627
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
628
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
629
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
630
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
631
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
632
 
 and c5 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
633
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
634
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
635
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
636
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4",
637
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
638
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
639
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
640
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
641
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
642
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
643
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
644
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
645
 
 and c6 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
646
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
647
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
648
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
649
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4",
650
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
651
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
652
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
653
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
654
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
655
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
656
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
657
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
658
 
 and c7 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
659
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
660
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
661
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
662
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
663
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
664
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
665
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
666
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
667
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
668
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
669
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
670
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
671
 
 and c8 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
672
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
673
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
674
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
675
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
676
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
677
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
678
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
679
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
680
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
681
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
682
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
683
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
684
 
 and c9 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
685
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
686
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
687
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
688
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
689
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
690
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
691
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
692
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
693
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
694
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
695
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
696
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
697
 
 and c10 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh", 
698
 
            "abcdefg1", "123456781", "qwertyui1", "asddfg1", 
699
 
            "abcdefg2", "123456782", "qwertyui2", "asddfg2", 
700
 
            "abcdefg3", "123456783", "qwertyui3", "asddfg3", 
701
 
            "abcdefg4", "123456784", "qwertyui4", "asddfg4", 
702
 
            "abcdefg5", "123456785", "qwertyui5", "asddfg5",
703
 
            "abcdefg6", "123456786", "qwertyui6", "asddfg6",
704
 
            "abcdefg7", "123456787", "qwertyui7", "asddfg7",
705
 
            "abcdefg8", "123456788", "qwertyui8", "asddfg8",
706
 
            "abcdefg9", "123456789", "qwertyui9", "asddfg9",
707
 
            "abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
708
 
            "abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
709
 
            "abcdefgC", "12345678C", "qwertyuiC", "asddfgC");
710
 
drop table t1;
711
 
--echo End of 4.1 tests
712
 
 
713
 
#
714
 
# Test for optimization request #10561: to use keys for
715
 
# NOT IN (c1,...,cn) and NOT BETWEEN c1 AND c2
716
 
#
717
 
 
718
 
CREATE TABLE t1 (
719
 
  id int NOT NULL auto_increment,
720
 
  status varchar(20),
721
 
  PRIMARY KEY  (id),
722
 
  KEY (status)
723
 
);
724
 
 
725
 
INSERT INTO t1 VALUES
726
 
(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'),
727
 
(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'),
728
 
(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'),
729
 
(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'), 
730
 
(25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'),
731
 
(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'),
732
 
(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'),
733
 
(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'),
734
 
(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'),
735
 
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
736
 
 
737
 
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
738
 
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
739
 
 
740
 
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
741
 
SELECT * FROM t1 WHERE status NOT IN ('A','B');
742
 
 
743
 
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
744
 
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
745
 
 
746
 
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
747
 
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
748
 
 
749
 
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
750
 
SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
751
 
 
752
 
DROP TABLE t1;
753
 
 
754
 
#
755
 
# Bug #11853: DELETE statement with a NOT (LIKE/<=>) where condition
756
 
#             for an indexed attribute              
757
 
#             
758
 
 
759
 
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
760
 
INSERT INTO t1 VALUES ('Betty'), ('Anna');
761
 
 
762
 
SELECT * FROM t1;
763
 
DELETE FROM t1 WHERE name NOT LIKE 'A%a';
764
 
SELECT * FROM t1;
765
 
 
766
 
DROP TABLE t1;
767
 
 
768
 
CREATE TABLE t1 (a int, KEY idx(a));
769
 
INSERT INTO t1 VALUES (NULL), (1), (2), (3);
770
 
 
771
 
SELECT * FROM t1;
772
 
DELETE FROM t1 WHERE NOT(a <=> 2);
773
 
SELECT * FROM t1;
774
 
 
775
 
DROP TABLE t1;
776
 
 
777
 
# BUG#13455: 
778
 
create table t3 (a int);
779
 
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
780
 
 
781
 
create table t1 (a varchar(10), filler char(200), key(a));
782
 
insert into t1 values ('a','');
783
 
insert into t1 values ('a ','');
784
 
insert into t1 values ('a  ', '');
785
 
insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), ''
786
 
  from t3 A, t3 B, t3 C;
787
 
 
788
 
create table t2 (a varchar(10), filler char(200), key(a));
789
 
insert into t2 select * from t1;
790
 
 
791
 
--replace_column 9 #
792
 
explain select * from t1 where a between 'a' and 'a '; 
793
 
--replace_column 9 #
794
 
explain select * from t1 where a = 'a' or a='a ';
795
 
 
796
 
--replace_column 9 #
797
 
explain select * from t2 where a between 'a' and 'a '; 
798
 
--replace_column 9 #
799
 
explain select * from t2 where a = 'a' or a='a ';
800
 
 
801
 
update t1 set a='b' where a<>'a';
802
 
--replace_column 9 #
803
 
explain select * from t1 where a not between 'b' and 'b'; 
804
 
select a, hex(filler) from t1 where a not between 'b' and 'b'; 
805
 
 
806
 
drop table t1,t2,t3;
807
 
 
808
 
#
809
 
# Bug #18165: range access for BETWEEN with a constant for the first argument 
810
 
#
811
 
 
812
 
CREATE TABLE t1 (
813
 
  id int NOT NULL DEFAULT '0',
814
 
  b int NOT NULL DEFAULT '0',
815
 
  c int NOT NULL DEFAULT '0', 
816
 
  INDEX idx1(b,c), INDEX idx2(c));
817
 
 
818
 
INSERT INTO t1(id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);
819
 
 
820
 
INSERT INTO t1(b,c) VALUES (3,4), (3,4);
821
 
 
822
 
SELECT * FROM t1 WHERE b<=3 AND 3<=c;
823
 
SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
824
 
 
825
 
EXPLAIN  SELECT * FROM t1 WHERE b<=3 AND 3<=c;
826
 
EXPLAIN  SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
827
 
 
828
 
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
829
 
SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
830
 
 
831
 
EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c;
832
 
EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
833
 
 
834
 
DROP TABLE t1;
835
 
 
836
 
#
837
 
# Bug #16249: different results for a range with an without index 
838
 
#             when a range condition use an invalid datetime constant 
839
 
#
840
 
 
841
 
CREATE TABLE t1 (                                      
842
 
  item char(20) NOT NULL default '',                          
843
 
  started datetime NOT NULL default '0000-00-00 00:00:00', 
844
 
  price decimal(16,3) NOT NULL default '0.000',                 
845
 
  PRIMARY KEY (item,started)                     
846
 
) ENGINE=MyISAM;   
847
 
 
848
 
INSERT INTO t1 VALUES
849
 
('A1','2005-11-01 08:00:00',1000),
850
 
('A1','2005-11-15 00:00:00',2000),
851
 
('A1','2005-12-12 08:00:00',3000),
852
 
('A2','2005-12-01 08:00:00',1000);
853
 
 
854
 
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
855
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
856
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
857
 
 
858
 
DROP INDEX `PRIMARY` ON t1;
859
 
 
860
 
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
861
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
862
 
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
863
 
 
864
 
DROP TABLE t1;
865
 
 
866
 
--echo
867
 
--echo BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
868
 
--echo
869
 
CREATE TABLE t1 (
870
 
  id int NOT NULL auto_increment,
871
 
  dateval date default NULL,
872
 
  PRIMARY KEY  (id),
873
 
  KEY dateval (dateval)
874
 
) AUTO_INCREMENT=173;
875
 
 
876
 
INSERT INTO t1 VALUES
877
 
(1,'2007-01-01'),(2,'2007-01-02'),(3,'2007-01-03'),(4,'2007-01-04'),
878
 
(5,'2007-01-05'),(6,'2007-01-06'),(7,'2007-01-07'),(8,'2007-01-08'),
879
 
(9,'2007-01-09'),(10,'2007-01-10'),(11,'2007-01-11');
880
 
 
881
 
--echo This must use range access:
882
 
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
883
 
 
884
 
drop table t1;
885
 
 
886
 
#
887
 
# Bug #33833: different or-ed predicates were erroneously merged into one that
888
 
# resulted in ref access instead of range access and  a wrong result set
889
 
#
890
 
 
891
 
CREATE TABLE t1 (
892
 
  a varchar(32), index (a)
893
 
) DEFAULT COLLATE=utf8_bin;
894
 
 
895
 
INSERT INTO t1 VALUES
896
 
  ('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
897
 
 
898
 
SELECT a FROM t1 WHERE a='b' OR a='B';
899
 
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
900
 
 
901
 
DROP TABLE t1;
902
 
 
903
 
#
904
 
# Bug #34731: highest possible value for INT erroneously filtered by WHERE
905
 
#
906
 
 
907
 
# test UNSIGNED. only occurs when indexed.
908
 
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
909
 
 
910
 
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
911
 
 
912
 
# test upper bound
913
 
# count 5
914
 
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
915
 
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
916
 
# count 4
917
 
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
918
 
 
919
 
# show we don't fiddle with lower bound on UNSIGNED
920
 
# count 0
921
 
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
922
 
# count 5
923
 
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
924
 
 
925
 
DROP TABLE t1;
926
 
 
927
 
 
928
 
# test signed. only occurs when index.
929
 
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
930
 
 
931
 
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
932
 
 
933
 
# test upper bound
934
 
# count 5
935
 
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
936
 
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
937
 
# count 4
938
 
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
939
 
 
940
 
# test lower bound
941
 
# count 5
942
 
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
943
 
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
944
 
# count 4
945
 
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
946
 
 
947
 
DROP TABLE t1;
948
 
 
949
 
# End of 5.0 tests
950
 
 
951
 
# BUG#22393 fix: Adjust 'ref' estimate if we have 'range' estimate for
952
 
#                a smaller scan interval
953
 
create table t1 (a int);
954
 
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
955
 
 
956
 
create table t2 (a int, b int, filler char(100)) ENGINE=myisam;
957
 
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
958
 
t1 B, t1 C where A.a < 5;
959
 
 
960
 
insert into t2 select 1000, b, 'filler' from t2;
961
 
alter table t2 add index (a,b);
962
 
# t2 values 
963
 
#  ( 1  , 10, 'filler')
964
 
#  ( 2  , 10, 'filler')
965
 
#  ( 3  , 10, 'filler')
966
 
#  (... , 10, 'filler')
967
 
#   ...
968
 
#  (1000, 10, 'filler') - 500 times
969
 
 
970
 
# 500 rows, 1 row
971
 
 
972
 
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
973
 
explain select * from t2 where a=1000 and b<11;
974
 
 
975
 
drop table t1, t2;
976
 
 
977
 
--echo End of 5.1 tests
978
 
 
979
 
#
980
 
# BUG#32262 fix: crash with decimal column...
981
 
#
982
 
 
983
 
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
984
 
INSERT INTO t1 VALUES (1),(2),(3);
985
 
SELECT c1 FROM t1 WHERE c1 >= 'A' GROUP BY 1;
986
 
DROP TABLE t1;
987
 
 
988
 
#
989
 
# BUG#32229: Range optimizer crashes for 'range checked for each record' query
990
 
#
991
 
create table t1 (a int,b int,key (b),key (a),key (b,a));
992
 
insert into t1(a,b) values (1,2),(3,4),(5,6),(7,8);
993
 
create table t2 (c int);
994
 
insert into t2(c) values (1),(5),(6),(7),(8);
995
 
select 1 from (select c from t1,t2 where b >= 1 and a <=> c group by 1 limit 1) as d1;
996
 
drop table t1, t2;
997