~drizzle-trunk/drizzle/development

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