Skip to content

fix(plan): resolve view sequences in stored database - #28116

Merged
XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-27581
Sep 7, 2026
Merged

XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-27581

Conversation

@jiangxinmeng1

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 #27581

What this PR does / why we need it:

Fix sequence-backed views to resolve NEXTVAL and CURRVAL using the database where the view
was created, rather than the caller’s current database. The database is passed as an internal
execution argument without changing the public SQL function signatures. Added planner unit
tests and distributed regression coverage for both functions.

@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 →

@aptend aptend 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.

Deep review completed at exact head 58bfad3355ccdf6c08dbcf0793b41804baa5691d against base/merge-base 99ed717b769e261b842c2f17345bd65865fc1470. There were no prior reviews or inline threads. I traced view expansion, hidden-overload binding, vector execution, database/relation lookup, and session sequence state across the full six-file diff.

The hidden database argument correctly fixes NEXTVAL and CURRVAL, preserves their one-argument SQL surface, and the committed cross-database regression covers both plus an ordinary-view control. One sibling sequence operation still follows the broken caller-database path and can mutate the wrong sequence, so this head needs changes before approval.

Validation with the repository-required CGO and locally built third-party artifacts: full go test ./pkg/sql/plan ./pkg/sql/plan/function -count=1; the new planner tests repeated 20 times; go vet for both packages; git diff --check; and a conflict-free merge tree against current origin/main. A review-only planner counterexample for SETVAL failed deterministically because the stored database argument was absent, and it was removed afterward. The SCA job failed in actions/checkout before analysis; other completed substantive checks are green, while UT and one BVT job remain in progress.

Comment thread pkg/sql/plan/base_binder.go Resolved

@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.

Review of commit bbe83f2bb5d4c50a3abae86a545bb22d8bdb462c.

No blocking finding in the reviewed change. The hidden database argument preserves the view's stored database for NEXTVAL/CURRVAL/SETVAL without splitting sequence names containing dots. Public arity guards and SETVAL overload normalization preserve existing calls; tests cover same-named sequences in the caller and view databases.

Evidence: source review and existing passing CI for this commit; no new local test run was performed for this review.

@XuPeng-SH XuPeng-SH 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.

Reviewed head bbe83f2bb5d4c50a3abae86a545bb22d8bdb462c against base/merge-base 845fff8ee9cac962c5002a1007e0b0180efd591b. No blocking finding remains in the nine-file change.

Previous review closure:

  • My CURRVAL performance finding is fixed: database handlers are cached by effective database within the batch. The four-row test expects exactly one Engine.Database call and verifies all four results.
  • Both my and aptend's window-regression findings are fixed: the base-to-head query_builder_test.go diff is now additive; the stronger direct-CHAR/RANGE/helper coverage is retained.
  • Aptend's earlier SETVAL finding is fixed: both public arities normalize to the stored-database internal overload, and the cross-database BVT checks that the caller's same-named sequence is not changed. The old review comments remain in GitHub history, but their cited code defects are resolved in this head.

I traced view-context inheritance into the hidden argument and NEXTVAL/CURRVAL/SETVAL execution, relation lookup, SQL updates, and table-ID-keyed session state. Public arities stay closed, dotted sequence names remain intact, and database/relation failures propagate. The cache is batch-local and introduces no shared lock, goroutine, or cross-transaction retained handle. The ordinary CURRVAL path adds a small map lookup per row but avoids the previously introduced per-row database resolution.

Evidence: complete diff/source review; current-head Ubuntu UT, SCA and both substantive multi-CN BVT checks are green; git diff --check passes. Existing CI evidence was reused, with no new local native execution. Approval expresses my independent conclusion and does not dismiss another reviewer's GitHub review state.

@XuPeng-SH
XuPeng-SH merged commit bcd5ed8 into matrixorigin:main Sep 7, 2026
15 of 18 checks passed

This branch was previously deployed

1 inactive deployment
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.

6 participants