Skip to content

fix: escape index comments in catalog SQL - #27085

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/27079-index-comment-quote
Aug 14, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/27079-index-comment-quote

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

What this PR does / why we need it:

fix: escape index comments in catalog SQL

@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

Choose a reason for hiding this comment

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

[P1] Complete the index-comment serialization/replay closure for backslashes

The INSERT-side change at pkg/sql/compile/util.go:312 correctly stores the comment, but the new regression uses index's comment\with unicode 维度 and only checks that this first SQL string contains sqlquote.String(comment). The reverse path still renders index comments through formatStr in pkg/sql/plan/build_show_util.go:407; that helper doubles quotes but leaves backslashes untouched. buildShowCreateTable then embeds the entire DDL in a double-quoted SQL literal, whose MySQL scanner treats backslash as an escape introducer.

I reproduced the exact current-head path: semantic value "index's comment\\with unicode 维度" produced a pre-scan DDL containing the backslash, but the SHOW CREATE value became "index's commentwith unicode 维度" (preserved=false). The same generated DDL is reparsed by CREATE TABLE LIKE/clone, so that path also silently changes the comment.

Thus the apostrophe write failure is fixed, but the issue's backslash + replay requirement is not closed, and the current unit test gives a false sense that it is. Please make the display/rewrite side preserve the comment across its required escaping layers and add an independent round-trip regression through ConstructCreateTableSQL/the parser (plus the inline and ALTER public paths requested by #27079), asserting the recovered comment equals the original.

@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 re-review completed on exact head d0aafa7. The previous catalog replay, public SHOW CREATE transport, and end-to-end coverage blockers are closed: the complete DDL now crosses the rewrite SQL boundary through sqlquote.String, quote/backslash/trailing-backslash controls round-trip, the generated mo_indexes INSERT is parsed and its semantic comment asserted, and distributed coverage exercises inline CREATE plus ALTER ADD INDEX through SHOW INDEX/SHOW CREATE and CREATE LIKE. Focused plan and compile tests pass with the required CGO/thirdparties setup; git diff --check is clean.

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

Reviewed exact head d0aafa7. SQL string quoting now closes catalog INSERT, SHOW CREATE transport, and replay paths for index comments including quotes, backslashes, and Unicode. Focused compile and plan round-trip tests pass; CI is green. Approving. GitHub currently reports a merge conflict with main; refresh before merge.

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

Deep-reviewed exact head 1ac5579ef7263e722648e052bbb6953549f836ea against base aa3f1551ca110687d63b932bad7f550eacb7c27c. The prior blockers are closed:

  • Catalog INSERT generation now applies the shared default-parser string quoting at the semantic-value boundary; inline CREATE and ALTER ADD INDEX both converge on this path.
  • SHOW CREATE / CREATE LIKE replay uses SQL-mode-aware quoting for the inner DDL, while the outer internal SHOW transport uses latest main's shared default-mode formatter.
  • Unit and distributed coverage includes quote + backslash + Unicode values, both public DDL entry points, SHOW metadata, and LIKE replay.

Local focused compile/plan tests pass. I also ran an independent default/NO_BACKSLASH_ESCAPES counterexample matrix covering quote + backslash + Unicode, backslash-before-quote, and trailing-backslash comments through inner DDL, outer SHOW transport, and replay; all semantic values round-trip exactly. No blocking correctness, compatibility, or maintainability issue found. CI is still running.

@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 13:10 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-14 13:47 UTC · at 36bd02aff9b39f3de1eb227a7f6b16417764ee3d

This pull request spent 37 minutes 11 seconds in the queue, with no time running CI.

Reason

Pull request #27085 has been merged manually at 61d0389

Hint

You were too fast!

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

  • Requeue this pull request

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.

5 participants