/
derived_cond_pushdown.result
8368 lines (8368 loc) · 260 KB
/
derived_cond_pushdown.result
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
create table t1 (a int, b int, c int);
create table t2 (a int, b int, c int, d decimal);
insert into t1 values
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
(7,11,708), (6,20,214);
insert into t2 values
(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
Warnings:
Note 1265 Data truncated for column 'd' at row 5
create table t1_double(a int, b double, c double);
insert into t1_double values
(1,23.4,14.3333), (1,12.5,18.9), (3,12.5,18.9),
(4,33.4,14.3333), (4,14.3333,13.65), (5,17.89,7.22),
(6,33.4,14.3), (10,33.4,13.65), (11,33.4,13.65);
create table t2_double(a int, b double, c double);
insert into t2_double values
(1,22.4,14.3333), (1,12.5,18.9), (2,22.4,18.9),
(4,33.4,14.3333), (5,22.4,13.65), (7,17.89,18.9),
(6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65);
create table t1_char(a char, b char(8), c int);
insert into t1_char values
('a','Ivan',1), ('b','Vika',2), ('b','Inga',6), ('c','Vika',7),
('b','Ivan',7), ('a','Alex',6), ('b','Inga',5), ('d','Ron',9),
('d','Harry',2), ('d','Hermione',3), ('c','Ivan',3), ('c','Harry',4);
create table t2_char(a char, b char(8), c int);
insert into t2_char values
('b','Ivan',1), ('c','Vinny',3), ('c','Inga',9), ('a','Vika',1),
('c','Ivan',2), ('b','Ali',6), ('c','Inga',2), ('a','Ron',9),
('d','Harry',1), ('b','Hermes',3), ('b','Ivan',11), ('b','Harry',4);
create table t1_decimal (a decimal(3,1), b decimal(3,1), c int);
insert into t1_decimal values
(1,1,23),(2,2,11),(3,3,16),
(1,1,12),(1,1,14),(2,3,15),
(2,1,13),(2,3,11),(3,3,16);
create table t2_decimal (a decimal(3,1), b decimal(3,1), c int);
insert into t2_decimal values
(2,1,13),(2,2,11),(3,3,16),
(1,3,22),(1,3,14),(2,2,15),
(2,1,43),(2,3,11),(2,3,16);
create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707;
create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
where t1.a>5 group by a,b having max_c < 707;
create view v3 as select a, b, min(c) as min_c from t1
where t1.a<10 group by a,b having min_c > 109;
create view v4 as
select a, b, min(max_c) as min_c from v1
where (v1.a<15) group by a,b;
create view v_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, max(c) as c from t1
where t1.b>10 group by a,b having c < 300;
create view v2_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, max(c) as c from t1
where t1.b>10 group by a,b having c < 300
union
select a, b, avg(c) as c from t1
where t1.c>300 group by a,b having c < 707;
create view v3_union as
select a, b, (a+1) as c from t1
where t1.a<10
union
select a, b, c from t1
where t1.b>10 and t1.c>100;
create view v4_union as
select a, b, max(c)-100 as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, (c+100) as c from t1
where t1.b>10;
create view v_double as
select a, avg(a/4) as avg_a, b, c from t1_double
where (b>12.2) group by b,c having (avg_a<22.333);
create view v_char as
select a, b, max(c) as max_c from t1_char
group by a,b having max_c < 9;
create view v_decimal as
select a, b, avg(c) as avg_c from t1_decimal
group by a,b having (avg_c>12);
# conjunctive subformula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 3 12 231 190
1 21 500 234.6000 6 23 303 909
6 20 315 279.3333 7 13 312 406
6 20 315 279.3333 8 64 248 107
6 20 315 279.3333 8 80 800 314
select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 3 12 231 190
1 21 500 234.6000 6 23 303 909
6 20 315 279.3333 7 13 312 406
6 20 315 279.3333 8 64 248 107
6 20 315 279.3333 8 80 800 314
explain select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.max_c > 214"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "t2.a > v1.a",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and max_c > 214",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
8 33 404 213.6667 8 64 248 107
6 20 315 279.3333 6 20 315 279
1 21 500 234.6000 1 19 203 107
8 33 404 213.6667 8 80 800 314
6 20 315 279.3333 6 23 303 909
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
8 33 404 213.6667 8 64 248 107
6 20 315 279.3333 6 20 315 279
1 21 500 234.6000 1 19 203 107
8 33 404 213.6667 8 80 800 314
6 20 315 279.3333 6 23 303 909
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 2 Using where
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100,
"attached_condition": "t2.a is not null"
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "5",
"used_key_parts": ["a"],
"ref": ["test.t2.a"],
"rows": 2,
"filtered": 100,
"attached_condition": "v1.max_c > 300",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and max_c > 300",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100
}
}
}
}
}
}
}
}
# extracted or formula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 3 12 231 190
1 21 500 234.6000 6 23 303 909
5 27 132 132.0000 2 3 207 207
5 27 132 132.0000 1 21 909 12
5 27 132 132.0000 1 19 203 107
5 27 132 132.0000 3 12 231 190
select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 3 12 231 190
1 21 500 234.6000 6 23 303 909
5 27 132 132.0000 2 3 207 207
5 27 132 132.0000 1 21 909 12
5 27 132 132.0000 1 19 203 107
5 27 132 132.0000 3 12 231 190
explain select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.max_c > 400 or v1.max_c < 135"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v1.max_c > 400 and t2.a > v1.a or v1.max_c < 135 and t2.a < v1.a",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and (max_c > 400 or max_c < 135)",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
1 19 107 107.0000 1 19 203 107
1 21 500 234.6000 1 21 909 12
6 20 315 279.3333 6 20 315 279
select * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
1 19 107 107.0000 1 19 203 107
1 21 500 234.6000 1 21 909 12
6 20 315 279.3333 6 20 315 279
explain select * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.max_c > 300 or v1.max_c < 135"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v1.b = t2.b and v1.max_c > 300 and v1.avg_c > t2.d or v1.a = t2.a and v1.max_c < 135 and v1.max_c < t2.c",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and (max_c > 300 or max_c < 135)",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100
}
}
}
}
}
}
}
}
# conjunctive subformula : pushing into WHERE
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
a b max_c avg_c a b c d
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
a b max_c avg_c a b c d
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
explain select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.a > 6"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "t2.b > v1.b",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a > 6"
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
a b max_c avg_c a b c d
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
a b max_c avg_c a b c d
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
explain select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v2.b > 25"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "t2.a < v2.a",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a > 5 and t1.b > 25"
}
}
}
}
}
}
}
}
# extracted or formula : pushing into WHERE
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
1 19 107 107.0000 7 13 312 406
1 19 107 107.0000 3 12 231 190
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 1 19 203 107
1 21 500 234.6000 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
1 19 107 107.0000 7 13 312 406
1 19 107 107.0000 3 12 231 190
1 21 500 234.6000 2 3 207 207
1 21 500 234.6000 7 13 312 406
1 21 500 234.6000 6 20 315 279
1 21 500 234.6000 1 19 203 107
1 21 500 234.6000 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
explain select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.a > 7 or v1.a < 2"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v1.a > 7 and t2.c < v1.max_c or v1.a < 2 and t2.b < v1.b",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a > 7 or t1.a < 2"
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
a b max_c avg_c a b c d
6 20 315 279.3333 2 3 207 207
6 20 315 279.3333 7 13 312 406
6 20 315 279.3333 1 19 203 107
6 20 315 279.3333 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
a b max_c avg_c a b c d
6 20 315 279.3333 2 3 207 207
6 20 315 279.3333 7 13 312 406
6 20 315 279.3333 1 19 203 107
6 20 315 279.3333 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
explain select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v2.a > 7 or v2.a > 5"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v2.a > 7 and t2.c < v2.max_c or v2.a > 5 and t2.b < v2.b",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a > 5 and (t1.a > 7 or t1.a > 5)"
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
a b max_c avg_c a b c d
1 19 107 107.0000 8 64 248 107
1 19 107 107.0000 1 19 203 107
5 16 207 207.0000 2 3 207 207
select * from v1,t2 where
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
a b max_c avg_c a b c d
1 19 107 107.0000 8 64 248 107
1 19 107 107.0000 1 19 203 107
5 16 207 207.0000 2 3 207 207
explain select * from v1,t2 where
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v1,t2 where
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.a > 4 or v1.a < 2"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v1.a > 4 and v1.b > t2.b and v1.max_c = t2.d or v1.a < 2 and v1.max_c < t2.c and v1.max_c = t2.d",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a > 4 or t1.a < 2"
}
}
}
}
}
}
}
}
# conjunctive subformulas : pushing into HAVING and WHERE
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
a b max_c avg_c a b c d
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 6 23 303 909
select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
a b max_c avg_c a b c d
1 21 500 234.6000 8 64 248 107
1 21 500 234.6000 8 80 800 314
1 21 500 234.6000 6 23 303 909
explain select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.a < 2 and v1.max_c > 400"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "t2.b > v1.b",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and max_c > 400",
"filesort": {
"sort_key": "t1.a, t1.b",
"temporary_table": {
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "t1.a < 2"
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_double as v,t2_double as t where
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
a avg_a b c a b c
1 0.50000000 12.5 18.9 1 22.4 14.3333
1 0.50000000 12.5 18.9 1 12.5 18.9
4 1.00000000 33.4 14.3333 4 33.4 14.3333
4 1.00000000 14.3333 13.65 4 33.4 14.3333
5 1.25000000 17.89 7.22 5 22.4 13.65
6 1.50000000 33.4 14.3 6 33.4 14.3333
10 2.62500000 33.4 13.65 10 31.4 13.65
select * from v_double as v,t2_double as t where
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
a avg_a b c a b c
1 0.50000000 12.5 18.9 1 22.4 14.3333
1 0.50000000 12.5 18.9 1 12.5 18.9
4 1.00000000 33.4 14.3333 4 33.4 14.3333
4 1.00000000 14.3333 13.65 4 33.4 14.3333
5 1.25000000 17.89 7.22 5 22.4 13.65
6 1.50000000 33.4 14.3 6 33.4 14.3333
10 2.62500000 33.4 13.65 10 31.4 13.65
explain select * from v_double as v,t2_double as t where
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t.a 2 Using where
2 DERIVED t1_double ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
explain format=json select * from v_double as v,t2_double as t where
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t",
"access_type": "ALL",
"rows": 9,
"filtered": 100,
"attached_condition": "t.a is not null"
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "5",
"used_key_parts": ["a"],
"ref": ["test.t.a"],
"rows": 2,
"filtered": 100,
"attached_condition": "v.avg_a > 0.45 and v.b > 10",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "avg_a < 22.333 and avg_a > 0.45",
"filesort": {
"sort_key": "t1_double.b, t1_double.c",
"temporary_table": {
"table": {
"table_name": "t1_double",
"access_type": "ALL",
"rows": 9,
"filtered": 100,
"attached_condition": "t1_double.b > 12.2 and t1_double.b > 10"
}
}
}
}
}
}
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_decimal as v,t2_decimal as t where
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
a b avg_c a b c
3.0 3.0 16.0000 3.0 3.0 16
select * from v_decimal as v,t2_decimal as t where
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
a b avg_c a b c
3.0 3.0 16.0000 3.0 3.0 16
explain select * from v_decimal as v,t2_decimal as t where
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
1 PRIMARY <derived2> ref key0 key0 3 test.t.a 2 Using where
2 DERIVED t1_decimal ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
explain format=json select * from v_decimal as v,t2_decimal as t where
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t",
"access_type": "ALL",
"rows": 9,
"filtered": 100,
"attached_condition": "t.a is not null"
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "3",
"used_key_parts": ["a"],
"ref": ["test.t.a"],
"rows": 2,
"filtered": 100,
"attached_condition": "v.avg_c > 15 and v.b > 1",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "avg_c > 12 and avg_c > 15",
"filesort": {
"sort_key": "t1_decimal.a, t1_decimal.b",
"temporary_table": {
"table": {
"table_name": "t1_decimal",
"access_type": "ALL",
"rows": 9,
"filtered": 100,
"attached_condition": "t1_decimal.b > 1"
}
}
}
}
}
}
}
}
# extracted or formula : pushing into HAVING and WHERE
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
1 19 107 107.0000 7 13 312 406
1 19 107 107.0000 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
select * from v1,t2 where
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
1 19 107 107.0000 7 13 312 406
1 19 107 107.0000 3 12 231 190
8 33 404 213.6667 2 3 207 207
8 33 404 213.6667 7 13 312 406
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 6 20 315 279
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
explain select * from v1,t2 where
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from v1,t2 where
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 9,
"filtered": 100
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 20,
"filtered": 100,
"attached_condition": "v1.a > 7 and v1.max_c > 300 or v1.a < 4 and v1.max_c < 500"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "v1.a > 7 and v1.max_c > 300 and t2.c < v1.max_c or v1.a < 4 and v1.max_c < 500 and t2.b < v1.b",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c < 707 and (t1.a > 7 and max_c > 300 or t1.a < 4 and max_c < 500)",