Package org.apache.calcite.sql2rel
Class TopDownGeneralDecorrelator
java.lang.Object
org.apache.calcite.sql2rel.TopDownGeneralDecorrelator
- All Implemented Interfaces:
ReflectiveVisitor
A top‑down, generic decorrelation algorithm that can handle deep nestings of correlated
subqueries and that generalizes to complex query constructs. More details are in paper:
Improving Unnesting of Complex Queries. It's an improved version of the paper:
Unnesting Arbitrary Queries.
Usage notes for TopDownGeneralDecorrelator:
TopDownGeneralDecorrelator is not yet integrated into other modules and needs to be called
separately. If you want to use it to replace RelDecorrelator, we recommend:
- When generating the initial plan by
SqlToRelConverter, do not remove subqueries and do not enable decorrelation. - Build a
HepPlannerand apply rules for removing subqueries to the initial plan. With subqueries removed correctly, TopDownGeneralDecorrelator can in theory eliminate all correlation. We recommend usingCoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATEandCoreRules.PROJECT_SUB_QUERY_TO_MARK_CORRELATEto remove subqueries from Filter and Project. These rules produce LEFT MARK Join/Correlate which are better suited for TopDownGeneralDecorrelator. There is not yet a corresponding, specially tailored rule for Join; you may choose to useCoreRules.JOIN_SUB_QUERY_TO_CORRELATE. Alternatively, for greater stability, you can run TopDownGeneralDecorrelator first and then applyCoreRules.JOIN_SUB_QUERY_TO_CORRELATEtogether withRelDecorrelator. - Call
decorrelateQuery(RelNode, RelBuilder)to obtain the decorrelated plan. - Continue with other optimizations.
See
org.apache.calcite.test.RelOptRulesTest#testTopDownGeneralDecorrelateForFilterExists()
and org.apache.calcite.test.RelOptFixture#checkPlanning(boolean) for
working examples.
-
Method Summary
Modifier and TypeMethodDescriptionstatic TopDownGeneralDecorrelatorcreateEmptyDecorrelator(RelBuilder builder) static RelNodedecorrelateQuery(RelNode rel, RelBuilder builder) Decorrelates a query.unnestInternal(Aggregate aggregate, boolean allowEmptyOutputFromRewrite) unnestInternal(Correlate correlate, boolean allowEmptyOutputFromRewrite) unnestInternal(Filter filter, boolean allowEmptyOutputFromRewrite) unnestInternal(Join join, boolean allowEmptyOutputFromRewrite) unnestInternal(Project project, boolean allowEmptyOutputFromRewrite) unnestInternal(SetOp setOp, boolean allowEmptyOutputFromRewrite) unnestInternal(Sort sort, boolean allowEmptyOutputFromRewrite) unnestInternal(RelNode other, boolean allowEmptyOutputFromRewrite)
-
Method Details
-
createEmptyDecorrelator
-
decorrelateQuery
Decorrelates a query. This is the entry point for this class.- Parameters:
rel- Root node of the querybuilder- RelBuilder- Returns:
- Equivalent node without correlation
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
unnestInternal
-
getVisitor
-