-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix prune output rules for intersect and except nodes #21343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -790,33 +790,33 @@ public PlanNode visitDelete(DeleteNode node, RewriteContext<Set<VariableReferenc | |
| @Override | ||
| public PlanNode visitUnion(UnionNode node, RewriteContext<Set<VariableReferenceExpression>> context) | ||
| { | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context); | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context, true); | ||
| ImmutableList<PlanNode> rewrittenSubPlans = rewriteSetOperationSubPlans(node, context, rewrittenVariableMapping); | ||
| return new UnionNode(node.getSourceLocation(), node.getId(), node.getStatsEquivalentPlanNode(), rewrittenSubPlans, ImmutableList.copyOf(rewrittenVariableMapping.keySet()), fromListMultimap(rewrittenVariableMapping)); | ||
| } | ||
|
|
||
| @Override | ||
| public PlanNode visitIntersect(IntersectNode node, RewriteContext<Set<VariableReferenceExpression>> context) | ||
| { | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context); | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context, false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way we can also do is like this Basically add intersects output as expectedInputs and refactor rewriteSetOperationVariableMapping function to take Set as the input. I think this is more in line logically with this optimizer. |
||
| ImmutableList<PlanNode> rewrittenSubPlans = rewriteSetOperationSubPlans(node, context, rewrittenVariableMapping); | ||
| return new IntersectNode(node.getSourceLocation(), node.getId(), node.getStatsEquivalentPlanNode(), rewrittenSubPlans, ImmutableList.copyOf(rewrittenVariableMapping.keySet()), fromListMultimap(rewrittenVariableMapping)); | ||
| } | ||
|
|
||
| @Override | ||
| public PlanNode visitExcept(ExceptNode node, RewriteContext<Set<VariableReferenceExpression>> context) | ||
| { | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context); | ||
| ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMapping = rewriteSetOperationVariableMapping(node, context, false); | ||
| ImmutableList<PlanNode> rewrittenSubPlans = rewriteSetOperationSubPlans(node, context, rewrittenVariableMapping); | ||
| return new ExceptNode(node.getSourceLocation(), node.getId(), node.getStatsEquivalentPlanNode(), rewrittenSubPlans, ImmutableList.copyOf(rewrittenVariableMapping.keySet()), fromListMultimap(rewrittenVariableMapping)); | ||
| } | ||
|
|
||
| private ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewriteSetOperationVariableMapping(SetOperationNode node, RewriteContext<Set<VariableReferenceExpression>> context) | ||
| private ListMultimap<VariableReferenceExpression, VariableReferenceExpression> rewriteSetOperationVariableMapping(SetOperationNode node, RewriteContext<Set<VariableReferenceExpression>> context, boolean pruneUnreferencedOutput) | ||
| { | ||
| // Find out which output variables we need to keep | ||
| ImmutableListMultimap.Builder<VariableReferenceExpression, VariableReferenceExpression> rewrittenVariableMappingBuilder = ImmutableListMultimap.builder(); | ||
| for (VariableReferenceExpression variable : node.getOutputVariables()) { | ||
| if (context.get().contains(variable)) { | ||
| if (context.get().contains(variable) || !pruneUnreferencedOutput) { | ||
| rewrittenVariableMappingBuilder.putAll( | ||
| variable, | ||
| node.getVariableMapping().get(variable)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit- The method is called rewriteSetOperationVariableMapping, so Instead of changing the method to not prune, can we use inline and exit early where it should be false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewriteSetOperationVariableMappingis doing two things, 1) prune variables 2) rewrite Map<Variable, List> to ListMultimap<Variable, Variable>. For the intersect and except node, it does not need to be pruned. Ideally we do not even need to rewrite to ListMultimap here, however it needs to change functionrewriteSetOperationSubPlansas well, which seems too much change for this fix. After some thought I found the current way to be with minimum change in code and more direct in intention, i.e. skip pruning for these two nodes.