~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/range.test

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

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