Skip to content

fix(sql): MySQL warnings for FORMAT locale, LN/LOG args, STR_TO_DATE - #30373

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aptend:fix/warnings-compat-30217-30213-30214
Oct 17, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aptend:fix/warnings-compat-30217-30213-30214

Conversation

@aptend

@aptend aptend commented Oct 16, 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 #30217
Fixes #30214
Fixes #30213

What this PR does / why we need it:

Return MySQL diagnostics alongside existing scalar results: FORMAT warning 1649 with the en_US fallback for unknown/empty/NULL locales, logarithm warning 3020 with NULL results for invalid arguments, and STR_TO_DATE warnings 1411 for invalid input and 1292 for accepted trailing text.

Register diagnostic-producing overloads in the existing rowScopedDiagnostics metadata. Optimizer/file-pruning admission and the shared folding/direct-evaluation probes now preserve per-row effects; safe constants still fold. Remove the duplicate scalar-warning prediction switch and STR_TO_DATE calendar validator, preserving the existing DIV/INTEGER_DIV/MOD policy. Logarithm diagnostics and all three STR_TO_DATE return types respect selected-row masks and NULLs.

Bound FORMAT locale echoes before formatting, reject unsupported locale lengths before case conversion, and avoid cloning unknown locale strings into the formatter. No-sink and zero-retention probes skip message construction. NULL now reports exactly Unknown locale: 'NULL', while an empty locale retains Unknown locale: ''. STR_TO_DATE diagnostic text remains bounded before construction.

Rebased onto main d304047724. Validation:

  • Complete function, colexec, external, vectorize/format, plan/rule, plan and compile packages passed. A real bound FORMAT filepath predicate reproduces the pre-fix file-pruning error and now stays row-level without publishing a pruning-time warning; the pure-filepath control still prunes.
  • Runtime tests cover three-row diagnostic constants and safe folding across the logarithm family, FORMAT and all STR_TO_DATE result types. Direct FORMAT evaluation checks three-row/zero-row counts, NULL/empty/valid locales and scalar result preservation. Canonical and legacy kernels check bounded messages and count-only probes.
  • Incremental golangci-lint (including govet) over every changed Go package and the service build passed.
  • FORMAT benchmarks allocate locale inputs outside the measured loop. With a 2 MiB locale the helper reports 0 B/op and 0 allocs/op without a sink or with WarningProbe; the canonical kernel uses 280 B/op (6 allocs/op) in those modes and 456 B/op (8 allocs/op) with retained warnings.
  • function/scalar_compat_warnings.sql: 64 statements passed twice through normal mo-tester comparison. Independent SQL assertions check values, diagnostic codes/counts, exact NULL/empty locale messages, short-circuit branches, prepared reuse and max_error_count=0 (three counted warnings, no retained rows). Schema cleanup and owned-service shutdown passed.

Full CI on the pushed revision is required before merging.

@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 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d5d321d58ea69136e67b57f10e658d2359598ad9

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: d5d321d58ea69136e67b57f10e658d2359598ad9

Assessment: request_changes

Reviewed the complete six-file delta. Reusing the warning sink and parser is reasonable, but public SQL reproduces missing FORMAT warnings and incorrect constant-expression warning counts. STR_TO_DATE also introduces substantial avoidable allocation for large invalid inputs.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/sql/plan/function/func_binary.go:6738: Execute SELECT FORMAT(1234.5,2,'bad_locale'), including string-valued numbers and empty or NULL locales.
    Impact: The promised warning 1649 remains absent from normal SQL. Wire the diagnostics into the canonical FORMAT implementation and cover it through SQL binding.
    Evidence: SQL returned '1,234.50' with empty SHOW WARNINGS and warning_count=0. list_builtIn.go binds overloads 2/3 to formatIntegerPrecision, which never emits locale warnings; this patch and its tests update only legacy FormatWith3Args paths. Reproductions are retained in sql-warning-contract.log.

  • P2 pkg/sql/plan/function/func_builtin.go:4859: Over a three-row table, execute SELECT LN(0) FROM t or SELECT LOG(1,2) FROM t.
    Impact: SHOW WARNINGS and @@warning_count report one warning instead of the required three. Preserve row-level diagnostics through runtime folding and constant-vector fast paths.
    Evidence: Both queries returned three NULLs but warning_count=1; column-based invalid logarithms correctly reported three warnings. Constant invalid STR_TO_DATE also reported only one. Runtime doFold caches these expressions after evaluating length=1, and the logarithm templates independently invoke callbacks once for constant vectors. See sql-warning-contract.log.

  • P2 pkg/sql/plan/function/func_str_to_date.go:80: STR_TO_DATE receives a large invalid string or a valid prefix followed by a large suffix.
    Impact: Formatting the entire input creates input-sized temporary allocations even when diagnostics are discarded. Bound message construction before formatting and avoid constructing unused messages.
    Evidence: The same kernel benchmark with a 2 MiB invalid input measured 216 B/op and approximately 121 ns/op at the merge-base versus 4,211,006 B/op and approximately 296,000 ns/op at this head without a sink. A discard-only WarningProbe showed the same regression. The sink's later message bound cannot prevent these allocations. Logs: base-bench.log and head-focused-and-bench.log.

Validation:

  • Artifacts are retained under /home/xupeng/.local/state/mo-bot/jobs/112b0faad65aee362e0b0f65/attempt-1. validation-ledger.json reconciles commands, source fingerprints, exit receipts, overlays and log hashes; evidence-audit.log passed. Source remained unchanged.

  • Private /tmp and loopback preflight passed. Current native provenance matched retained artifacts and was verified through the repository build owner. A bookkeeping failure after recovery was followed by successful provenance verification.

  • Public SQL check completed: 19 subtests passed and 8 failed on the reported FORMAT/count defects. Receipt: checks/1792138060906731095-146.json; log: sql-warning-contract.log.

  • All 11 focused unit-test roots and the complete vectorize/format package passed. Head/base kernel benchmarks completed successfully with verified base overlays. Short valid STR_TO_DATE inputs retained identical allocation counts.

Limitations:

  • Supplied CI records report success, but contain no raw execution logs; local_validation is empty and linked issue bodies were not supplied.

  • Public validation used one CN. No independent MySQL or multi-CN run was performed. Performance measurements cover kernel cost, not end-to-end throughput.

aptend added a commit to aptend/matrixone that referenced this pull request Oct 16, 2026
…atrixorigin#30373)

Review findings fixed:

1. FORMAT locale warning (P2): the binder routes FORMAT to
   formatIntegerPrecision (integer overloads), not the legacy
   FormatWith3Args path the original patch warned through. Emit the
   ER_UNKNOWN_LOCALE warning (1649) from formatIntegerPrecision for NULL
   and unknown constant/vector locales while keeping the en_US fallback.

2. Folded scalar warning counts (P2): a cached constant result cannot
   represent one warning per evaluated row, so LN/LOG folded to one
   warning across a batch. Generalize the runtime fold guard into
   function.ScalarDiagnosticNeedsRowEvaluation (DIV/MOD preserve matrixorigin#30211
   behavior verbatim) and extend it to LN/LOG/LOG2/LOG10, STR_TO_DATE
   and FORMAT: constants whose single evaluation would warn stay
   non-folded; proven-safe constants keep the fold fast path. LN/LOG
   diagnostics also move out of the value kernels into a shared
   post-pass (npZeroWarn pattern) so NULL operands stay silent and the
   count survives constant-vector fast paths.

3. STR_TO_DATE allocation (P2): appendStrToDateWarning now builds the
   diagnostic lazily only when a warning sink exists, and caps the
   echoed input at 128 bytes, so a multi-megabyte invalid input no
   longer forces input-sized allocations on discard-only evaluation.

Regression: pkg/sql/colexec/compat_warning_folding_test.go verifies
folded scalar LN/LOG/FORMAT constants keep per-row warning counts while
safe constants still fold.
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 16, 2026
@aptend

aptend commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH @mo-bot Pushed 77de298b33 addressing the three findings from the last review. Details:

1) FORMAT locale warning on the canonical binder path (P2)
The binder routes integer FORMAT overloads to formatIntegerPrecision (never to legacy FormatWith3Args), so previous locale diagnostics were unreachable for the common case. Now formatIntegerPrecision emits ER_UNKNOWN_LOCALE (1649) itself for NULL and unknown locales, keeping the en_US fallback value behavior. Unknown constant/vector locales are both covered.

2) Folded scalar warning counts (P2)
The cached-constant fold collapsed N rows of LN(x) / LOG / STR_TO_DATE warnings into one. The runtime guard from #30314 is now generalized into function.ScalarDiagnosticNeedsRowEvaluation and applied in doFold: constants whose single evaluation would emit a diagnostic (logarithm with non-positive/unity args, warning-bearing STR_TO_DATE constants, NULL/unknown FORMAT locale) stay non-folded, so the real batch length carries the per-row warning count; proven-safe constants keep the fold fast path. The DIV/INTEGER_DIV/MOD case preserves #30211 semantics unchanged. LN/LOG diagnostics were also moved out of the value kernels into a shared post-pass walk (same pattern as appendDivisionByZeroWarnings), so NULL operands stay silent and counts survive const-vector fast paths.

3) STR_TO_DATE allocation amplification (P2)
appendStrToDateWarning now short-circuits before building any message when no warning sink is installed, and caps the echoed input at 128 bytes. A multi-megabyte invalid input no longer inputs-scales allocations on discard-only evaluation.

Regression coverage: pkg/sql/colexec/compat_warning_folding_test.go evaluates folded scalar LN/LOG/FORMAT over a 3-row batch and asserts per-row warning counts for warning-bearing constants plus continued folding for safe constants; existing LN/LOG/FORMAT/STR_TO_DATE suites in pkg/sql/plan/function still pass.

@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 review of 247298e against d304047. No blocking finding remains.

All three findings from my previous review are addressed:

  • Diagnostic-producing overloads now declare rowScopedDiagnostics at the existing semantic owner. The shared runtime/direct-evaluation probes preserve per-row diagnostics while warning-free constants still fold; file pruning rejects effectful predicates. The duplicate function-ID prediction switch and duplicate STR_TO_DATE calendar validator are removed.
  • FORMAT bounds the locale before constructing a diagnostic, rejects unsupported lengths before case conversion, and does not copy unknown locale payloads into the formatter. No-sink/count-only paths avoid message formatting. The benchmark allocates its input outside the timed loop and measures the real canonical kernel as well as the helper.
  • NULL locale reports "Unknown locale: 'NULL'"; empty locale remains distinct.

Reviewed all 15 changed files, including production code, unit tests, benchmarks and SQL/result fixtures. Traced the canonical and legacy FORMAT entries, selected-row/NULL logarithm behavior, all three STR_TO_DATE result types, shared folding and external-file admission. The issue's >6-digit %f case follows the same remaining-input diagnostic path. Existing value parsing and warning-budget ownership are reused; no new state machine or execution pipeline is introduced.

The logarithm post-pass returns immediately for a batch without NULL results; invalid rows pay the necessary diagnostic work. No demonstrated material performance regression was found. This is not a claim of zero execution cost for newly required warnings.

Validation: current-head build, UT, coverage, SCA and both enabled BVT jobs pass in run 39050212481. Reviewed the new bound-expression, zero/multi-row, NULL/empty/long-locale, mask, prepared-reuse and retention-limit checks, and the author's reported targeted SQL and allocation results. No additional local test run was performed in this review; the CI log inspected does not independently establish execution of the newly added scalar_compat_warnings.sql fixture.

Approving this revision.

@mergify mergify Bot added the queued label Oct 17, 2026
@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-17 18:05 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-17 19:14 UTC · at 887019c3dc2a19896c03f2a2cd192299a5c1b3db · squash

This pull request spent 1 hour 8 minutes 35 seconds in the queue, including 53 minutes 4 seconds running CI.

Required conditions to merge

Copy link
Copy Markdown
Contributor

独立合并后实测完成,存在确认的新回归,不能称全部通过。

新增问题 #30505:main a8be04735bcf6d2a7aa48d464f76c0b13c691ef5 的FORMAT/STR_TO_DATE新warning producers在128字节echo处切断UTF-8。合法129字节中文或a+32emoji通过实际MySQL后,warning1649/1411含非法UTF-8;两次独立进程每次8子场景,4控制通过、4坏字节断言失败。源码两处byte slicing与原始hex一致;干净旧main d304047724相同6个语句实际无warning。issue有最小SQL、环境/SHA、bytes、影响及查重记录。

main原始ASCII/NULL/行/CASE/prepared/zero-retention组合SQL16事件通过;7完整归属包34098事件通过,11跳过单列;64条警告BVT在真实MySQL逐条与仓库golden行值对照通过(不比较JDBC展示头,不声称mo-tester/全CI资格)。这些通过不覆盖上述Unicode反例。

4.2-dev 35273bcd6a5cfa9468bcf7ca4031fe17560b5ab1 原始FORMAT、LN/LOG、STR_TO_DATE语句仍无warning,实际值正确但诊断断言失败。#30217/#30214/#30213已分别更新分支差异,保持开发处理。新问题 #30505按仓库模板已建并回读确认。

Copy link
Copy Markdown
Contributor

本轮 continue18 当前 main 4226537e5094995155eab9c2a883db649ff7b95b 的两个 CN 实测仍复现 FORMAT(1649)/STR_TO_DATE(1411) 的 UTF-8 截断:126 字节中文对照有效,129 字节中文/emoji 的 warning Message 无效。复用现有 #30505,未新建重复单,开发指派保留。更新证据:#30505 (comment) 。main-sql-final.log 保存 raw hex/断言,生产逻辑未修改;4.2 缺 warning,没有宣称它复现同一 malformed-message 缺陷。

This branch was previously deployed

1 inactive deployment
ci — 6241c0ed Deployed Oct 17, 2026 by mergify[bot]
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/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

3 participants