-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: support UPDATE ... FROM #7841
Copy link
Copy link
Closed
Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-semanticsC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)X-anchored-telemetryThe issue number is anchored by telemetry references.The issue number is anchored by telemetry references.
Description
(edit @knz 2018-05-19)
UPDATE X SET ... = Y FROM Z
https://www.postgresql.org/docs/10/static/sql-update.html
performs (I think) a lateral join of X with Z and then makes the values computed by Z available for the scalar expressions in Y, to serve as values to update.
Full support for the feature needs support for correlated subqueries #3288 and lateral joins #24560.
Reduced support when the relational expression Z is uncorrelated (a common case) could perhaps be added with a simple join, although additional execution machinery is still needed to propagate the PK prefixes for the X operand to the join through up to the point UPDATE can pick them up.
As to which rows get updated:
- Rows of table X that don't match in the join are not updated.
- Rows that match in X with the join on Z are updated. If there is just 1 matching row (or if there is a cross join but the right operand has just 1 row), then the situation is clear. I am not exactly sure what happens if there are multiple rows.
The work to be done is twofold:
- construct (and properly optimize) the data source with a join when FROM is specified
- plumb the PK values properly so that UPDATE still has PKs to work with.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-semanticsC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)X-anchored-telemetryThe issue number is anchored by telemetry references.The issue number is anchored by telemetry references.