-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Push update to connector (All jdbc) #16445
Push update to connector (All jdbc) #16445
Conversation
4a887e3
to
d538664
Compare
Implemented for Postgres to prove that full flow works, |
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.
Approach looks good to me. Add tests like the ones related to io.trino.testing.TestingConnectorBehavior#SUPPORTS_DELETE
/** | ||
* Push update into connector | ||
*/ | ||
Optional<TableHandle> applyUpdate(Session session, TableHandle tableHandle); |
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.
Don't we need assignments here? I think there could be a case where predicate is easy and assignments are complex to be pushed down. Is this handled somewhere else?
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.
As far as I understand this code executed only in PushMergeWriterUpdateIntoConnector rule, where we catch only concrete node plan for simple cases. So in case of complex assignment like Update with Select, we never fall here.
And flow will fail on beginMerge
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.
Updates cannot be pushed into a regular table scan. They have fundamentally different semantics -- scans are side-effect-free, while updates have side effects. This is important for retries and transactionality.
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.
We are already doing this for DELETE.
UPDATE, like DELETE, has side effects but it is idempotent operation (as long query is deterministic). It sounds like a good idea that we should not push down DELETE and UPDATE if they are not deterministic.
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.
What's the decision here?
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.
I think the update(value is deterministic) can be retry as long as the condition is not involved in the update assignments.
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.
Updates cannot be pushed into a regular table scan.
@martint notice that we are pushing update into TableUpdateNode
, then have dedicated operator that executes the update operation. So there is no table scan here.
core/trino-main/src/main/java/io/trino/sql/planner/PlanOptimizers.java
Outdated
Show resolved
Hide resolved
plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlMetadata.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/optimizations/StreamPropertyDerivations.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
a1b30bc
to
155293a
Compare
Consider expression translation for parsing assignment:
|
10c6926
to
e71a212
Compare
c71dc9e
to
ecead73
Compare
/** | ||
* Push update into connector | ||
*/ | ||
Optional<TableHandle> applyUpdate(Session session, TableHandle tableHandle); |
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.
Updates cannot be pushed into a regular table scan. They have fundamentally different semantics -- scans are side-effect-free, while updates have side effects. This is important for retries and transactionality.
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.
Very nice job. Only some doubts here, and one more question: I saw the modification in the fte tests, does it mean we can support fte on Update
after this merged?
...ino-postgresql/src/test/java/io/trino/plugin/postgresql/BasePostgresFailureRecoveryTest.java
Outdated
Show resolved
Hide resolved
...n/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java
Outdated
Show resolved
Hide resolved
...n/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
to be honest didn't get it, can you please describe it more |
core/trino-main/src/main/java/io/trino/operator/TableDeleteOperator.java
Outdated
Show resolved
Hide resolved
82d3e26
to
3fe2ed2
Compare
core/trino-main/src/main/java/io/trino/operator/TableMetadataOperator.java
Outdated
Show resolved
Hide resolved
3fe2ed2
to
a7dd36e
Compare
core/trino-main/src/main/java/io/trino/operator/TableDeleteOperator.java
Outdated
Show resolved
Hide resolved
a7dd36e
to
ceb991b
Compare
core/trino-main/src/main/java/io/trino/operator/TableUpdateOperator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/TableMetadataOperator.java
Outdated
Show resolved
Hide resolved
978c319
to
8ec6987
Compare
core/trino-main/src/main/java/io/trino/operator/TableMutationOperator.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushMergeWriterUpdateIntoConnector.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/plan/TableDeleteNode.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorMetadata.java
Outdated
Show resolved
Hide resolved
c99b853
to
c61f578
Compare
c61f578
to
57cd7af
Compare
The engine level changes look good now
Merged. Thank you @vlad-lyutenko for the change and thank you @martint for code review! |
@vlad-lyutenko Can you please update the PR description and suggest the release notes. Please mention explicitly which connectors are now able to support simple UPDATE statements. |
Description
Introduce push update for jdbc connectors in the same way as delete.
So it's kind of shorthand path, where we catch some specific execution plan.
And only if it's match and it's simple we fire the direct connector call,
omitting global update/merge logic.
In initial version it has some limitations like:
Supported connectors:
Additional context and related issues
Release notes
(x) Release notes are required, with the following suggested text:
Add limited support for UPDATE statement. Only UPDATE with constant assignments and predicates is supported today like
UPDATE table SET col1 = 'abc' WHERE col2 = 3
Supported predicates :
This version has some limitations like:
Supported connectors: