Skip to content

fix(plan): fallback UPDATE generated-column correctness (follow-up #24536) - #24600

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
ck89119:fix-23137-fallback-gencol
May 28, 2026
Merged

fix(plan): fallback UPDATE generated-column correctness (follow-up #24536)#24600
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
ck89119:fix-23137-fallback-gencol

Conversation

@ck89119

@ck89119 ck89119 commented May 26, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23137

What this PR does / why we need it:

Follow-up correctness fixes for PostgreSQL-style UPDATE ... SET ... FROM ... WHERE fallback planning, completing #24536 (already merged to main).

These two fixes were added during review of the 4.0-dev backport (#24562) but were missing on main:

  • keep fallback update generated columns contiguous (892d892b3): generated-column recompute expressions are inserted into the current target table's contiguous update segment instead of being appended after all targets, so later targets in a multi-target fallback UPDATE no longer read/write wrong projection positions.
  • recompute fallback generated columns after rewrites (988c01bbb): the fallback generated-column recompute now runs after rewriteUpdateQueryLastNode(), so DEFAULT / ON UPDATE rewrites are visible before generated expressions are derived; the generated-column lookup is mutable so generated-on-generated chains use freshly recomputed earlier expressions.

Added planner coverage for the multi-target fallback + generated-column case, and for fallback generated columns over DEFAULT, ON UPDATE, and generated-on-generated chains.

@ck89119
ck89119 requested review from aunjgr and ouyuanning as code owners May 26, 2026 07:00
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

The fallback UPDATE planner change keeps generated-column projections contiguous after rewrite and now recomputes them from the rewritten source expressions, so DEFAULT / ON UPDATE / chained generated-column cases stay correct. The new planner tests cover the risky cases.

@XuPeng-SH
XuPeng-SH merged commit 7ff125d into matrixorigin:main May 28, 2026
1 of 4 checks passed
@ck89119
ck89119 deleted the fix-23137-fallback-gencol branch May 28, 2026 12:04
ck89119 added a commit to ck89119/matrixone that referenced this pull request Jun 1, 2026
The fallback UPDATE rewrite builds the inner SELECT projection by ranging
the usedTbl map to order target tables (build_constraint_util.go), so for a
multi-table UPDATE the table order followed Go's randomized map iteration.
rewriteGeneratedColumnsForUpdate derives projection offsets (tableBase /
baseLookup) from that order, so ~50% of runs the generated-column
substitution resolved the wrong base column, producing a flaky/incorrect
plan (intermittently failing TestUpdateFallbackGeneratedColumns* added in
matrixorigin#24600).

Port the deterministic ordering already on 4.0-dev: iterate aliases in
their original declaration order via orderedDmlAliases() instead of ranging
the map. No behavior change beyond determinism.

Verified: go test ./pkg/sql/plan -run 'TestUpdateFallback' -count=300 now
passes 300/300 (previously failed intermittently); full pkg/sql/plan green;
make static-check clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants