-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Simplify planning of MERGE #23684
Simplify planning of MERGE #23684
Conversation
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 looked good to me and it looks like all the CI tests pass. I wondered why the first test in TestDeleteAndInsertMergeProcessor
was removed.
core/trino-main/src/test/java/io/trino/sql/planner/TestDeleteAndInsertMergeProcessor.java
Outdated
Show resolved
Hide resolved
965e345
to
ca494af
Compare
Hi, I tried this PR and it seems to help with one of the tables I was having trouble MERGING, thank you! |
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.
Looks good, I only have questions for my own understanding.
We used to use the synthetic value as a "marker" to signal what operation to do.
Now we rely on the fact that the table scan will not produce a tuple with the value CAST(null AS row(columns..., c1 boolean, c2 tinyint, c3 integer))
ever? Why is this assumption true? Is it true because there will never be a column in the table whose type matches the row we have created?
Or do I misunderstand something?
whenClauses.build(), | ||
new Constant( | ||
RowType.anonymous(ImmutableList.<Type>builder() | ||
.addAll(dataColumnSchemas.stream().map(ColumnSchema::getType).collect(Collectors.toList())) |
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: static import toList
The columns from the table scan are wrapped in a ROW(...) with some additional fields by a synthetic projection in the plan that handles the branches of the MERGE statement. The row is then consumed by the merge processor to decide if a row is being inserted or deleted. In one of the cases, we were producing a row that was meant to be ignored by the merge processor (i.e., when none of the MERGE branches matched). |
Currently, the planner inserts a projection of the following shape to assemble the merged row: merge_row := ( CASE WHEN ... THEN ROW(..., $not((present IS NULL)), <operation>, 0) WHEN ... THEN ROW(..., $not((present IS NULL)), <operation>, 1) ... ELSE ROW(<nulls>, $not((present IS NULL)), -1, -1) END) This change replaces the ELSE branch to return a single null instead of a synthetic value with nulls. By reducing the size of the projection, it allows for wider tables to be used with MERGE.
ca494af
to
c0d70e6
Compare
Currently, the planner inserts a projection of the following shape to assemble the merged row:
This change replaces the ELSE branch to return a single null instead of a synthetic value with nulls. By reducing the size of the projection, it allows for wider tables to be used with MERGE.
Related to #15848
Release notes
(x) No release notes needed