Skip to content

Fix UTF-8 statement diagnostics and bound prepared logging work - #29826

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue29809-utf8
Oct 10, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue29809-utf8

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 10, 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 #29809

What this PR does / why we need it:

After the plan TEXT capacity fix in #29812, statement diagnostics still contained malformed UTF-8 at two producer boundaries: byte truncation could split Chinese/emoji characters, and prepared binary parameters were copied directly into text. A real prepared SELECT hex(?) with bytes FF FE executed correctly but produced a short statement_info value that failed strict UTF-8 decoding.

Reuse the common UTF-8 prefix boundary in abbreviation and statement recording, including both ends of the existing mo_logger LOAD sample. At the existing prepared diagnostic formatter, reuse writeSQLHexLiteral for malformed UTF-8 and non-text C0/DEL bytes. Valid text, TAB/LF/CR, literal U+FFFD, numeric strings, empty parameters and null-bitmap NULL preserve their presentation. Execution bindings and parameter bytes remain unchanged.

Apply the existing LengthOfQueryPrinted budget while composing the complete prepared diagnostic. Stream SQL and values rather than building full parameter arrays and joining them before truncation. Stop before invisible parameters; bound visible hex encoding by the remaining budget. Common Abbreviate remains the single owner of final UTF-8 boundaries, ellipsis and limit sentinel semantics. No new budget policy, execution path or storage state is introduced.

Normalize malformed ordinary SQL diagnostics as well as prepared diagnostics. Common Abbreviate replaces each retained malformed UTF-8 byte with ASCII ?, preserving byte budgets and valid text (including genuine U+FFFD). Scan only the retained prefix; use the standard valid-UTF-8 fast path. Apply the same owner to retained mo_logger LOAD head/tail fragments. Executable SQL is unchanged: a raw malformed string literal still returns its original bytes through HEX.

Make failed diagnostics readable too. The lexer now selects a complete UTF-8 error excerpt within its existing 1024-byte budget and renders malformed retained bytes with the same common helper. The existing CapStatementInfoText storage owner normalizes both under-capacity and oversized statement/error text, retaining the existing TEXT limit and truncation marker. Live FillRow and historical CSV uploads reuse that owner without consumer-specific sanitizers. Valid text remains byte-exact and allocation-free; short malformed bytes become ? per byte, including on historical upload. Already persisted records are not rewritten. Execution inputs, original nonparser error objects/aggregation keys, error codes and status remain unchanged.

Correct the logtail progress regression test to follow the existing single publisher owner. Receiving a transport packet does not mean Publish has committed its frontier; directly completing another subscription at that point introduced an interleaving absent from the production logtailSender. Drive publisher admission synchronously while retaining real asynchronous transport, all four older/equal/newer frontier cases, decoded payload assertions and the no-extra-update check. No production synchronization or additional timeout is added.

Local formatter microbenchmarks compare this optimization with the preceding binary-safe implementation and assert identical 1027-byte output. With an 8-MiB parameter completely outside the retained prefix, time decreased from 40.6 ms to 359 ns and allocation from 67,143,952 to 2,320 B/op. Discarded 1-KiB, 1-MiB and 32-parameter cases likewise allocate 2,320 B/op. Visible binary values beginning with an invalid byte allocate 4,400 B/op across 1-KiB to 8-MiB inputs. These are component measurements, not SQL throughput estimates. UTF-8 validation adds bounded retained-prefix cost: a 1024-byte Unicode abbreviation measured 685 ns versus 105 ns previously, with unchanged 1152 B and one allocation; ASCII measured 132 ns versus 137 ns. Hidden 1-KiB and 8-MiB suffixes both measured approximately 130 ns with the same allocation. Capacity-renderer microbenchmarks measured oversized 1-MiB, 8-MiB and hidden-invalid-suffix inputs at about 6 microseconds versus 36.8 microseconds previously, with unchanged 65536 B and one allocation. Valid under-cap inputs now incur a scan: about 30 ns for 1024 ASCII bytes and 710 ns for 1023 Chinese bytes, with zero allocations. The existing eight-row normal historical batch measured 4.70 microseconds versus 4.25 microseconds, with unchanged 34 allocations; these are single-sample component results. A visible value with an invalid final byte still requires linear classification; unlimited diagnostics intentionally retain full formatting.

Extend existing fixtures instead of adding another test framework. Independent full-output oracles cover every byte budget, -2/-1/0, exact-fit and overflow, empty SQL/environment, UTF-8 rune boundaries, partial hex literals, malformed/partial UTF-8, controls, Unicode, NULL/empty and mixed parameters. Real populated prepared vectors and row serialization assert exact output and unchanged execution data.

Validation:

  • Full owning frontend normal PASS (20.642 s) and race PASS (33.018 s). Current owning mysql parser, ETL/db and motrace normal/race PASS; unchanged common/util evidence reused.
  • Lexer excerpt controls cover 2/3/4-byte cuts, aligned boundaries, malformed/partial input, exact ASCII format, source and positions. Existing ETL fixtures cover short repairs, capacity boundaries, unchanged other tables and historical upload; row tests check nonparser error identity/key/code and exact stored output.
  • Incremental configured golangci-lint: 0 issues across mysql, ETL/db, motrace and frontend; final test corrections also passed their package static checks. Repository molint, formatting and diff checks passed. Earlier unchanged direct-consumer static evidence remains valid.
  • Frontend tests use a task-owned NVMe TMPDIR. Default /tmp is a tmpfs smaller than the existing 16-GiB spill reserve; the same eight RETURNING failures were reproduced at the preceding HEAD and disappear with adequate temporary storage. No production budget policy or test assertion was relaxed.
  • Rebuilt isolated one-CN service with a 128-MB shared memory cache: five actual malformed COM_QUERY cases and eight binary Prepare/Execute cases passed exact independently read persisted diagnostics, strict Go/Python UTF-8 decoding, unchanged HEX results, NULL/empty semantics and same-session recovery. Includes an 8-KiB binary parameter behind a prefix exceeding the logging budget. Includes parser failure with failed status and same-session recovery. All 13 persisted diagnostic files passed independent strict UTF-8 decoding.
  • Four additional failed COM_QUERY cases on the rebuilt isolated instance passed valid protocol messages, protocol error 1064, persisted statement/error UTF-8, status Failed and stored code 20303, plus same-connection recovery. All four independent raw error readbacks passed strict Python decoding. Includes valid long Chinese SQL that previously produced an invalid 1234-byte error.
  • Actual gpt-6.1-sol/xhigh design, complete-change review and focused correction review passed, with no unresolved material blocker. The new error fixture uses the existing pooled factory and retains its configured buffer capacity; final motrace normal/race passed. An independent eager oracle also passed 106,556 capacity/repair/idempotence comparisons across mixed malformed bytes, Unicode, controls and all applicable budgets.

CI triage: the logtail test scheduling defect is corrected; focused coverage + race passed 100 repetitions, full owning logtail normal/race and incremental static checks passed. The separate fulltext concurrent snapshot-restore failure returned context canceled in an internal metadata query before its 240-second timeout. The exact existing two-CN test and a one-CN public 20-round probe passed locally; three additional two-CN repetitions with temporary context probes and targeted compile/process coverage also passed; cancellation attribution remains open, and no speculative suppression or retry is included.

No historical repair, ARM64/multi-CN/proxy diagnostic revalidation or overall CI success is claimed. Hex diagnostics may be cut mid-literal by the existing logging budget; they are diagnostic text, not executable 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 changed the title fix: preserve UTF-8 boundaries in statement diagnostics fix: preserve valid UTF-8 in statement diagnostics and prepared parameters Oct 10, 2026
@XuPeng-SH XuPeng-SH changed the title fix: preserve valid UTF-8 in statement diagnostics and prepared parameters Fix UTF-8 statement diagnostics and bound prepared logging work Oct 10, 2026
@matrix-meow matrix-meow removed the size/M Denotes a PR that changes [100,499] lines label Oct 10, 2026

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

Reviewed head 220da8d against merge-base e5dd472. No blocking findings after the complete implementation, test, consumer and unhappy-path review. This is a self-authored PR, so this COMMENT records the review result and is not an independent approval.

The previous malformed COM_QUERY diagnostic finding is addressed: retained text is normalized by common/util.Abbreviate, parser excerpts use the same boundary/repair logic, and CapStatementInfoText covers live statement/error serialization and historical CSV ingestion. The execution SQL/parameter data and original nonparser error identity/code remain untouched. Prepared formatting uses the existing logging budget and hex renderer; storage capacity stays with the existing storage owner. I found no redundant state machine, storage format, execution path or dead compatibility mechanism introduced here.

I traced all Abbreviate consumers, prepared EXECUTE USING/binary execution, mo_logger head/tail sampling, aggregated/nonaggregated FillRow and historical bulkInsert. For the separate logtail regression-test correction, synchronous publisher admission matches logtailSender's single-owner ordering while retaining asynchronous transport, all four frontier cases and the no-extra-update oracle. Adjacent tests still cover actual barrier admission/cancellation.

Validation: the changed formatter/recording, parser excerpt, diagnostic-capacity/historical import and motrace tests all passed locally on Darwin/arm64 with the repository CGo wrapper and freshly built matching native dependencies (Go 1.27.1). An additional independent eager repair/prefix oracle passed 940,397 comparisons, including all one-/two-byte strings and deterministic mixed Unicode/malformed inputs across every relevant budget. Reused the exact-head successful owning-package CI, SCA and author protocol/race evidence; diff checks passed.

Performance qualification: hidden parameters are no longer rendered and hex allocation is bounded by the retained prefix. A visible parameter can still require a full classification scan; unlimited diagnostics retain full formatting. UTF-8 normalization adds a retained-text scan, including the storage boundary. The component measurements in the PR describe those costs; this review does not claim measured TP/QPS neutrality.

Reviewed implementation +178/-86 and tests +523/-20 separately; no documentation delta. The tests cover distinct owner/consumer boundaries with reused fixtures and deterministic oracles. No unresolved blocker remains from the existing review comments.

This branch was previously deployed

1 inactive deployment
ci — 35899514 Deployed Oct 10, 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 kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: system.statement_info ingestion fails with TEXT length overflow during BF16 EXPLAIN ANALYZE diagnostics

2 participants