Repository navigation
fix: preserve TRIM and POSITION syntax in CTAS - #29359
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review — no blocking findings; approval recommendation
Reviewed head 563bd82c7cde9e049d67857711cf62577194bacc, merge-base a61e7710e26c7d7613e2aa19913460ff9b7e2606, against freshly verified main (e914d987641c266162eb607ec072fdb5a2b06da9). All three changed files and every changed hunk were reviewed. This is an ordinary bug fix; a separate design document is unnecessary.
Contract and engineering review
- Traced MySQL grammar →
FuncExpr.Format/trimExprsFormat→ CTAS SQL construction → execution of the generated INSERT/SELECT. TRIM directions are parser-createdNumValnodes from the closed BOTH/LEADING/TRAILING grammar. Emitting their keyword text directly is appropriate; source/removal expressions retain normal formatting. POSITION preserves itsINseparator, argument order, and parentheses. The!IsGenericguard preserves whitespace-sensitive generic calls. - The change is localized and proportionate. It adds a fixed name/arity check during formatting, with no new per-row execution work, I/O, retained state, or synchronization. No additional abstraction or distributed protocol is warranted. This is source analysis, not a performance benchmark.
- Tests cover distinct contracts: AST syntax/argument round trips and materialized CTAS results. Reviewed cleanup after failure, independent cleanup context, database/connection ownership, shared fixture reuse and termination. No new unbounded growth or asynchronous lifecycle was introduced. No API/wire/storage-format or authorization contract changes were found.
Evidence
- Exact-head CI run 35996059270 is green for the required gate, Ubuntu UT, coverage, arm64 SCA, shared build and both active multi-CN BVT jobs. Skipped jobs are excluded from this evidence.
- Verified the Ubuntu UT checkout SHA and artifact selection:
TestCTASSpecialFunctionSyntaxpassed (37.79 s), including all five named result-checking subtests; the owning integration package passed (242.30 s). Reused that execution instead of starting another cluster locally. - Built native artifacts with provenance validation and ran the PR's formatter regression plus 14 review-only boundary cases under both CTAS and ordinary quoting: PASS (
pkg/sql/parsers/tree, 0.023 s). Cases included direction-only TRIM, uppercase keywords, empty/NULL operands, nested calls, parenthesized arithmetic, embedded quotes, and generic TRIM/POSITION. Review probes were supplied through a Go overlay; the checkout is clean. - Examined the earlier coverage failure:
pkg/tests/issues/isolatedreached its 10-minute package timeout, withTestSpeedupAbortAllTxnrunning for only 18 s at the alarm. The current rerun passed. This log does not establish a TRIM/POSITION regression or a 10-minute hang in that individual test.
Existing limitation found during boundary checks
The CTAS double-quote formatter duplicates backslashes: parsing select trim('\\a\\'), formatting with WithQuoteString(true), and reparsing changes the stored string value. The ordinary single-quote mode preserves it. A separate diagnostic fails identically on this head and with the merge-base expr.go restored via overlay. The cause is the unchanged NumVal.Format → FormatString → %q path; this existing literal-escaping defect warrants separate tracking. The approval recommendation is limited to the syntax fix in this PR.
One non-blocking test suggestion is attached inline. GitHub review event is COMMENT because the authenticated account owns this PR; the review recommendation is APPROVE.
| }{ | ||
| {"trim default", "select trim(b) as t from s", "trim(`b`)", "trim(`b`)"}, | ||
| {"trim removal", "select trim(a from b) as t from s", "trim(`a` from `b`)", "trim(`a` from `b`)"}, | ||
| {"trim both", "select trim(both a from b) as t from s", "trim(both `a` from `b`)", "trim(both `a` from `b`)"}, |
There was a problem hiding this comment.
Non-blocking test coverage: please consider adding trim(both from b), trim(leading from b), and trim(trailing from b) to this table. They exercise the distinct case "2" branch changed by this PR; the existing direction cases exercise case "3". I verified all three missing forms under both quoting modes with a review-only probe and they pass, so this is regression protection rather than a demonstrated correctness defect.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29330
What this PR does / why we need it:
CTAS reparses a generated
INSERT ... SELECT. FormattingTRIM(BOTH|LEADING|TRAILING remstr FROM str)under CTAS's string-quoting options incorrectly quoted the direction keyword, andPOSITION(substr IN str)was formatted as comma syntax. Both generated invalid SQL despite valid original SELECTs.Render TRIM direction as a keyword and POSITION with
IN. Parser round-trip tests cover default/removal/directional TRIM and column/literal POSITION in ordinary and CTAS formatting modes. A real embedded-MO SQL integration test creates CTAS tables for all five reported forms and verifies their materialized values.Validation:
make cgo; focused and fullpkg/sql/parsers/treetests;TestCTASSpecialFunctionSyntaxthrough the SQL frontend;go vet ./pkg/sql/parsers/tree;git diff --check. GPT-6 medium design and final code review completed.