Skip to content

fix(sequence): validate bounds and honor identifier case policy - #32187

Open
aptend wants to merge 4 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-31908-31909
Open

aptend wants to merge 4 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-31908-31909

Conversation

@aptend

@aptend aptend commented Nov 4, 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:

Fixes #31908
Fixes #31909

What this PR does / why we need it:

Reject explicit sequence START/MINVALUE/MAXVALUE literals outside the declared signed or unsigned integer type before narrowing them. Errors retain the original value, rejected CREATE leaves no sequence, and rejected ALTER preserves the stored row and issued position. The six supported integer domains are covered; INCREMENT retains its existing int64 contract.

Resolve NEXTVAL/CURRVAL/SETVAL string arguments with the same case policy as CREATE SEQUENCE: mode 1 folds names, while modes 0 and 2 preserve their spelling. Sequence-owned internal SQL executes already-resolved physical identifiers without folding them again in mode 2, closing the real allocation UPDATE failure reported in review 5776394217. This is limited to the sequence executor environment; allocation identity, generation fences, permissions, caller/autonomous transaction ownership and session caches retain their existing behavior.

Update the legacy SMALLINT MAXVALUE 9999999 golden error to report the original out-of-domain value instead of a silently wrapped MAXVALUE -27009. The abnormal SQL statement remains in the comparison suite.

Validation:

  • Independently reviewed the complete 13-file diff, CREATE/ALTER range guards and rejection paths, actual NEXT/CURR/SET relation resolution and generated allocation SQL, and the shared branch-reconciliation consumer of the sequence executor environment. No global identifier/compiler policy change is included.
  • Matching CGO/native mo-cgo-test runs used explicit named sequence roots with real failing-before/passing-after evidence. Lookup mode 2 originally requested the wrong lowercase relation; the internal executor regression originally observed policy 2 instead of the required preserved policy 0. Both controls failed with original rc 1 and the matching focused runs passed with original rc 0; these were nonzero selections, not full-package or verbose event-count claims.
  • Actual public SQL with the matching mode-2 allocation binary covered fresh-session policies 1, 2 and 0. Mode 2 preserved MySeq and produced NEXT 1,2 / CURR 2 / SET 10 / NEXT 11; wrong-case and missing sequences returned 1146/42S02 and an ordinary relation returned 20101/HY000. One session continued through wrong-case and uninitialized-CURRVAL errors to NEXT 12. Mode 1 stored myseqb; mode 0 preserved MySeqZ. Global policy restoration to 1 was checked from a fresh session.
  • That runtime's actual source was d174baec70313885563112481025a2bc0a8ad5fd on base 692c8e1 with the reviewed changes present (vcs.modified=true). Service SHA-256: 059d9bad044bc3d4b1ceb2ea181a58df2b1511cb9a2b752d5d20b51df7e2aa91; rebuilt native libmo.so: 9bfae6e28fe57b30d9db4a3901d14aaec8fc91452841e466c326b93d3211b164. The earlier normal sequence-directory comparison passed 958/958 at its recorded 83907d source and 6cbefbeabde8c0a2bc0934089f77f61c88418be4470f250465c167ff2b93c6ae service; it remains evidence for unchanged type-bound/mode-1 paths, not a new mode-2 or latest-base run.
  • The foreground runtime retained ISCP readiness, exact service/CLI ancestry and executable identity, private effective HK/raft/seed/JDBC targets and complete pre-SQL TCP/all-state UDP captures. Root raw inspection found 12 owned TCP listeners, 2 UDP-UNCONN endpoints and 228 owned established connections; 48 pre-run pidless TIME-WAIT rows were disclosed. Normal cleanup had original SQL rc 0, residue 0, original-parent wait 0 and no owned process/active private socket remaining. Separate minimal helper fault witnesses cover bounded original-parent reaping, admission failure with zero SQL, unavailable post-socket audit and invalid restore-policy verdicts; injected observations are distinguished from real process exits. Earlier unsuccessful harness attempts remain in the evidence.
  • Linearly rebased onto official main d630ed1. All 13 product-file hashes are unchanged across the disjoint collation integration, so the identified functional evidence is reused without relabelling its source or binary. On this final source, the repository-pinned full-graph SCA fallback covered changed packages, tests and reverse consumers: make config; make err-check; molint check -mod=readonly ./...; license-eye -c .licenserc.yml header check; license-eye -c .licenserc.yml dep check; golangci-lint run -v -c .golangci.yml ./.... All six immediate original return codes were 0, with 0 final issues and 0 invalid license headers. Tool identities: golangci-lint 2.14.0, molint 35bd4d9a4055, license-eye 0.4.0; repository configuration and CGO/native prerequisites were preserved.

CI and the requested re-review are pending on the new HEAD. Local validation does not claim predecessor-binary migration or multi-CN coverage.

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

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Nov 4, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Nov 4, 2026
@aptend
aptend force-pushed the fix/astra-meow-31908-31909 branch from 9015951 to 4c4323b Compare November 4, 2026 20:27
@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4c4323b55476267ca7a6b2cb256a8d8152759644

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 4c4323b55476267ca7a6b2cb256a8d8152759644

Assessment: request_changes

The shared conversion helper correctly centralizes bounds validation without new state. Name resolution has a mode-2 regression: CREATE preserves spelling, but the new helper lowercases it.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/sql/plan/function/seqfunc.go:341: A session using lower_case_table_names=2 creates MySeq and then calls nextval('MySeq'), currval('MySeq') or setval('MySeq', ...).
    Impact: CREATE stores MySeq, but this helper requests myseq, so the functions cannot resolve the created mixed-case sequence. Match CREATE's mode-1-only folding and correct the new mode-2 test expectation.
    Evidence: mysql_lexer.go:642 GetDbOrTblName folds only mode 1; the table_name grammar and buildCreateSequence retain its result. Catalog lookup compares names exactly (cache/catalog.go:500). The component probe reproduces MySeq versus myseq in mode 2, while modes 0/1 agree. sequence_relation_name_policy_test.go:52 asserts the incorrect lowercase result. Evidence: mode-two-source-proof.json and case-policy-probe.jsonl.

Validation:

  • Reviewed all 10 changed paths, both discussion entries and linked issues #31908/#31909; traced DDL rollback and relation/session identity.

  • Preflight passed: checks/1793828542927548911-2.json; preflight.log.

  • Range helpers passed 18,720 independent math/big comparisons and baseline controls: checks/1793828623125360417-2.json; sequence-range-probe.jsonl.

  • Policy probe reproduced the mode-2 mismatch: checks/1793829032993920439-2.json; case-policy-probe.jsonl.

  • Source/fixture audit passed, including 38+17 SQL/result statements and the corrected legacy golden: checks/1793828795570654656-2.json; source-audit-v2.log. Reconciliation: validation-evidence.json.

  • Frozen-head CI reports successful build, unit tests, SCA and multi-CN BVT.

Limitations:

  • Local probes use extracted production bodies with documented harness adaptations; full native packages and public SQL suites were not rerun locally.

  • Detailed author logs were not supplied; reported package and 958-statement BVT runs carry older-base labels.

  • INCREMENT semantics remain unchanged; the bounds fix covers START/MINVALUE/MAXVALUE.

@aptend
aptend requested a review from XuPeng-SH November 5, 2026 00:41
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Nov 5, 2026
@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4ecca8ecdc6c8867d01279c7cef1c9600c10edcc

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 4ecca8ecdc6c8867d01279c7cef1c9600c10edcc

Assessment: approve

Shared validation correctly rejects out-of-domain START/MIN/MAX values, and sequence lookup plus internal SQL now follow CREATE's identifier policy. The prior mode-2 finding is resolved; no actionable correctness or design findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 13 changed files, affected consumers, four discussion entries and both linked issues.

  • Extracted production helpers passed 12,648 independent math/big comparisons using Go 1.26.6; range-probe.log and checks/1793862414202087910-2.json.

  • Source audit passed: clean head, diff/gofmt checks and 55 SQL/result statements; source-audit.log and checks/1793862571019366748-2.json.

  • Reused supplied exact-head UT, static analysis, coverage and both BVT successes; author SQL evidence retains its reported source/binary labels.

Limitations:

  • Go 1.27.1 bootstrap timed out. Local execution covered extracted helpers, not native packages or public SQL; those checks rely on supplied CI and attributed author evidence.

@mergify mergify Bot added the queued label Nov 5, 2026
@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🟠 Testing · estimated merge 10:27 UTC

Waiting for

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Queue rule main · 1 of 8 no longer met

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

So far

  • ✅ Entered the queue Thu 5 Nov, 07:13 · rule main · triggered by rule Automatic queue on approval for main
  • 🟠 Testing · in place
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
Queue rule main: 7 of 8 queue conditions still met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • -closed
  • -conflict
  • -draft
  • any of:
    • -mergify-configuration-changed
    • check-success = @mergify/Configuration changed
    • check-success = @mergify/Configuration has been deleted
  • any of:
    • check-neutral = @mergify/Mergify Merge Protections
    • check-skipped = @mergify/Mergify Merge Protections
    • check-success = @mergify/Mergify Merge Protections

Times in UTC · dashboard · how the merge queue works

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 kind/test-ci queued size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

3 participants