Repository navigation
Fix UTF-8 statement diagnostics and bound prepared logging work - #29826
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.
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.
What type of PR is this?
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:
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.