Skip to content

fix(plan): escape backslashes in SHOW CREATE TABLE comments - #31069

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/show-create-comment-backslash
Oct 25, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/show-create-comment-backslash

Conversation

@MatrixAdventurer

@MatrixAdventurer MatrixAdventurer commented Oct 25, 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 #31068

What this PR does / why we need it:

SHOW CREATE TABLE must preserve backslashes when its column/table comments are replayed. Stored comments already double single quotes but keep backslashes raw; escape those backslashes in default SQL mode while retaining literal backslashes under NO_BACKSLASH_ESCAPES.

Preserve DUMP/LOAD compatibility at the same time. DUMP persists a SHA256 of reconstructed schema text, so changing comment display bytes originally made old archives fail LOAD despite identical metadata. A dedicated hash-only planner entry retains the historical column/table COMMENT representation; ordinary SHOW/replay and manifest DDL keep the corrected escaping. Index/default quoting, archive versions, existing normalization/fallbacks and strict LOAD comparisons are unchanged. Changed comments, types and defaults remain mismatches.

Rebased onto frozen main 12eeeb0205b5e87faef48660ddbcd8cb5e18baea. Production repair is 4c797463ad; subsequent Go changes only release test-owned ASTs.

Regression and compatibility evidence

  • Fixed golden fingerprints were obtained by executing the actual frontend hash function with frozen-main production files. The original PR fails the column/table/mixed-backslash cases while empty/plain/quote controls pass; the repair preserves all six goldens without mutating metadata.
  • A real old-server full DUMP contains two rows plus a secondary index, with backslashes/quotes in column/table/index comments and a backslash default. An independent candidate cluster loads it, preserves rows/comments and satisfies FORCE INDEX. Five changed-schema targets are rejected with error20301 and stay empty.
  • The old server also loads the candidate's new archive successfully. Both producers retain schema hash 0357a0ede5ef359080f54e141cda3556a1dd789ae980566e6a2aa89146af87cd. Old archive files remain byte-for-byte unchanged.
  • The immutable pre-fix archive is committed as a 3,884-byte fixture. The public BVT loads it, checks rows/index access, tests current DUMP/CREATE LIKE/LOAD and mismatch rejection, and retains all original SHOW/replay/HEX assertions.
  • BVT normal comparison: changed case 32/32, complete comment group 106/106, same-instance repeat 32/32; no ignored/failed checks. Case-owned databases/stages and temporary manifest files are cleaned up.
  • Owning pkg/sql/plan and pkg/frontend normal/race validation passes, including changed regressions. Three unrelated existing skips are explicitly excluded from pass counts. The first planner race attempt hit a 30s deadline in an unchanged view-schema test; the baseline focused check and final complete planner race pass. That first attempt is not counted as a package pass or claimed to prove a pre-existing defect.
  • Incremental gofmt/vet/lint for both packages passes. Twelve molint diagnostics reproduce with the same checker on an exact clean-main overlay; no introduced diagnostic. The AST cleanup receives focused normal and final owning-package race/static validation.
  • Design and complete final review: gpt-6.1-sol / xhigh, with source/evidence reconciliation.

Reproduction and retained evidence include source/binary/native identities, exact commands, old/new archive manifests, SQL receipts, BVT reports/cleanup and test selections. Initial harness/index-flush/startup preflights are explicitly excluded. New-head GitHub CI has not been evaluated and is not included in local pass claims.

@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 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 117bfe8c250a2cf79eec227ef1599ba7b1448820

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: 117bfe8c250a2cf79eec227ef1599ba7b1448820

Assessment: request_changes

Reviewed the complete five-file delta and affected callers. The mode-aware comment escaping is sound, but it changes persisted DUMP schema fingerprints without preserving compatibility.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P1 pkg/sql/plan/build_show_util.go:1680: Create a DUMP TABLE archive before this change for a table with backslashes in a column or table comment, then upgrade and LOAD it into an identically defined empty table.
    Impact: Existing archives are rejected with "target table schema does not match table dump" despite unchanged metadata. Preserve legacy fingerprint compatibility alongside the escaping fix, and add a pre-fix archive/current-version LOAD regression.
    Evidence: pkg/frontend/table_dump.go:357–367 hashes ConstructCreateTableSQL output; DUMP persists that hash at line 1290, and LOAD requires exact equality at lines 1722–1723 without a fallback. Hashing uses a nil compiler context, so the new helper doubles backslashes. The source-extracted probe confirms changed fingerprints for both column and table comments, while quote-only, plain and empty controls remain unchanged.

Validation:

  • Isolation preflight passed: checks/1792911898139249946-2.json matches preflight.log.

  • The source-extracted formatter/scanner probe passed 40 round-trip cases across four SQL-mode configurations and five fingerprint controls. Receipt checks/1792912003112957379-2.json matches comment_probe.log, exit 0 and the assigned executor.

  • Commands, source/artifact fingerprints, logs and clean checkout status were independently reconciled. Evidence and review notes are retained under /home/xupeng/.local/state/mo-bot/jobs/ab16a8df77e65f1e0e6859ba/attempt-1.

  • Frozen exact-head evidence records successful UT, SCA, coverage and proxy/pessimistic BVT checks; local_validation is empty.

Limitations:

  • The probe executes extracted formatter/scanner code with fixture scaffolding, not production DUMP/LOAD. The rejection follows from the reviewed production call chain; no cross-version server restore was executed.

  • Native package tests were not rerun, and raw CI logs were not supplied.

  • Rendering adds SQL-mode parsing and linear comment escaping work, bounded by existing comment limits. Ordinary SELECT/DML is unaffected; no performance benchmark was run.

MatrixAdventurer and others added 5 commits October 25, 2026 08:06
@mergify mergify Bot added kind/documentation Improvements or additions to documentation kind/test-ci labels Oct 25, 2026
@matrix-meow matrix-meow added size/XXL Denotes a PR that changes 2000+ lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 25, 2026
@XuPeng-SH

XuPeng-SH commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 089fd2e28f46204ddef9ec8393f0a2fd9bca1bab

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: 089fd2e28f46204ddef9ec8393f0a2fd9bca1bab

Assessment: approve

Reviewed the complete 15-file delta and affected callers. The previous DUMP compatibility finding is resolved: one shared planner implementation now distinguishes replayable SQL from historical schema-hash input, preserving strict LOAD validation. Comment escaping respects SQL mode and existing quote encoding without mutating metadata. The design is proportionate, and no actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • The independent static audit passed: checks/1792951857477887056-4.json matches review-audit-final.log, exit 0, the assigned head and a clean source checkout. It verified legacy reconstruction-body equivalence to the base, four Go source fingerprints, module/config identities, fixture integrity and retained evidence consistency.

  • Verified all four legacy archive files against recorded producer hashes and manifest object sizes: 3,884 bytes total. Reviewed the embedded cross-version SQL transcripts covering old-to-new and new-to-old LOAD, row/comment/index preservation, and five schema-mismatch rejections leaving targets empty.

  • Reconciled source history with retained normal/race package records and focused regression selection. Reviewed normal BVT reports for the changed case, comment group and same-instance repeat: 32/32, 106/106 and 32/32, with teardown checks. These are reused author records, not newly executed tests.

  • The frozen exact-head CI snapshot records successful shared build, UT, SCA, coverage, proxy BVT and multi-CN BVT. Skipped upgrade checks were not counted as passes.

  • Detailed review and receipt mapping are retained under /home/xupeng/.local/state/mo-bot/jobs/ed2391dd0d914246a3aa6c83/attempt-1/review-record.json. The initial audit-script key error is preserved separately and is not a product failure.

Limitations:

  • No native tests or server processes were run locally. Original author binaries and full raw Go/lint/service logs are unavailable; verification used committed transcripts, terminal records, source identities, immutable fixtures and the frozen CI snapshot. Raw CI logs were not supplied.

  • No performance benchmark was run. Additional work is limited to SQL-mode parsing and linear comment escaping during reconstruction; ordinary SELECT/DML paths are unchanged, and schema hashing bypasses escaping.

@mergify mergify Bot added the queued label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-25 18:13 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-25 19:40 UTC · at 7f9fa94518b71624751875048a8ae4657b85e52c

This pull request spent 1 hour 27 minutes 15 seconds in the queue, with no time running CI.

Reason

Pull request #31069 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit b160a38 into matrixorigin:main Oct 25, 2026
27 of 28 checks passed
@mergify mergify Bot added dequeued and removed queued labels Oct 25, 2026
gouhongshen added a commit to gouhongshen/matrixone that referenced this pull request Oct 25, 2026
…ions

Main already carries the production repair for matrixorigin#31068: the merged PR matrixorigin#31069
renders stored column/table comments with backslashes doubled for replay
(verbatim under NO_BACKSLASH_ESCAPES) through ConstructCreateTableSQL, keeps
the historical raw spelling for persisted DUMP fingerprints via
ConstructCreateTableSQLForSchemaHash, and pins the display and legacy-archive
regressions with its own UT and BVT.

Rebase this branch onto that fix: the duplicate production changes and the
signature churn of the private constructCreateTableSQL parameter are dropped
in favor of the merged implementation, while the regression coverage this
branch developed stays, adapted to the merged API:

- pkg/sql/plan/show_create_comment_backslash_replay_test.go: catalog-stored
  comment bytes pinned across default and NO_BACKSLASH_ESCAPES modes
  including plain, empty, trailing-backslash and quote-adjacent columns;
  rendered fragment asserts plus their negation, replay idempotence,
  non-mutation of the input TableDef, and single-literal transport
  re-parsing.
- pkg/frontend/table_dump_comment_fingerprint_test.go: the frozen pre-fix
  schema and logical-index fingerprints for backslash comments, old-manifest
  acceptance after the escaping fix, and corrupted-comment/altered-type
  mismatch controls on tableDumpRelationSchemaMatches.
- comment_backslash_roundtrip BVT: replay SHOW output with both-column hex
  asserts, the NO_BACKSLASH_ESCAPES and plain-comment controls, merged with
  the upstream legacy dump-fixture and metadata-only DUMP/LOAD blocks.

Related to matrixorigin#31068
XuPeng-SH added a commit that referenced this pull request Oct 26, 2026
…ions (#31143)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #31068

## What this PR does / why we need it:

The production repair for #31068 has already merged into `main` as
#31069:
stored column/table comments keep their already-doubled quotes and get
their
backslashes doubled for replay while backslash escapes are active
(verbatim
under `NO_BACKSLASH_ESCAPES`), and the persisted `DUMP` schema
fingerprints keep
hashing the historical raw comment spelling through
`ConstructCreateTableSQLForSchemaHash`.

While that merged upstream, this branch had independently developed the
same
regression theme. This PR rebases onto the merged fix, drops the
duplicate
production implementation in favor of the merged one, and keeps the
complementary regression coverage this branch produced, adapted to the
merged
API:

- `pkg/sql/plan/show_create_comment_backslash_replay_test.go` (new):
pins the
exact catalog-stored comment bytes through render+replay in both SQL
modes
for plain, empty, trailing-backslash and quote-adjacent columns, asserts
the
  rendered fragments plus their negation, requires replay idempotence
(re-rendering is byte-stable), non-mutation of the rendered `TableDef`,
and
  that the displayed DDL survives single-literal transport encoding.
- `pkg/frontend/table_dump_comment_fingerprint_test.go` (new): freezes
the
  pre-fix schema and logical-index fingerprints for a backslash-comment
fixture, accepts an old manifest (legacy fingerprint) for an unchanged
table
  after the escaping fix, and rejects genuine mismatches: the corrupted
  comment bytes the pre-fix bug produced and an altered column type.
- `test/distributed/cases/comment/comment_backslash_roundtrip.sql` +
`.result`:
replay `SHOW CREATE TABLE` output with `information_schema` hex checks
on both
columns plus the table comment in both SQL modes, the plain-comment
control
  and the `NO_BACKSLASH_ESCAPES` controls, merged with the upstream
  immutable legacy dump-fixture LOAD and metadata-only DUMP/LOAD
fingerprint-mismatch blocks. The case owns and drops its database and
stages,
  so it is re-runnable, and it saves the incoming `sql_mode` into a user
variable around its `NO_BACKSLASH_ESCAPES` control block and restores it
  afterwards (the pattern `information_schema.sql` and
`table_func_json_table.sql` already use), so the shared mo-tester
session is
  left in its incoming state for every later script of the same BVT
  generation.

All production behavior now comes unchanged from `main`; this PR is
test-only.

## Validation

All verification ran on the rebased tree `07876cfdab` =
`origin/main@b160a38` (which already contains merged #31069) plus
this commit; the produced binary contains CommitID `07876cfdab` (sha256
`968e0617...`). CGo test runs use the repository `mo-cgo-test` wrapper.

- `go test -list` selection proof:
`TestShowCreateTableCommentBackslashStoredByteRoundTrip`,
`TestShowCreateTableCommentIsNotMutated`,
`TestShowCreateTableCommentTransport` (new in `pkg/sql/plan`), the
merged upstream `TestShowCreateTableCommentBackslashRoundTrip`, and
`TestDumpSchemaHashKeepsLegacyBackslashCommentSpelling`,
`TestOldDumpManifestMatchesUnchangedTableAfterCommentEscapingFix` (new
in `pkg/frontend`) plus the upstream
`TestTableSchemaHashStoredCommentCompatibility`,
`TestTableSchemaHashStillRejectsCommentAndSchemaDifferences` all listed
(non-empty selection).
- `go test -run 'TestShowCreateTableComment' ./pkg/sql/plan` - ok
2.527s, exit 0 (replay round trip in both sql modes, fragment/negation
asserts, idempotent re-render, non-mutation, transport re-encode).
- `go test -run
'TestDumpSchemaHashKeepsLegacyBackslashCommentSpelling|TestOldDumpManifestMatchesUnchangedTableAfterCommentEscapingFix|TestTableSchemaHashStoredCommentCompatibility|TestTableSchemaHashStillRejectsCommentAndSchemaDifferences'
./pkg/frontend` - ok 7.847s, exit 0. The pre-fix fixture fingerprint
stays `d0f7fd53926c805dd05af3d5dcd2f4f148d8861d539db9a7490aa77e07b061bd`
under the merged `ConstructCreateTableSQLForSchemaHash` path (schema and
logical-index hashes), an old manifest still matches an unchanged table,
and corrupted-comment/altered-type mismatches are still rejected.
- Owning packages in normal mode: `go test ./pkg/sql/plan` - ok 256.339s
exit 0; `go test ./pkg/frontend` - ok 54.640s exit 0.
- BVT on an isolated single-node instance (fresh runtime, separate port
plan): `genrs` regenerated `comment_backslash_roundtrip.result`
byte-identical to the committed file (zero-diff, every row reviewed
against the union of the two upstream expectations); normal comparison
run 42/42 exit 0; same-instance repeat run 42/42 exit 0; full
`test/distributed/cases/comment` group 116/116 exit 0 (`annotion` 18,
`comment` 56, `comment_backslash_roundtrip` 42, mo-tester `error.txt`
empty). The legacy `$resources` dump fixture loads with rows intact,
`FORCE INDEX` is honored, `LOAD` rejects the changed-schema target with
`target table schema does not match table dump` and the mismatched table
stays empty. Post-run teardown verified: `comment_bs_rt` database, both
stages, `/tmp` metadata files all absent; the instance was stopped with
SIGTERM and confirmed exited with its listeners released.
- Static: `gofmt -l` on all changed Go files - clean; `go vet` and `go
vet -vettool=molint` on `./pkg/frontend ./pkg/sql/plan` with the
repository CGo environment - exit 0; `golangci-lint run -c .golangci.yml
--new-from-rev origin/main` on the two packages - 0 issues (see
golangci-rebased log).

## Follow-up (2026-10-26): fix the compose-proxy BVT failure this branch
introduced

CI run

[40232128784](https://github.com/matrixorigin/matrixone/actions/runs/40232128784)
('multi cn e2e bvt test docker compose(PROXY)') failed exactly 2 of
49746
statements, both in
`test/distributed/cases/cte/local_outer_reference.sql`
(rows 379/382) with `correlated columns in aggregate function is not yet
implemented`; every other script in the generation stayed green,
including
`comment_backslash_roundtrip.sql` itself (42/42).

Root cause: the case's `NO_BACKSLASH_ESCAPES` control block ended with
`set sql_mode = ''`, mo-tester reuses one session for every script of a
generation (CI log shows `con[id=0]` throughout), so the CTE case and
everything later lost `ONLY_FULL_GROUP_BY`.
`pkg/sql/plan/having_binder.go`
only rebinds correlated columns in aggregate/HAVING predicates under
`mysqlFullGroupByCompat`, which requires `ONLY_FULL_GROUP_BY` in
`sql_mode`;
without it the binder returns the NYI error. Commit `57f93b5873`
therefore
saves the incoming `sql_mode` before the block and restores it
afterwards.
The same run's `UT Coverage` failure
(`TestCrossTargetUpgradeRecovery/manual-4.0.13`,
pkg/embed upgrade-recovery budget flake) is the known family flake
tracked in
#31044 and is unrelated to this test-only diff.

New verification for `57f93b5873` ran on a fresh isolated instance of
the same
produced binary (`07876cfdab`; `57f93b5873` changes only the two comment
BVT
files, so production behavior is identical):

- Direct session probe on the same binary: the controlled statement
returns the
  expected rows (1|1, 2|NULL, 3|0) under the platform default `sql_mode`
  (`ONLY_FULL_GROUP_BY,...`), fails with the exact NYI error under
  `sql_mode=''`, and passes again after the save/restore pattern.
- Ordered pair through mo-tester (CI compare semantics: `$resources`
mapping +
  `nometa`), exactly as the CI group orders them: pre-fix reproduction =
  `comment_backslash_roundtrip.sql` 42/42 and
  `cte/local_outer_reference.sql` 266/268 with only rows 379/382 failing
(mo-tester exit 1); post-fix = comment 43/43, cte 268/268, 311/311 and
exit 0.
- `genrs` on the fixed case regenerates
`comment_backslash_roundtrip.result`
  byte-identical to the committed file (zero-diff).
- Full `test/distributed/cases/comment` group with metadata comparison
on:
117/117 exit 0 (`annotion` 18, `comment` 56,
`comment_backslash_roundtrip` 43).

## Residual risk

- The case writes DUMP metadata to
`/tmp/mo-comment-backslash-roundtrip-31068/`
and removes it again in the same script (`remove files from stage ...`),
the
  same path and cleanup the merged upstream case already carries.
- No CI, workflow, or configuration files are touched; the diff is
limited to
  the two new UT files and the reworked comment BVT case.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
MatrixAdventurer added a commit to MatrixAdventurer/matrixone that referenced this pull request Oct 26, 2026
Resolve table_dump.go conflict with matrixorigin#31069: a single
ConstructCreateTableSQLForSchemaHash now keeps both legacy comment bytes and
legacy string-default bytes for DUMP fingerprints.

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

dequeued kind/bug Something isn't working kind/documentation Improvements or additions to documentation kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SHOW CREATE TABLE drops backslashes in column and table comments, so replaying it changes the comment

3 participants