Skip to content

[4.2-dev] fix(frontend): preserve SQL source through policy rewrite - #29605

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/backport-29600-4.2-dev
Oct 4, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/backport-29600-4.2-dev

Conversation

@XuPeng-SH

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:

Refs #29597. Backport of #29600 to 4.2-dev, including the complete final source range through 3dae3634fbe759bd69688f7edf83f45835b8b231 (three source commits).

What this PR does / why we need it:

Policy rewrite prepends optimizer comments. The old comment-indexed source classifier consequently shifts save_result / cloud_nonuser away from their executable statement. On clean 4.2-dev, a role-filtered query returns the correct live row but result_scan fails with 20440.

  • Bind sources at the existing computation-wrapper owner, using grammar statement boundaries and the SQLMode-aware lexer. Compact SQL/source slots together, including fresh/cache, staged SQLMode and prepared paths.
  • Preserve source provenance when copying rewritten input; derive prepared nonuser state from its owner statement and decoded string/variable body, not a sibling statement.
  • Keep parse-failure records paired with diagnostic sources; do not infer markers from quoted data or beyond lexical failure.
  • Preserve internal protection and conservatively skip source lexing when exact tag candidates are absent. No new cache, state machine or parser.
  • Close 4.2's saved-result eligibility gap for nonuser SHOW results, using the same existing guard as internal results.

Branch adaptations and compatibility

Preserves 4.2's existing enable_remap_hint semantics, rewrite policy structure, native PREPARE envelope and lexical rules. Does not bring main's mandatory-role switch behavior, new snapshot fields, native wrapper refactoring or single-CN fixture. Existing saved-result/data/wire formats are unchanged. Mixed-version upgrade is outside this backport.

Validation

Target base: 6d4569bce66acb67e6d0fe746ee537da7955bffd; macOS arm64 / Go 1.26.4; freshly built target-native libraries.

  • Clean-target white-box and real SQL reproduction both fail for the expected old source-alignment cause.
  • Full frontend and all SQL parser package tests pass.
  • Maintained public regression passes two cleanup/recreation rounds on the same existing 3-CN fixture, with two-row row/column/combined policies, sparse/mixed markers, error recovery, privilege revocation, switch-off control, saved contents/metadata and nonuser SHOW absence.
  • Independent public QA passes NULL/UTF-8/empty/alias, lexical marker/literal controls, repeated cached execution, native/text/string/variable PREPARE, executable comments, staged SQLMode and partial-batch failure/recovery.
  • Owning/dependent go vet passes; incremental golangci-lint reports 0 issues.

Performance

Same target-native/toolchain, sequential baseline/candidate benchmarks. Marker-free binding allocations unchanged. After background compilation ended, the final interleaved pair showed plain 64 KiB / internal / escaped 64 KiB / 1000-row INSERT medians within the 10% budget (candidate approximately 1–3% lower). Earlier loaded-machine timings were noisy and are not used to claim speedup.

Ordinary EXECUTE source classification is 39.04 → 62.86 ns (same 16 B, 1 allocation). A literal containing a tag candidate still pays lexical validation (approximately 152 → 292 µs and 75,888 → 149,632 B for the synthetic 64 KiB case); this is the correctness fallback, not the marker-free path. No end-to-end workload speedup claim.

Design and final review

Both required gates used actual gpt-6.1-sol / xhigh: design ACCEPT and complete-change review ACCEPT, followed by accepted test-ownership delta review. Final reviewed staged diff SHA-256: 0ba62e50b7848de20fe62eb63e72589af76a125dcb886a27ea12e7a487edf40e. No unresolved delivery blocker. Target-specific cached AST test cleanup was corrected and the entire frontend suite/static checks rerun afterward.

CI has not been waited for.

Backport the complete final fix from PR matrixorigin#29600, preserving 4.2 rewrite enablement and native protocol behavior. Bind sources at the grammar owner, preserve decoded PREPARE protection and reject nonuser saved SHOW results.

Backport-source: 140c544
Backport-source: 023be96
Backport-source: 3dae363
Refs: matrixorigin#29597
Backport-of: matrixorigin#29600
@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Final whole-change model review: gpt-6.1-sol / xhigh — ACCEPT, no unresolved delivery blocker at c97be2b008be53424aacbece1919d963bfd2bf3e. This is an author-side review record, not a GitHub APPROVE.

Reviewed the complete 9-file backport and target adaptations against 6d4569bce66acb67e6d0fe746ee537da7955bffd: source publication, fresh/cache/AST/PREPARE/staged SQLMode paths, lexical markers and parse failures, internal/nonuser protection, result persistence, scanner reuse, test ownership and performance. Final diff fingerprint matches the reviewed content: 0ba62e50b7848de20fe62eb63e72589af76a125dcb886a27ea12e7a487edf40e.

Validation: full frontend and parser suites, public two-round lifecycle regression, independent public QA, vet and incremental lint (0 issues). After correcting target cached-AST ownership in the new test, the entire frontend suite and static checks passed again. Marker-free target allocation counts stayed unchanged; stabilized 64 KiB/internal/escaped/INSERT cost controls stayed within the 10% budget. Ordinary EXECUTE adds ~24ns; candidate-tag literals retain the documented lexical-validation cost. No end-to-end speedup claim.

The 4.2 rewrite switch/native envelope semantics and existing data formats remain unchanged. Mixed-version upgrade, main-only policy/harness changes and unrelated pre-existing cache behavior are outside this backport. CI has not been waited for.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review: no verified PR-introduced blocker

Technical recommendation: APPROVE for head c97be2b008be53424aacbece1919d963bfd2bf3e against 4.2-dev 6d4569bce66acb67e6d0fe746ee537da7955bffd. This review was performed directly, without subagents. Submitted as COMMENT, because the authenticated account owns this PR; it is not a formal GitHub approval or an independent human approval. CI is not being declared green.

Design and scope

  • The repair belongs at the existing GetComputationWrapper statement-binding boundary. Source entries and executable grammar fragments stay aligned through fresh/cache/AST/prepared/staged paths; policy materialization does not create a competing provenance owner.
  • The comment observer reuses the SQL lexer and its SQLMode rules. The comment mode is per call, not pooled mutable configuration. Internal provenance overrides every slot; nonuser precedence and decoded PREPARE bodies are handled explicitly. Parse-error records are paired with diagnostic-only sources and stop inference at lexical failure.
  • Existing PrepareStmt.IsCloudNonuser, query-result eligibility and authorization consumers are reused. No new state machine, cache, durable format, execution engine or compatibility branch was added. Scanner borrows have deferred returns; arrays are request-owned and input-bounded; no new asynchronous wait or lock dependency exists.
  • 4.2's rewrite-switch behavior, native PREPARE envelope and text EXECUTE contract remain branch-local. No main-only policy semantics were silently imported. Stored result formats/readers are unchanged; historical snapshots are not re-filtered by later policy changes. Mixed-version upgrade is outside the requested scope.

Comments and QA

#29605 has no unresolved code-review threads. The two historical findings on #29600—sparse markers selecting the wrong statement and unconditional re-lexing of marker-free large SQL—are fixed in this backport, with matching consumer/performance evidence, not just resolved-comment flags.

Reused evidence was checked against the final diff fingerprint 0ba62e50b7848de20fe62eb63e72589af76a125dcb886a27ea12e7a487edf40e: complete frontend/parser suites, maintained public SQL regression with two same-instance lifecycle rounds, native/text/variable PREPARE and SQLMode/partial-failure QA, scoped vet and lint. The earlier aggregate QA command had an obsolete SHOW-privilege fixture failure; the QA test itself passed, and the corrected maintained SHOW regression subsequently passed. That failed aggregate command is not counted as an all-green run.

Additional read-only overlay challenge in this review: eight adjacent cases passed through GetComputationWrapper, covering repeated identical fragments, tagged empty fragments, UTF-8 byte offsets, executable-comment boundaries, line comments and SQLMode-sensitive quotes. One additional input was rejected by both this head and the exact 4.2 base with the same syntax error:

/* cloud_user */ /*! select 1; select '/* cloud_nonuser */' */; /* save_result */

Adding an x before the quoted /* is the nearest accepted control and its expected source vector passes. The original failed probe was retained; all eight baseline overlay blobs were hash-checked against the base. This establishes an existing executable-comment lexer limitation, not a regression introduced here. No tracked source was changed during this review.

Performance and engineering quality

Implementation and tests were reviewed separately: production +233/-75, tests +590/-17, no documentation added. Tests extend existing fixtures and separate binding, eligibility and public-result oracles; the integration regression uses two rows and the existing shared cluster, with cleanup/reuse checks. No new test framework or production test hook was introduced.

Reused stabilized base/fixed measurements: ordinary 64 KiB binding 156.8→151.7 µs with unchanged 67,696 B / 20 allocations; ordinary EXECUTE classification adds about 24 ns with unchanged allocation count. External SQL containing candidate tag text only inside a 64 KiB literal still requires lexical disambiguation: 151.6→292.5 µs and 75,888→149,632 B. This is an explicit correctness cost, not an across-the-board performance improvement or end-to-end throughput claim.

Current CI qualification

Iceberg E2E Local job 111438322483 failed in make dev-up-iceberg-tier-a: Docker could not pull the MinIO image (unauthorized: access to the requested resource is not authorized). Adapter/golden-vector checks had passed; the SQL E2E environment did not start. This is an image-access/setup failure, not evidence of a SQL-source regression. Other pending CI is not awaited, skipped checks are not counted as passes, and no CI rerun or merge was triggered.

This branch was previously deployed

1 inactive deployment
ci — c97be2b0 Deployed Oct 4, 2026 by XuPeng-SH
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants