~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/include/index_merge_ror.inc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# include/index_merge_ror.inc
 
2
#
 
3
#  ROR-index_merge tests.
 
4
#
 
5
# The variable
 
6
#     $engine_type       -- storage engine to be tested
 
7
# has to be set before sourcing this script.
 
8
#
 
9
# Note: The comments/expectations refer to MyISAM.
 
10
#       They might be not valid for other storage engines.
 
11
#
 
12
# Last update:
 
13
# 2006-08-02 ML test refactored
 
14
#               old name was t/index_merge_ror.test
 
15
#               main code went into include/index_merge_ror.inc
 
16
#
 
17
 
 
18
--echo #---------------- ROR-index_merge tests -----------------------
 
19
 
 
20
eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
 
21
 
 
22
--disable_warnings
 
23
drop table if exists  t0,t1,t2;
 
24
--enable_warnings
 
25
create table t1
 
26
(
 
27
  /* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */
 
28
  st_a int not null default 0,
 
29
  swt1a int not null default 0,
 
30
  swt2a int not null default 0,
 
31
 
 
32
  st_b int not null default 0,
 
33
  swt1b int not null default 0,
 
34
  swt2b int not null default 0,
 
35
 
 
36
  /* fields/keys for row retrieval tests */
 
37
  key1 int,
 
38
  key2 int,
 
39
  key3 int,
 
40
  key4 int,
 
41
 
 
42
  /* make rows much bigger then keys */
 
43
  filler1 char (200),
 
44
  filler2 char (200),
 
45
  filler3 char (200),
 
46
  filler4 char (200),
 
47
  filler5 char (200),
 
48
  filler6 char (200),
 
49
 
 
50
  /* order of keys is important */
 
51
  key sta_swt12a(st_a,swt1a,swt2a),
 
52
  key sta_swt1a(st_a,swt1a),
 
53
  key sta_swt2a(st_a,swt2a),
 
54
  key sta_swt21a(st_a,swt2a,swt1a),
 
55
 
 
56
  key st_a(st_a),
 
57
  key stb_swt1a_2b(st_b,swt1b,swt2a),
 
58
  key stb_swt1b(st_b,swt1b),
 
59
  key st_b(st_b),
 
60
 
 
61
  key(key1),
 
62
  key(key2),
 
63
  key(key3),
 
64
  key(key4)
 
65
) ;
 
66
 
 
67
# Fill table
 
68
create table t0 as select * from t1;
 
69
--disable_query_log
 
70
--echo # Printing of many insert into t0 values (....) disabled.
 
71
let $cnt=1000;
 
72
while ($cnt)
 
73
{
 
74
  eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
 
75
  dec $cnt;
 
76
}
 
77
--enable_query_log
 
78
 
 
79
alter table t1 disable keys;
 
80
--disable_query_log
 
81
--echo # Printing of many insert into t1 select .... from t0 disabled.
 
82
let $1=4;
 
83
while ($1)
 
84
{
 
85
  let $2=4;
 
86
  while ($2)
 
87
  {
 
88
    let $3=4;
 
89
    while ($3)
 
90
    {
 
91
      eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0;
 
92
      dec $3;
 
93
    }
 
94
    dec $2;
 
95
  }
 
96
 dec $1;
 
97
}
 
98
 
 
99
--echo # Printing of many insert into t1 (...) values (....) disabled.
 
100
# Row retrieval tests
 
101
# -1 is used for values 'out of any range we are using'
 
102
# insert enough rows for index intersection to be used for (key1,key2)
 
103
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4');
 
104
let $cnt=400;
 
105
while ($cnt)
 
106
{
 
107
  eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
 
108
  dec $cnt;
 
109
}
 
110
let $cnt=400;
 
111
while ($cnt)
 
112
{
 
113
  eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
 
114
  dec $cnt;
 
115
}
 
116
--enable_query_log
 
117
alter table t1 enable keys;
 
118
select count(*) from t1;
 
119
 
 
120
-- disable_query_log
 
121
-- disable_result_log
 
122
analyze table t0;
 
123
analyze table t1;
 
124
-- enable_result_log
 
125
-- enable_query_log
 
126
 
 
127
# One row results tests for cases where a single row matches all conditions
 
128
explain select key1,key2 from t1 where key1=100 and key2=100;
 
129
select key1,key2 from t1 where key1=100 and key2=100;
 
130
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
131
explain format=json select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
132
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
133
 
 
134
# Several-rows results
 
135
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
 
136
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
 
137
 
 
138
-- disable_query_log
 
139
-- disable_result_log
 
140
analyze table t1;
 
141
-- enable_result_log
 
142
-- enable_query_log
 
143
 
 
144
#  ROR-intersection, not covering
 
145
explain select key1,key2,filler1 from t1 where key1=100 and key2=100;
 
146
select key1,key2,filler1 from t1 where key1=100 and key2=100;
 
147
 
 
148
#  ROR-intersection, covering
 
149
explain select key1,key2 from t1 where key1=100 and key2=100;
 
150
select key1,key2 from t1 where key1=100 and key2=100;
 
151
 
 
152
#  ROR-union of ROR-intersections
 
153
explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
154
select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
155
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
156
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
157
 
 
158
#  3-way ROR-intersection
 
159
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
 
160
select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
 
161
 
 
162
#  ROR-union(ROR-intersection, ROR-range)
 
163
insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101');
 
164
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
 
165
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
 
166
 
 
167
# Run some ROR updates/deletes
 
168
select key1,key2, filler1 from t1 where key1=100 and key2=100;
 
169
update t1 set filler1='to be deleted' where key1=100 and key2=100;
 
170
update t1 set key1=200,key2=200 where key1=100 and key2=100;
 
171
delete from t1 where key1=200 and key2=200;
 
172
-- disable_query_log
 
173
-- disable_result_log
 
174
analyze table t1;
 
175
-- enable_result_log
 
176
-- enable_query_log
 
177
select key1,key2,filler1 from t1 where key2=100 and key2=200;
 
178
 
 
179
# ROR-union(ROR-intersection) with one of ROR-intersection giving empty
 
180
# results
 
181
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
182
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
183
 
 
184
delete from t1 where key3=100 and key4=100;
 
185
 
 
186
-- disable_query_log
 
187
-- disable_result_log
 
188
analyze table t1;
 
189
-- enable_result_log
 
190
-- enable_query_log
 
191
 
 
192
# ROR-union with all ROR-intersections giving empty results
 
193
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
194
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
 
195
 
 
196
# ROR-intersection with empty result
 
197
explain select key1,key2 from t1 where key1=100 and key2=100;
 
198
select key1,key2 from t1 where key1=100 and key2=100;
 
199
 
 
200
# ROR-union tests with various cases.
 
201
#  All scans returning duplicate rows:
 
202
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1');
 
203
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2');
 
204
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3');
 
205
 
 
206
-- disable_query_log
 
207
-- disable_result_log
 
208
analyze table t1;
 
209
-- enable_result_log
 
210
-- enable_query_log
 
211
 
 
212
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
213
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
214
 
 
215
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4');
 
216
 
 
217
-- disable_query_log
 
218
-- disable_result_log
 
219
analyze table t1;
 
220
-- enable_result_log
 
221
-- enable_query_log
 
222
 
 
223
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
224
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
225
 
 
226
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3');
 
227
 
 
228
-- disable_query_log
 
229
-- disable_result_log
 
230
analyze table t1;
 
231
-- enable_result_log
 
232
-- enable_query_log
 
233
 
 
234
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
235
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
 
236
 
 
237
##
 
238
## Optimizer tests
 
239
##
 
240
 
 
241
# Check that the shortest key is used for ROR-intersection, covering and non-covering.
 
242
if (!$index_merge_random_rows_in_EXPLAIN)
 
243
{
 
244
  # Too unstable on InnoDB
 
245
  explain select * from t1 where st_a=1 and st_b=1;
 
246
  explain select st_a,st_b from t1 where st_a=1 and st_b=1;
 
247
  explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1;
 
248
}
 
249
 
 
250
# Do many tests
 
251
# Check that keys that don't improve selectivity are skipped.
 
252
#
 
253
 
 
254
# Different value on 32 and 64 bit
 
255
--replace_result sta_swt12a sta_swt21a sta_swt12a, sta_swt12a,
 
256
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1;
 
257
 
 
258
explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
 
259
 
 
260
if ($index_merge_random_rows_in_EXPLAIN)
 
261
{
 
262
  --replace_column 9 #
 
263
}
 
264
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
 
265
 
 
266
if ($index_merge_random_rows_in_EXPLAIN)
 
267
{
 
268
  --replace_column 9 #
 
269
}
 
270
explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b)
 
271
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
 
272
 
 
273
if ($index_merge_random_rows_in_EXPLAIN)
 
274
{
 
275
  --replace_column 9 #
 
276
}
 
277
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b)
 
278
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
 
279
 
 
280
if ($index_merge_random_rows_in_EXPLAIN)
 
281
{
 
282
  --replace_column 9 #
 
283
}
 
284
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b)
 
285
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
 
286
 
 
287
if ($index_merge_random_rows_in_EXPLAIN)
 
288
{
 
289
  --replace_column 9 #
 
290
}
 
291
explain select * from t1
 
292
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
 
293
 
 
294
if ($index_merge_random_rows_in_EXPLAIN)
 
295
{
 
296
  --replace_column 9 #
 
297
}
 
298
explain select * from t1
 
299
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
 
300
 
 
301
if ($index_merge_random_rows_in_EXPLAIN)
 
302
{
 
303
  --replace_column 9 #
 
304
}
 
305
explain select st_a from t1
 
306
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
 
307
 
 
308
if ($index_merge_random_rows_in_EXPLAIN)
 
309
{
 
310
  --replace_column 9 #
 
311
}
 
312
explain select st_a from t1
 
313
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
 
314
 
 
315
drop table t0,t1;
 
316
 
 
317
# 'Partially' covered fields test
 
318
 
 
319
create table t2 (
 
320
  a char(10),
 
321
  b char(10),
 
322
  filler1 char(255),
 
323
  filler2 char(255),
 
324
  key(a(5)),
 
325
  key(b(5))
 
326
);
 
327
 
 
328
--disable_query_log
 
329
let $1=8;
 
330
while ($1)
 
331
{
 
332
  eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2');
 
333
  dec $1;
 
334
}
 
335
insert into t2 select * from t2;
 
336
insert into t2 select * from t2;
 
337
--enable_query_log
 
338
 
 
339
# The table row buffer is reused. Fill it with rows that don't match.
 
340
select count(a) from t2 where a='BBBBBBBB';
 
341
select count(a) from t2 where b='BBBBBBBB';
 
342
 
 
343
-- disable_query_log
 
344
-- disable_result_log
 
345
analyze table t2;
 
346
-- enable_result_log
 
347
-- enable_query_log
 
348
 
 
349
# BUG#1:
 
350
--replace_result a a_or_b b a_or_b
 
351
explain select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
 
352
select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
 
353
select count(a) from t2 ignore index(a,b) where a='AAAAAAAA' and b='AAAAAAAA';
 
354
 
 
355
insert into t2 values ('ab', 'ab', 'uh', 'oh');
 
356
-- disable_query_log
 
357
-- disable_result_log
 
358
analyze table t2;
 
359
-- enable_result_log
 
360
-- enable_query_log
 
361
explain select a from t2 where a='ab';
 
362
drop table t2;
 
363
 
 
364
#
 
365
# BUG#25048 - ERROR 126 : Incorrect key file for table '.XXXX.MYI'; try to
 
366
#             repair it
 
367
#
 
368
CREATE TABLE t1(c1 INT, c2 INT DEFAULT 0, c3 CHAR(255) DEFAULT '',
 
369
KEY(c1), KEY(c2), KEY(c3));
 
370
INSERT INTO t1(c1) VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),
 
371
(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
 
372
INSERT INTO t1 VALUES(0,0,0);
 
373
CREATE TABLE t2(c1 int);
 
374
INSERT INTO t2 VALUES(1);
 
375
DELETE t1 FROM t1,t2 WHERE t1.c1=0 AND t1.c2=0;
 
376
SELECT * FROM t1;
 
377
DROP TABLE t1,t2;