-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Support correlated subquery in UPDATE assignments (SET) #8286
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
550c167
9a08ffc
50fafb7
b227200
b7702a8
a1f1cf3
6db2338
093249d
06b408d
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.sql.analyzer; | ||
|
|
||
| public enum QueryType | ||
| { | ||
| DESCRIBE, | ||
| EXPLAIN, | ||
| OTHERS, | ||
| /**/; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,12 @@ | |
| import io.trino.sql.planner.PlanNodeIdAllocator; | ||
|
Praveen2112 marked this conversation as resolved.
Outdated
|
||
| import io.trino.sql.planner.SymbolAllocator; | ||
| import io.trino.sql.planner.TypeProvider; | ||
| import io.trino.sql.planner.plan.AssignUniqueId; | ||
| import io.trino.sql.planner.plan.DeleteNode; | ||
| import io.trino.sql.planner.plan.ExchangeNode; | ||
| import io.trino.sql.planner.plan.FilterNode; | ||
| import io.trino.sql.planner.plan.JoinNode; | ||
| import io.trino.sql.planner.plan.MarkDistinctNode; | ||
| import io.trino.sql.planner.plan.PlanNode; | ||
| import io.trino.sql.planner.plan.ProjectNode; | ||
| import io.trino.sql.planner.plan.SemiJoinNode; | ||
|
|
@@ -48,8 +50,8 @@ | |
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static com.google.common.collect.Iterables.getOnlyElement; | ||
| import static io.trino.sql.planner.optimizations.QueryCardinalityUtil.isAtMostScalar; | ||
| import static io.trino.sql.planner.plan.ChildReplacer.replaceChildren; | ||
| import static io.trino.sql.planner.planprinter.PlanPrinter.textLogicalPlan; | ||
| import static java.util.stream.Collectors.toSet; | ||
|
|
@@ -254,7 +256,9 @@ private WriterTarget createWriterTarget(WriterTarget target) | |
| private TableHandle findTableScanHandle(PlanNode node) | ||
| { | ||
| if (node instanceof TableScanNode) { | ||
| return ((TableScanNode) node).getTable(); | ||
| TableScanNode tableScanNode = (TableScanNode) node; | ||
| checkArgument(((TableScanNode) node).isUpdateTarget(), "TableScanNode should be an updatable target"); | ||
| return tableScanNode.getTable(); | ||
| } | ||
| if (node instanceof FilterNode) { | ||
| return findTableScanHandle(((FilterNode) node).getSource()); | ||
|
|
@@ -267,9 +271,13 @@ private TableHandle findTableScanHandle(PlanNode node) | |
| } | ||
| if (node instanceof JoinNode) { | ||
| JoinNode joinNode = (JoinNode) node; | ||
|
Praveen2112 marked this conversation as resolved.
Outdated
Praveen2112 marked this conversation as resolved.
Outdated
|
||
| if (joinNode.getType() == JoinNode.Type.INNER && isAtMostScalar(joinNode.getRight())) { | ||
|
Contributor
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. nit: I would love to see in the commit description why this check is no longer needed :)
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. 👍 Why this check is removed?
Member
Author
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. Now with support for correlated queries for assignment...we would translate them to a
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. moved to top level discussion @ #8286 (comment) |
||
| return findTableScanHandle(joinNode.getLeft()); | ||
| } | ||
| return findTableScanHandle(joinNode.getLeft()); | ||
| } | ||
| if (node instanceof AssignUniqueId) { | ||
| return findTableScanHandle(((AssignUniqueId) node).getSource()); | ||
| } | ||
| if (node instanceof MarkDistinctNode) { | ||
| return findTableScanHandle(((MarkDistinctNode) node).getSource()); | ||
| } | ||
| throw new IllegalArgumentException("Invalid descendant for DeleteNode or UpdateNode: " + node.getClass().getName()); | ||
| } | ||
|
|
@@ -303,11 +311,16 @@ private PlanNode rewriteModifyTableScan(PlanNode node, TableHandle handle) | |
| return replaceChildren(node, ImmutableList.of(source, ((SemiJoinNode) node).getFilteringSource())); | ||
| } | ||
| if (node instanceof JoinNode) { | ||
| JoinNode joinNode = (JoinNode) node; | ||
| if (joinNode.getType() == JoinNode.Type.INNER && isAtMostScalar(joinNode.getRight())) { | ||
| PlanNode source = rewriteModifyTableScan(joinNode.getLeft(), handle); | ||
| return replaceChildren(node, ImmutableList.of(source, joinNode.getRight())); | ||
| } | ||
| PlanNode source = rewriteModifyTableScan(((JoinNode) node).getLeft(), handle); | ||
| return replaceChildren(node, ImmutableList.of(source, ((JoinNode) node).getRight())); | ||
| } | ||
| if (node instanceof AssignUniqueId) { | ||
| PlanNode source = rewriteModifyTableScan(((AssignUniqueId) node).getSource(), handle); | ||
| return replaceChildren(node, ImmutableList.of(source)); | ||
| } | ||
| if (node instanceof MarkDistinctNode) { | ||
| PlanNode source = rewriteModifyTableScan(((MarkDistinctNode) node).getSource(), handle); | ||
| return replaceChildren(node, ImmutableList.of(source)); | ||
| } | ||
| throw new IllegalArgumentException("Invalid descendant for DeleteNode or UpdateNode: " + node.getClass().getName()); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,7 +230,7 @@ public ActualProperties visitAssignUniqueId(AssignUniqueId node, List<ActualProp | |
| } | ||
|
|
||
| return ActualProperties.builderFrom(properties) | ||
| .global(partitionedOn(ARBITRARY_DISTRIBUTION, ImmutableList.of(node.getIdColumn()), Optional.empty())) | ||
| .global(partitionedOn(ARBITRARY_DISTRIBUTION, ImmutableList.of(node.getIdColumn()), Optional.of(ImmutableList.of(node.getIdColumn())))) | ||
|
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. from cmt msg
I think that it doesn't matter how the ID is generated. please update the commit message. |
||
| .local(newLocalProperties.build()) | ||
| .build(); | ||
| } | ||
|
|
||
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.
This is used when creating a TableScanNode to set the
updateTargetflag. Is it intentional that after this change we set the flag totrueforANALYZE,CREATE MATERIALIZED VIEWetc., while before this change it was set only forUPDATEandDELETEqueries?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.
It will be still set only for
UPDATEandDELETEqueries - astargetTableis set only for those two types of queries andisUpdateTargetwill return false if thetargetTableisOptional#emptyThere 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.
Right.