Commit bc4fe93
committed
Move PullupCorrelatedPredicates and RewritePredicateSubquery after OptimizeSubqueries
This commit moves two rules right next to the rule OptimizeSubqueries.
1. PullupCorrelatedPredicates:
the rewrite of [Not] Exists and [Not] In (ListQuery) to PredicateSubquery
2. RewritePredicateSubquery:
the rewrite of PredicateSubquery to LeftSemi/LeftAnti
With this change, [Not] Exists/In subquery is now rewritten to LeftSemi/LeftAnti
at the beginning of Optimizer.
By moving rule PullupCorrelatedPredicates after rule OptimizerSubqueries, all
the rules from the nested call to the entire Optimizer on the plans in subqueries
will need to deal with (1). the correlated columns wrapped with OuterReference,
and (2) the SubqueryExpression.
We will block any push down of both types of expressions for the following reasons:
1. We do not want to push any correlated expressions further down the plan tree.
Deep correlation is not yet supported in Spark, and, even when supported,
deep correlation is more difficult to be unnested to a join.
2. We do not want to push any correlated subquery down because the correlated
columns' ExprIds in the subquery may need to remap to different ExprIds from
the plan below the current Filter that hosts the subquery.
Another side effect is we used to push down Exists/In subquery as if it is a
predicate in rule PushDownPredicate and rule PushPredicateThroughJoin. Now
Exists/In subquery is rewritten to LeftSemi/LeftAnti, we need to handle
the push down of LeftSemi/LeftAnti instead. This will be done in a followup
commit.
Another Todo is to merge the two-stage rewrite in rule PullupCorrelatedPredicates
and rule RewritePredicateSubquery into a single stage rewrite.1 parent 9e1c18c commit bc4fe93
File tree
3 files changed
+40
-33
lines changed- sql/catalyst/src
- main/scala/org/apache/spark/sql/catalyst/optimizer
- test/scala/org/apache/spark/sql/catalyst/optimizer
3 files changed
+40
-33
lines changedLines changed: 31 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | 71 | | |
74 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 133 | + | |
137 | 134 | | |
138 | 135 | | |
139 | 136 | | |
| |||
746 | 743 | | |
747 | 744 | | |
748 | 745 | | |
749 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
750 | 749 | | |
751 | 750 | | |
752 | 751 | | |
| |||
769 | 768 | | |
770 | 769 | | |
771 | 770 | | |
772 | | - | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
773 | 774 | | |
774 | 775 | | |
775 | 776 | | |
| |||
797 | 798 | | |
798 | 799 | | |
799 | 800 | | |
800 | | - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
801 | 804 | | |
802 | 805 | | |
803 | 806 | | |
| |||
815 | 818 | | |
816 | 819 | | |
817 | 820 | | |
818 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
819 | 829 | | |
820 | 830 | | |
821 | 831 | | |
| |||
839 | 849 | | |
840 | 850 | | |
841 | 851 | | |
842 | | - | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
843 | 855 | | |
844 | 856 | | |
845 | 857 | | |
| |||
887 | 899 | | |
888 | 900 | | |
889 | 901 | | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | 902 | | |
905 | 903 | | |
906 | 904 | | |
| |||
927 | 925 | | |
928 | 926 | | |
929 | 927 | | |
930 | | - | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
931 | 933 | | |
932 | 934 | | |
933 | 935 | | |
934 | 936 | | |
935 | 937 | | |
936 | | - | |
| 938 | + | |
| 939 | + | |
937 | 940 | | |
938 | 941 | | |
939 | 942 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
449 | 453 | | |
450 | 454 | | |
451 | 455 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
799 | 799 | | |
800 | 800 | | |
801 | 801 | | |
802 | | - | |
| 802 | + | |
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
812 | | - | |
813 | 812 | | |
| 813 | + | |
814 | 814 | | |
815 | 815 | | |
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
819 | | - | |
| 819 | + | |
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
831 | | - | |
832 | 831 | | |
833 | 832 | | |
| 833 | + | |
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
| |||
0 commit comments