MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
index_merge1.inc
1 # include/index_merge1.inc
2 #
3 # Index merge tests
4 #
5 # The variables
6 # $engine_type -- storage engine to be tested
7 # $merge_table_support -- 1 storage engine supports merge tables
8 # -- 0 storage engine does not support merge tables
9 # have to be set before sourcing this script.
10 #
11 # Note: The comments/expectations refer to MyISAM.
12 # They might be not valid for other storage engines.
13 #
14 # Last update:
15 # 2006-08-02 ML test refactored
16 # old name was t/index_merge.test
17 # main code went into include/index_merge1.inc
18 #
19 
20 --echo #---------------- Index merge test 1 -------------------------------------------
21 
22 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
23 
24 --disable_warnings
25 drop table if exists t0, t1, t2, t3, t4;
26 --enable_warnings
27 
28 # Create and fill a table with simple keys
29 create table t0
30 (
31  key1 int not null,
32  key2 int not null,
33  key3 int not null,
34  key4 int not null,
35  key5 int not null,
36  key6 int not null,
37  key7 int not null,
38  key8 int not null,
39  INDEX i1(key1),
40  INDEX i2(key2),
41  INDEX i3(key3),
42  INDEX i4(key4),
43  INDEX i5(key5),
44  INDEX i6(key6),
45  INDEX i7(key7),
46  INDEX i8(key8)
47 );
48 
49 --disable_query_log
50 insert into t0 values (1,1,1,1,1,1,1,1023),(2,2,2,2,2,2,2,1022);
51 
52 let $1=9;
53 set @d=2;
54 while ($1)
55 {
56  eval insert into t0 select key1+@d, key2+@d, key3+@d, key4+@d, key5+@d,
57  key6+@d, key7+@d, key8-@d from t0;
58  eval set @d=@d*2;
59  dec $1;
60 }
61 --enable_query_log
62 
63 analyze table t0;
64 
65 # 1. One index
66 explain select * from t0 where key1 < 3 or key1 > 1020;
67 
68 # 2. Simple cases
69 explain
70 select * from t0 where key1 < 3 or key2 > 1020;
71 select * from t0 where key1 < 3 or key2 > 1020;
72 
73 if ($index_merge_random_rows_in_EXPLAIN)
74 {
75  --replace_column 9 #
76 }
77 explain select * from t0 where key1 < 2 or key2 <3;
78 
79 if ($index_merge_random_rows_in_EXPLAIN)
80 {
81  --replace_column 9 #
82 }
83 explain
84 select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40);
85 # Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
86 select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40);
87 
88 # 3. Check that index_merge doesn't break "ignore/force/use index"
89 if ($index_merge_random_rows_in_EXPLAIN)
90 {
91  --replace_column 9 #
92 }
93 explain select * from t0 ignore index (i2) where key1 < 3 or key2 <4;
94 
95 if ($index_merge_random_rows_in_EXPLAIN)
96 {
97  --replace_column 9 #
98 }
99 explain select * from t0 where (key1 < 3 or key2 <4) and key3 = 50;
100 
101 if ($index_merge_random_rows_in_EXPLAIN)
102 {
103  --replace_column 9 #
104 }
105 explain select * from t0 use index (i1,i2) where (key1 < 2 or key2 <3) and key3 = 50;
106 
107 if ($index_merge_random_rows_in_EXPLAIN)
108 {
109  --replace_column 9 #
110 }
111 explain select * from t0 where (key1 > 1 or key2 > 2);
112 
113 if ($index_merge_random_rows_in_EXPLAIN)
114 {
115  --replace_column 9 #
116 }
117 explain select * from t0 force index (i1,i2) where (key1 > 1 or key2 > 2);
118 
119 
120 # 4. Check if conjuncts are grouped by keyuse
121 if ($index_merge_random_rows_in_EXPLAIN)
122 {
123  --replace_column 9 #
124 }
125 explain
126  select * from t0 where key1<2 or key2<3 or (key1>5 and key1<7) or
127  (key1>10 and key1<12) or (key2>100 and key2<102);
128 
129 # 5. Check index_merge with conjuncts that are always true/false
130 # verify fallback to "range" if there is only one non-confluent condition
131 if ($index_merge_random_rows_in_EXPLAIN)
132 {
133  --replace_column 9 #
134 }
135 explain select * from t0 where key2 = 45 or key1 <=> null;
136 
137 if ($index_merge_random_rows_in_EXPLAIN)
138 {
139  --replace_column 9 #
140 }
141 explain select * from t0 where key2 = 45 or key1 is not null;
142 
143 if ($index_merge_random_rows_in_EXPLAIN)
144 {
145  --replace_column 9 #
146 }
147 explain select * from t0 where key2 = 45 or key1 is null;
148 
149 # the last conj. is always false and will be discarded
150 if ($index_merge_random_rows_in_EXPLAIN)
151 {
152  --replace_column 9 #
153 }
154 explain select * from t0 where key2=10 or key3=3 or key4 <=> null;
155 
156 # the last conj. is always true and will cause 'all' scan
157 if ($index_merge_random_rows_in_EXPLAIN)
158 {
159  --replace_column 9 #
160 }
161 explain select * from t0 where key2=10 or key3=3 or key4 is null;
162 
163 # some more complicated cases
164 
165 if ($index_merge_random_rows_in_EXPLAIN)
166 {
167  --replace_column 9 #
168 }
169 explain select key1 from t0 where (key1 <=> null) or (key2 < 2) or
170  (key3=10) or (key4 <=> null);
171 
172 if ($index_merge_random_rows_in_EXPLAIN)
173 {
174  --replace_column 9 #
175 }
176 explain select key1 from t0 where (key1 <=> null) or (key1 < 5) or
177  (key3=10) or (key4 <=> null);
178 
179 # 6.Several ways to do index_merge, (ignored) index_merge vs. range
180 if ($index_merge_random_rows_in_EXPLAIN)
181 {
182  --replace_column 9 #
183 }
184 explain select * from t0 where
185  (key1 < 2 or key2 < 2) and (key3 < 3 or key4 < 3) and (key5 < 5 or key6 < 5);
186 
187 if ($index_merge_random_rows_in_EXPLAIN)
188 {
189  --replace_column 9 #
190 }
191 explain
192 select * from t0 where (key1 < 2 or key2 < 4) and (key1 < 5 or key3 < 3);
193 
194 select * from t0 where (key1 < 2 or key2 < 4) and (key1 < 5 or key3 < 3);
195 
196 
197 if ($index_merge_random_rows_in_EXPLAIN)
198 {
199  --replace_column 9 #
200 }
201 explain select * from t0 where
202  (key1 < 3 or key2 < 2) and (key3 < 3 or key4 < 3) and (key5 < 2 or key6 < 2);
203 
204 if ($index_merge_random_rows_in_EXPLAIN)
205 {
206  --replace_column 9 #
207 }
208 explain select * from t0 where
209  (key1 < 3 or key2 < 3) and (key3 < 70);
210 
211 if ($index_merge_random_rows_in_EXPLAIN)
212 {
213  --replace_column 9 #
214 }
215 explain select * from t0 where
216  (key1 < 3 or key2 < 3) and (key3 < 1000);
217 
218 
219 # 7. Complex cases
220 # tree_or(List<SEL_IMERGE>, range SEL_TREE).
221 if ($index_merge_random_rows_in_EXPLAIN)
222 {
223  --replace_column 9 #
224 }
225 explain select * from t0 where
226  ((key1 < 3 or key2 < 3) and (key2 <4 or key3 < 3))
227  or
228  key2 > 4;
229 
230 if ($index_merge_random_rows_in_EXPLAIN)
231 {
232  --replace_column 9 #
233 }
234 explain select * from t0 where
235  ((key1 < 4 or key2 < 4) and (key2 <4 or key3 < 3))
236  or
237  key1 < 5;
238 
239 select * from t0 where
240  ((key1 < 4 or key2 < 4) and (key2 <4 or key3 < 3))
241  or
242  key1 < 5;
243 
244 # tree_or(List<SEL_IMERGE>, List<SEL_IMERGE>).
245 if ($index_merge_random_rows_in_EXPLAIN)
246 {
247  --replace_column 9 #
248 }
249 explain select * from t0 where
250  ((key1 < 2 or key2 < 2) and (key3 <4 or key5 < 3))
251  or
252  ((key5 < 3 or key6 < 3) and (key7 <3 or key8 < 3));
253 
254 if ($index_merge_random_rows_in_EXPLAIN)
255 {
256  --replace_column 9 #
257 }
258 explain select * from t0 where
259  ((key3 <3 or key5 < 4) and (key1 < 3 or key2 < 3))
260  or
261  ((key7 <5 or key8 < 3) and (key5 < 4 or key6 < 4));
262 
263 if ($index_merge_random_rows_in_EXPLAIN)
264 {
265  --replace_column 9 #
266 }
267 explain select * from t0 where
268  ((key3 <3 or key5 < 4) and (key1 < 3 or key2 < 4))
269  or
270  ((key3 <4 or key5 < 2) and (key5 < 5 or key6 < 3));
271 
272 if ($index_merge_random_rows_in_EXPLAIN)
273 {
274  --replace_column 9 #
275 }
276 explain select * from t0 where
277  ((key3 <4 or key5 < 3) and (key1 < 3 or key2 < 3))
278  or
279  (((key3 <5 and key7 < 5) or key5 < 2) and (key5 < 4 or key6 < 4));
280 
281 if ($index_merge_random_rows_in_EXPLAIN)
282 {
283  --replace_column 9 #
284 }
285 explain select * from t0 where
286  ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
287  or
288  ((key3 >5 or key5 < 2) and (key5 < 5 or key6 < 6));
289 
290 if ($index_merge_random_rows_in_EXPLAIN)
291 {
292  --replace_column 9 #
293 }
294 explain select * from t0 force index(i1, i2, i3, i4, i5, i6 ) where
295  ((key3 <3 or key5 < 4) and (key1 < 3 or key2 < 3))
296  or
297  ((key3 >4 or key5 < 2) and (key5 < 5 or key6 < 4));
298 
299 # Can't merge any indexes here (predicate on key3 is always true)
300 if ($index_merge_random_rows_in_EXPLAIN)
301 {
302  --replace_column 9 #
303 }
304 explain select * from t0 force index(i1, i2, i3, i4, i5, i6 ) where
305  ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
306  or
307  ((key3 >=5 or key5 < 2) and (key5 < 5 or key6 < 6));
308 
309 # 8. Verify that "order by" after index merge uses filesort
310 select * from t0 where key1 < 3 or key8 < 2 order by key1;
311 
312 if ($index_merge_random_rows_in_EXPLAIN)
313 {
314  --replace_column 9 #
315 }
316 explain
317 select * from t0 where key1 < 3 or key8 < 2 order by key1;
318 
319 # 9. Check that index_merge cost is compared to 'index' where possible
320 create table t2 like t0;
321 insert into t2 select * from t0;
322 
323 alter table t2 add index i1_3(key1, key3);
324 alter table t2 add index i2_3(key2, key3);
325 alter table t2 drop index i1;
326 alter table t2 drop index i2;
327 alter table t2 add index i321(key3, key2, key1);
328 
329 -- disable_query_log
330 -- disable_result_log
331 analyze table t2;
332 -- enable_result_log
333 -- enable_query_log
334 
335 # index_merge vs 'index', index_merge is better.
336 if ($index_merge_random_rows_in_EXPLAIN)
337 {
338  --replace_column 9 #
339 }
340 explain select key3 from t2 where key1 = 100 or key2 = 100;
341 
342 # index_merge vs 'index', 'index' is better.
343 if ($index_merge_random_rows_in_EXPLAIN)
344 {
345  --replace_column 9 #
346 }
347 explain select key3 from t2 where key1 <100 or key2 < 100;
348 
349 # index_merge vs 'all', index_merge is better.
350 if ($index_merge_random_rows_in_EXPLAIN)
351 {
352  --replace_column 9 #
353 }
354 explain select key7 from t2 where key1 <100 or key2 < 100;
355 
356 # 10. Multipart keys.
357 create table t4 (
358  key1a int not null,
359  key1b int not null,
360  key2 int not null,
361  key2_1 int not null,
362  key2_2 int not null,
363  key3 int not null,
364  index i1a (key1a, key1b),
365  index i1b (key1b, key1a),
366  index i2_1(key2, key2_1),
367  index i2_2(key2, key2_1)
368 );
369 
370 insert into t4 select key1,key1,key1 div 10, key1 % 10, key1 % 10, key1 from t0;
371 
372 -- disable_query_log
373 -- disable_result_log
374 analyze table t4;
375 -- enable_result_log
376 -- enable_query_log
377 
378 # the following will be handled by index_merge:
379 select * from t4 where key1a = 3 or key1b = 4;
380 explain select * from t4 where key1a = 3 or key1b = 4;
381 
382 # and the following will not
383 explain select * from t4 where key2 = 1 and (key2_1 = 1 or key3 = 5);
384 
385 explain select * from t4 where key2 = 1 and (key2_1 = 1 or key2_2 = 5);
386 
387 if ($index_merge_random_rows_in_EXPLAIN)
388 {
389  --replace_column 9 #
390 }
391 explain select * from t4 where key2_1 = 1 or key2_2 = 5;
392 
393 
394 # 11. Multitable selects
395 create table t1 like t0;
396 insert into t1 select * from t0;
397 
398 -- disable_query_log
399 -- disable_result_log
400 analyze table t1;
401 -- enable_result_log
402 -- enable_query_log
403 
404 # index_merge on first table in join
405 explain select * from t0 left join t1 on (t0.key1=t1.key1)
406  where t0.key1=3 or t0.key2=4;
407 
408 select * from t0 left join t1 on (t0.key1=t1.key1)
409  where t0.key1=3 or t0.key2=4;
410 
411 explain
412 select * from t0,t1 where (t0.key1=t1.key1) and ( t0.key1=3 or t0.key2=4);
413 
414 # index_merge vs. ref
415 if (!$index_merge_random_rows_in_EXPLAIN)
416 {
417 #this plan varies too much for InnoDB
418 explain
419 select * from t0,t1 where (t0.key1=t1.key1) and
420  (t0.key1=3 or t0.key2=4) and t1.key1<200;
421 }
422 
423 # index_merge vs. ref
424 explain
425 select * from t0,t1 where (t0.key1=t1.key1) and
426  (t0.key1=3 or t0.key2<4) and t1.key1=2;
427 
428 # index_merge on second table in join
429 explain select * from t0,t1 where t0.key1 = 5 and
430  (t1.key1 = t0.key1 or t1.key8 = t0.key1);
431 
432 # Fix for bug#1974
433 if ($index_merge_random_rows_in_EXPLAIN)
434 {
435  --replace_column 9 #
436 }
437 explain select * from t0,t1 where t0.key1 < 3 and
438  (t1.key1 = t0.key1 or t1.key8 = t0.key1);
439 
440 # index_merge inside union
441 explain select * from t1 where key1=3 or key2=4
442  union select * from t1 where key1<4 or key3=5;
443 
444 # index merge in subselect
445 explain select * from (select * from t1 where key1 = 3 or key2 =3) as Z where key8 >5;
446 
447 # 12. check for long index_merges.
448 create table t3 like t0;
449 insert into t3 select * from t0;
450 alter table t3 add key9 int not null, add index i9(key9);
451 alter table t3 add keyA int not null, add index iA(keyA);
452 alter table t3 add keyB int not null, add index iB(keyB);
453 alter table t3 add keyC int not null, add index iC(keyC);
454 update t3 set key9=key1,keyA=key1,keyB=key1,keyC=key1;
455 
456 -- disable_query_log
457 -- disable_result_log
458 analyze table t3;
459 -- enable_result_log
460 -- enable_query_log
461 
462 explain select * from t3 where
463  key1=1 or key2=2 or key3=3 or key4=4 or
464  key5=5 or key6=6 or key7=7 or key8=8 or
465  key9=9 or keyA=10 or keyB=11 or keyC=12;
466 
467 select * from t3 where
468  key1=1 or key2=2 or key3=3 or key4=4 or
469  key5=5 or key6=6 or key7=7 or key8=8 or
470  key9=9 or keyA=10 or keyB=11 or keyC=12;
471 
472 # Test for Bug#3183
473 explain select * from t0 where key1 < 3 or key2 < 4;
474 # Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
475 select * from t0 where key1 < 3 or key2 < 4;
476 
477 update t0 set key8=123 where key1 < 3 or key2 < 4;
478 
479 -- disable_query_log
480 -- disable_result_log
481 analyze table t0;
482 -- enable_result_log
483 -- enable_query_log
484 
485 # Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
486 select * from t0 where key1 < 3 or key2 < 4;
487 
488 delete from t0 where key1 < 3 or key2 < 4;
489 -- disable_query_log
490 -- disable_result_log
491 analyze table t0;
492 -- enable_result_log
493 -- enable_query_log
494 
495 select * from t0 where key1 < 3 or key2 < 4;
496 select count(*) from t0;
497 
498 # Test for BUG#4177
499 drop table t4;
500 create table t4 (a int);
501 insert into t4 values (1),(4),(3);
502 -- disable_query_log
503 -- disable_result_log
504 analyze table t4;
505 -- enable_result_log
506 -- enable_query_log
507 
508 set @save_join_buffer_size=@@join_buffer_size;
509 set join_buffer_size= 4096;
510 
511 if ($index_merge_random_rows_in_EXPLAIN)
512 {
513  --replace_column 9 #
514 }
515 explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
516  from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
517  where (A.key1 < 500000 or A.key2 < 3)
518  and (B.key1 < 500000 or B.key2 < 3);
519 
520 select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
521  from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
522  where (A.key1 < 500000 or A.key2 < 3)
523  and (B.key1 < 500000 or B.key2 < 3);
524 
525 update t0 set key1=1;
526 -- disable_query_log
527 -- disable_result_log
528 analyze table t0;
529 -- enable_result_log
530 -- enable_query_log
531 
532 if ($index_merge_random_rows_in_EXPLAIN)
533 {
534  --replace_column 9 #
535 }
536 explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
537  from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
538  where (A.key1 = 1 or A.key2 = 1)
539  and (B.key1 = 1 or B.key2 = 1);
540 
541 select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
542  from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
543  where (A.key1 = 1 or A.key2 = 1)
544  and (B.key1 = 1 or B.key2 = 1);
545 
546 alter table t0 add filler1 char(200), add filler2 char(200), add filler3 char(200);
547 update t0 set key2=1, key3=1, key4=1, key5=1,key6=1,key7=1 where key7 < 500;
548 
549 -- disable_query_log
550 -- disable_result_log
551 analyze table t0;
552 -- enable_result_log
553 -- enable_query_log
554 
555 # The next query will not use index i7 in intersection if the OS doesn't
556 # support file sizes > 2GB. (ha_myisam::ref_length depends on this and index
557 # scan cost estimates depend on ha_myisam::ref_length)
558 if (!$index_merge_random_rows_in_EXPLAIN)
559 {
560  # Too unstable for innodb
561  --replace_column 9 #
562  --replace_result "4,4,4,4,4,4,4" X "4,4,4,4,4,4" X "i6,i7" "i6,i7?" "i6" "i6,i7?"
563  explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
564  from t0 as A, t0 as B
565  where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
566  and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
567 }
568 select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
569  from t0 as A, t0 as B
570  where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
571  and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
572 
573 set join_buffer_size= @save_join_buffer_size;
574 # Test for BUG#4177 ends
575 
576 drop table t0, t1, t2, t3, t4;
577 
578 # BUG#16166
579 CREATE TABLE t1 (
580  cola char(3) not null, colb char(3) not null, filler char(200),
581  key(cola), key(colb)
582 );
583 INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ');
584 
585 --disable_query_log
586 let $1=9;
587 while ($1)
588 {
589  eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo';
590  dec $1;
591 }
592 
593 let $1=13;
594 while ($1)
595 {
596  eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo';
597  dec $1;
598 }
599 
600 --enable_query_log
601 
602 OPTIMIZE TABLE t1;
603 select count(*) from t1;
604 
605 -- disable_query_log
606 -- disable_result_log
607 analyze table t1;
608 -- enable_result_log
609 -- enable_query_log
610 
611 if ($index_merge_random_rows_in_EXPLAIN)
612 {
613  --replace_column 9 #
614 }
615 explain select * from t1 WHERE cola = 'foo' AND colb = 'bar';
616 
617 if ($index_merge_random_rows_in_EXPLAIN)
618 {
619  --replace_column 9 #
620 }
621 explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar';
622 drop table t1;
623 
624 if ($merge_table_support)
625 {
626 #
627 # BUG#17314: Index_merge/intersection not choosen by the optimizer for MERGE tables
628 #
629 create table t0 (a int);
630 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
631 create table t1 (
632  a int, b int,
633  filler1 char(200), filler2 char(200),
634  key(a),key(b)
635 );
636 insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C;
637 create table t2 like t1;
638 
639 create table t3 (
640  a int, b int,
641  filler1 char(200), filler2 char(200),
642  key(a),key(b)
643 ) engine=merge union=(t1,t2);
644 
645 -- disable_query_log
646 -- disable_result_log
647 analyze table t0;
648 analyze table t1;
649 analyze table t2;
650 analyze table t3;
651 -- enable_result_log
652 -- enable_query_log
653 
654 --replace_column 9 #
655 explain select * from t1 where a=1 and b=1;
656 --replace_column 9 #
657 explain select * from t3 where a=1 and b=1;
658 
659 drop table t3;
660 drop table t0, t1, t2;
661 }
662 
663 #
664 # BUG#20256 - LOCK WRITE - MyISAM
665 #
666 CREATE TABLE t1(a INT);
667 INSERT INTO t1 VALUES(1);
668 CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b));
669 INSERT INTO t2(a,b) VALUES
670 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
671 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
672 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
673 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
674 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
675 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
676 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
677 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
678 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
679 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
680 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
681 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
682 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
683 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
684 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
685 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
686 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
687 (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
688 (1,2);
689 LOCK TABLES t1 WRITE, t2 WRITE;
690 INSERT INTO t2(a,b) VALUES(1,2);
691 SELECT t2.a FROM t1,t2 WHERE t2.b=2 AND t2.a=1;
692 UNLOCK TABLES;
693 DROP TABLE t1, t2;
694 
695 #
696 # BUG#29740: HA_KEY_SCAN_NOT_ROR wasn't set for HEAP engine
697 #
698 CREATE TABLE `t1` (
699  `a` int(11) DEFAULT NULL,
700  `filler` char(200) DEFAULT NULL,
701  `b` int(11) DEFAULT NULL,
702  KEY `a` (`a`),
703  KEY `b` (`b`)
704 ) ENGINE=MEMORY DEFAULT CHARSET=latin1;
705 
706 insert into t1 values
707 (0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3),
708 (4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7),
709 (8, 'filler', 8), (9, 'filler', 9), (0, 'filler', 0), (1, 'filler', 1),
710 (2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5),
711 (6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9),
712 (10, 'filler', 10), (11, 'filler', 11), (12, 'filler', 12), (13, 'filler', 13),
713 (14, 'filler', 14), (15, 'filler', 15), (16, 'filler', 16), (17, 'filler', 17),
714 (18, 'filler', 18), (19, 'filler', 19), (4, '5 ', 0), (5, '4 ', 0),
715 (4, '4 ', 0), (4, 'qq ', 5), (5, 'qq ', 4), (4, 'zz ', 4);
716 
717 create table t2(
718  `a` int(11) DEFAULT NULL,
719  `filler` char(200) DEFAULT NULL,
720  `b` int(11) DEFAULT NULL,
721  KEY USING BTREE (`a`),
722  KEY USING BTREE (`b`)
723 ) ENGINE=MEMORY DEFAULT CHARSET=latin1;
724 insert into t2 select * from t1;
725 
726 -- disable_query_log
727 -- disable_result_log
728 analyze table t1;
729 analyze table t2;
730 -- enable_result_log
731 -- enable_query_log
732 
733 --echo must use sort-union rather than union:
734 --replace_column 9 #
735 explain select * from t1 where a=4 or b=4;
736 --sorted_result
737 select * from t1 where a=4 or b=4;
738 --sorted_result
739 select * from t1 ignore index(a,b) where a=4 or b=4;
740 
741 --echo must use union, not sort-union:
742 --replace_column 9 #
743 explain select * from t2 where a=4 or b=4;
744 --sorted_result
745 select * from t2 where a=4 or b=4;
746 
747 drop table t1, t2;
748 
749 #
750 # Bug #37943: Reproducible mysqld crash/sigsegv in sel_trees_can_be_ored
751 #
752 
753 CREATE TABLE t1 (a varchar(8), b set('a','b','c','d','e','f','g','h'),
754  KEY b(b), KEY a(a));
755 INSERT INTO t1 VALUES ('y',''), ('z','');
756 
757 #should not crash
758 SELECT b,a from t1 WHERE (b!='c' AND b!='f' && b!='h') OR
759  (a='pure-S') OR (a='DE80337a') OR (a='DE80799');
760 
761 DROP TABLE t1;
762 
763 --echo #
764 --echo # BUG#40974: Incorrect query results when using clause evaluated using range check
765 --echo #
766 create table t0 (a int);
767 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
768 
769 create table t1 (a int);
770 insert into t1 values (1),(2);
771 create table t2(a int, b int);
772 insert into t2 values (1,1), (2, 1000);
773 create table t3 (a int, b int, filler char(100), key(a), key(b));
774 
775 insert into t3 select 1000, 1000,'filler' from t0 A, t0 B, t0 C;
776 insert into t3 values (1,1,'data');
777 insert into t3 values (1,1,'data');
778 -- echo The plan should be ALL/ALL/ALL(Range checked for each record (index map: 0x3)
779 
780 -- disable_query_log
781 -- disable_result_log
782 analyze table t0;
783 analyze table t1;
784 analyze table t2;
785 analyze table t3;
786 -- enable_result_log
787 -- enable_query_log
788 
789 if ($index_merge_random_rows_in_EXPLAIN)
790 {
791  --replace_column 9 #
792 }
793 explain select * from t1
794 where exists (select 1 from t2, t3
795  where t2.a=t1.a and (t3.a=t2.b or t3.b=t2.b or t3.b=t2.b+1));
796 
797 select * from t1
798 where exists (select 1 from t2, t3
799  where t2.a=t1.a and (t3.a=t2.b or t3.b=t2.b or t3.b=t2.b+1));
800 
801 drop table t0, t1, t2, t3;
802 
803 --echo #
804 --echo # BUG#44810: index merge and order by with low sort_buffer_size
805 --echo # crashes server!
806 --echo #
807 CREATE TABLE t1(a VARCHAR(128),b VARCHAR(128),KEY(A),KEY(B));
808 INSERT INTO t1 VALUES (REPEAT('a',128),REPEAT('b',128));
809 INSERT INTO t1 SELECT * FROM t1;
810 INSERT INTO t1 SELECT * FROM t1;
811 INSERT INTO t1 SELECT * FROM t1;
812 INSERT INTO t1 SELECT * FROM t1;
813 INSERT INTO t1 SELECT * FROM t1;
814 INSERT INTO t1 SELECT * FROM t1;
815 -- disable_query_log
816 -- disable_result_log
817 analyze table t1;
818 -- enable_result_log
819 -- enable_query_log
820 
821 SET SESSION sort_buffer_size=1;
822 
823 if ($index_merge_random_rows_in_EXPLAIN)
824 {
825  --replace_column 9 #
826 }
827 EXPLAIN
828 SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%'
829  ORDER BY a,b;
830 
831 # we don't actually care about the result : we're checking if it crashes
832 --disable_result_log
833 SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%'
834  ORDER BY a,b;
835 --enable_result_log
836 
837 SET SESSION sort_buffer_size=DEFAULT;
838 DROP TABLE t1;
839 
840 
841 --echo End of 5.0 tests