Enable logical planning for UPDATE ... FROM and preserve joined assignment qualifiers#21530
Open
kosiew wants to merge 7 commits intoapache:mainfrom
Open
Enable logical planning for UPDATE ... FROM and preserve joined assignment qualifiers#21530kosiew wants to merge 7 commits intoapache:mainfrom
UPDATE ... FROM and preserve joined assignment qualifiers#21530kosiew wants to merge 7 commits intoapache:mainfrom
Conversation
Restore support for single-source UPDATE ... FROM in the planner by removing the rejection of early joined update plans. Move the safety block to the physical planner to ensure joined updates are safeguarded. Add test coverage for logical shapes and mock schemas, and update execution regression tests to confirm successful planning while maintaining fail-closed behavior.
Ensure EXPLAIN UPDATE ... FROM fails during SQL planning, instead of misleadingly passing to physical_plan_error. Maintain the physical-planner guard for direct execution failures. Update joined assignment extraction to preserve source references and avoid misclassifying columns in single-table updates. Add regression tests in sql_integration.rs and unit tests in physical_planner.rs.
Remove the EXPLAIN-time UPDATE ... FROM rejection in statement.rs to allow the SQL planner to expose the joined logical plan. Adjust regression test in sql_integration.rs to assert the Explain -> Dml(Update) plan shape. Consolidate duplicated projection-walking logic in physical_planner.rs by using a shared helper function for extract_update_assignments(). This simplifies identity-check and qualifier-normalization rules.
Adjust update.slt to ensure both EXPLAIN UPDATE ... FROM cases account for successful logical planning in addition to the existing physical-planner rejection. Align Utf8View cast with reports from sqllogictest in the filter for better consistency.
Update the alias collection logic to only traverse the update target branch, preventing self-join source aliases from being confused with target aliases. Add a regression test ensuring the correct assignment of src.a in the UPDATE statement for improved accuracy in query execution.
Consolidate duplicated joined-update and target-alias walks in physical_planner.rs by implementing a shared analyze_dml_input(...) helper. Update the filter and assignment extraction to utilize this common metadata. In sql_integration.rs, encapsulate the t1/t2 setup within a local UpdatePlanningContextProvider for new joined-update planner tests, eliminating unnecessary table names from the shared mock catalog in common/mod.rs.
Simplify physical planner by reusing DmlInputAnalysis and centralizing projection lookup. Streamline assignment extraction with iterators. Reduce duplication in SQL planning setup by introducing a shared helper and improve context provider to reuse stored schemas for efficiency. Enhance test scaffolding with shared update schema and new assertion utilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
UPDATE ...FROMbug #19950Rationale for this change
Previously,
UPDATE ... FROMstatements were rejected early in the SQL planner, preventing even valid single-target update cases from reaching logical planning. This blocked progress toward full support for joined updates and made it difficult to incrementally implement the feature.Additionally, the existing assignment extraction logic stripped column qualifiers unconditionally, which caused incorrect expressions when updates referenced joined sources (e.g.
SET t1.a = t2.b).This PR enables logical planning for
UPDATE ... FROMand introduces a more precise analysis of the input plan so that assignment expressions and filters are handled correctly depending on whether joins are present.What changes are included in this PR?
Planner enablement
UPDATE ... FROMin the SQL layer.Cross Join+Filter).Fail-closed physical planning
UPDATE ... FROM) until execution support is implemented.DML input analysis
Introduced
DmlInputAnalysisto:Added
analyze_dml_inputandanalyze_target_branchhelpers.Filter extraction improvements
Assignment extraction overhaul
Refactored assignment extraction into:
find_update_projectionappend_update_assignmentsextract_update_assignments_with_analysisPreserves qualifiers for joined-source expressions.
Strips qualifiers only for single-table updates to maintain provider compatibility.
Improved identity-assignment detection to respect table references.
SQL planning tests
Added logical plan tests verifying:
UPDATE ... FROMwith joinsEXPLAIN UPDATE ... FROMPhysical planner and DML tests
Updated tests to assert fail-closed behavior for joined updates.
Added coverage for:
t2.col)Are these changes tested?
Yes.
This PR adds and updates comprehensive test coverage across both SQL and physical planning layers:
Logical plan tests confirm that
UPDATE ... FROMis now accepted and produces the expected plan structure.Physical planner tests verify that execution still fails with a clear error (
UPDATE ... FROM is not supported).Unit tests validate assignment extraction behavior for:
These tests ensure both correctness and safe incremental rollout of the feature.
Are there any user-facing changes?
Yes.
UPDATE ... FROMis no longer rejected during SQL parsing/planning.Users can now run
EXPLAIN UPDATE ... FROMand inspect logical plans.Execution of such queries still fails with:
This provides improved visibility while maintaining safe behavior until full execution support is implemented.
LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.