Repository navigation
fix: bound statement_info diagnostics to TEXT capacity - #29812
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 commit 3178a829dcfb0bf5614ac196ec2352e135e68eae against main (0ccc989731f9c2b40d31554a44ca505c656c0e62). I found no blocking correctness, lifecycle, compatibility, or design issues.
The producer-side bound and historical CSV normalization cover distinct paths and share one capacity policy. Aggregation remains bounded while statistics continue to accumulate, and existing cleanup owns builder release. Normal SQL TEXT validation remains intact. Focused owner-package race tests, the real SQL LOAD case, historical-file retry coverage, and incremental SCA passed locally.
Paired performance checks showed unchanged normal-path allocations. Small timing differences were noisy; a targeted CSV-content follow-up measured +1.35% versus base, with no repeatable material regression. This supports no material regression, not a zero-cost claim. CI checks are still in progress; this approval is based on the reviewed code and local evidence.
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] 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.
What type of PR is this?
Which issue(s) this PR fixes:
Closes #29797.
What this PR does / why we need it:
Ordinary TEXT assignment correctly enforces its 65,535-byte capacity. Internal statement diagnostics and merged SQL could exceed that capacity, causing statement_info CSV uploads to fail with error 1406 and leave files retrying. The offending incident column is unknown; local producer and real LOAD reproductions confirm the contract mismatch.
Design
etl/dbowner, which already handles statement_info ingestion compatibility....[truncated], including the marker in the byte budget. Preserve the original error and aggregation key.truncated,original_bytes, andlimit_bytes; retain normal/cached plan bytes and existing plan cleanup.Freeown builder cleanup so repeated exports remain stable.Implementation delta: +130/-21 (net +109 lines); tests +615 lines, including reusable performance fixtures and one shared embedded-cluster consumer case; documentation +0. Tests cover distinct producer, ingestion, durable-file and performance risks rather than duplicating service setup.
Validation
0ccc989731f9c2b40d31554a44ca505c656c0e62:go vet, configuredmolint, and configured golangci-lint 2.14.0 (--new-from-rev/--whole-files) passed, 0 issues. Scope includes db, motrace, export, etl and dml; final dml fixture cleanup revalidated separately.-p 2..agents/skills/mo-dev/scripts/mo-cgo-test -race -p 2 -count=1 -timeout=300s \ ./pkg/util/export/etl/db ./pkg/util/trace/impl/motrace \ ./pkg/util/export ./pkg/util/export/etl .agents/skills/mo-dev/scripts/mo-cgo-test -race -p 2 -count=1 -timeout=300s \ ./pkg/tests/dml -run '^TestStatementInfoDiagnosticCapacitySQL$'Both race scopes passed, including existing owning-package tests.
Performance
Exact-base source overlays and identical fixtures on the same host: five 1-second samples per normal reporting case, with no added normal allocations. Full ContentBuffer.Add + CSV medians were 2.800→2.787 µs and 2.780→2.762 µs for the two writer modes; historical 8-row batch median 3.174→3.212 µs. Individual FillRow differences were around 1–3%; these are not claimed as speedups. Representative aggregate output uses 16 fewer bytes through exact header sizing. Full New/Update/FillRow/Free group measurements preserve allocation counts for normal groups: merged 1.636→1.641 µs, representative 1.547→1.471 µs. Synthetic saturating and already-saturated groups run about 70% faster and allocate over 90% fewer bytes, by stopping text growth while continuing statistics. These improvements concern overflowing aggregate reports, not SQL execution throughput.
Tracing-enabled real SQL controls: SELECT median 177.5→177.1 µs. UPDATE timings had substantial background variance and no consistent regression; their lower median is not claimed as an improvement. These local controls do not replace broad workload benchmarking.
Initial large-plan marshaling and existing in-place batch escaping remain unchanged. This bounds exported diagnostics and aggregate text, not every telemetry allocation. Compatible historical files are recovered; schema-incompatible files retain their existing separate handling.
Design and final independent QA used
gpt-6.1-sol / xhigh. Final verdict: APPROVE, no material blockers; missing aggregation-performance evidence and test-backoff isolation were corrected and re-reviewed. Final reviewed delta fingerprint:b4b610c5d697206e09480f4298de4f9edb1fb0e200a4e602ff92556d86ffa85a. CI has not been awaited.