Skip to content

fix(sql): report malformed integer argument warnings - #30312

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/9bcbdc05d7d8f3c6563484ed14a3128831d9ba553ac0c30fd2f05ce1ff68fa0a
Oct 17, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/9bcbdc05d7d8f3c6563484ed14a3128831d9ba553ac0c30fd2f05ce1ff68fa0a

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 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:

What this PR does / why we need it:

Integer arguments such as REPEAT('x','3x') returned the integer-prefix result while omitting conversion warnings. Emit warning 1292 (Truncated incorrect INTEGER value) from the shared integer-argument conversion boundary and BIT_COUNT's separate text path. Preserve converted values, range errors, binary-string behavior, and existing empty-string handling.

Reuse the existing warning sink and warning-aware constant folding. BIT_COUNT retains its binary fast path and evaluates textual diagnostics only for selected, non-NULL rows. Separate diagnostic effects from value volatility. Warning-isolated planner and runtime probes fold deterministic constants only after warning-free success, preserving CEIL, XML XPath, and percentile constant arguments. Malformed text remains executable for selected-row diagnostics. After real evaluation, structurally scalar diagnostic trees retain constant vector shape through CAST, CONCAT and scalar flow control, including an explicit DECIMAL cast after rebasing onto current main, preserving malformed CEIL/XML constant arguments without caching away warnings. Prepared reuse rechecks each binding. Retain main's row-evaluation ownership for explicit DECIMAL casts and SQL-mode-dependent division. Ordinary expressions retain their existing partial-selection NULL shape. Conservative optimization and diagnostic-ownership predicates remain unchanged. Generated columns, RETURNING, GROUP BY, and numeric/binary folding retain their supported behavior. Text conversion adds a bounded prefix scan without retaining additional state. Non-folded execution checks diagnostic-tree ancestry; cached warning-free values keep their existing path.

Regression coverage checks all reported built-ins, secondary integer positions, column inputs, projection warning counts, inactive branches, and SQL/binary prepared-statement reuse across malformed text, valid text/numeric values, and NULL. FIELD's already-correct DOUBLE diagnostics remain covered. Extend the existing integer-parameter BVT with exact value and warning checks.

Validation after rebasing onto official main c21a102e74590253dad70d86e0f18646b61457ae, on Go 1.27.1 / macOS arm64 with the repository CGo wrapper:

  • Full pkg/sql/plan/function, pkg/sql/plan, pkg/sql/plan/rule, and pkg/sql/colexec suites with -vet=all -count=1: passed.
  • TestBuiltinConversionWarnings and TestStatementInfoDiagnosticCapacitySQL in pkg/tests/dml, through the real frontend with -short -race -tags matrixone_test -vet=all -count=1: passed. Conversion regressions cover selected-row diagnostics, branch selection, generated-column insert/update, RETURNING, constant-only consumers including the explicit DECIMAL cast, and prepared text/XML reuse.
  • Incremental lint for the five affected packages against the official base: passed, 0 issues.
  • Regression probes reproduced missing warnings, deterministic-expression rejection, and valid/malformed text constant-consumer failures before their respective fixes.

The previous-head UT run 38836114410 failed in TestStatementInfoDiagnosticCapacitySQL during connection setup (context deadline exceeded / internal error: AddressFunc). The case passes locally with race enabled; the original timeout remains unattributed and is not claimed fixed. The rebased head needs fresh CI; the old run was not rerun. The local mo-tester harness was not rerun. MySQL 8.0.46 source supports the diagnostic contract; no live MySQL execution or current SQL throughput benchmark is claimed. Issue verification is left to the reporter after merge.

@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 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9214a01640455123c296ce7daead8e65b92086e7

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: 9214a01640455123c296ce7daead8e65b92086e7

Assessment: request_changes

Reviewed the complete seven-file delta. Shared conversion and warning ownership is appropriate, but BIT_COUNT’s new diagnostics are not integrated with runtime folding, causing incorrect warning counts.

Model: gpt-6-astra / xhigh

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

  • P2 pkg/sql/plan/function/func_unary.go:1054: With three rows, SELECT BIT_COUNT('3x') FROM t ORDER BY id returns three values but only one warning. SELECT IF(id=1,0,BIT_COUNT('3x')) FROM t ORDER BY id likewise reports one warning for two evaluated rows.
    Impact: The per-row diagnostic contract is lost for literal inputs. Integrate the warning-producing text overload with diagnostic-aware runtime folding and add frontend tests for constant projections and partially selected branches.
    Evidence: A real-frontend reproduction confirmed one warning instead of three/two; equivalent column inputs produced three warnings, while inactive branches and empty results produced none. evalExpression.go:472-474 protects string-to-numeric CASTs only; evalExpressionReset.go:334-352 folds BIT_COUNT at length one. The added constant_rows unit test bypasses this executor. Reproduction: bitcount-frontend.log and checks/1792084978458242630-4.json in the assigned diagnostic directory.

Validation:

  • Preflight passed. Verified 192 native build inputs and 62 artifact hashes; source remained unchanged.

  • Passed 26 focused function tests and all 23 TestBuiltinConversionWarnings frontend scenarios.

  • Base-production overlay failed the new warning assertions while preserving expected values and controls.

  • Reviewer frontend probe reproduced the finding in two scenarios; column, inactive-branch and empty-result controls passed.

  • Measured valid-text overhead: BIT_COUNT kernel 9.58→18.14 ns/row; integer conversion 18.56→27.01 ns/row. Warm 8192-row SQL medians increased 0.426→0.571 ms for text BIT_COUNT and 0.580→0.705 ms for text ROUND. Numeric and folded-constant controls were roughly unchanged.

  • Commands, source fingerprints, exits and retained logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/a395900db1c269054403d05e/attempt-1/evidence-manifest.json. Complete review coverage is recorded in review-report.json.

Limitations:

  • Supplied exact-head CI reports successful UT and BVT jobs; raw CI logs and individual mo-tester reports were unavailable. Local execution was targeted.

  • The linked issue body was not supplied, and no live MySQL comparison was performed.

  • Benchmarks cover small warm workloads, not production-scale concurrency or throughput.

@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a300322ed7d524af95b3513dedc3ef7cbaafef6c

Review completed. Read the assessment.

@iamlinjunhong
iamlinjunhong force-pushed the codex/loom/develop/9bcbdc05d7d8f3c6563484ed14a3128831d9ba553ac0c30fd2f05ce1ff68fa0a branch from 72c4338 to 445fe00 Compare October 17, 2026 01:56

@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 re-review of exact head 445fe006be874697bc2d1dcf4944b1c428b477d8 against merge base 65bcea5d24610dde1a21bb9f4dea1efd82a8ce50. Read every hunk in all 23 files, the issue/discussion and all previous reviews; traced the increment since the previously approved head together with the full current range. Implementation +149/-41 in 12 files; tests/golden +798/-1 in 11 files; separate docs zero.

No blocking finding remains. Existing conversion and warning owners remain authoritative. Separating value volatility from row diagnostics is justified by actual consumers: generated columns/RETURNING still accept deterministic expressions, speculative folders use isolated warning sinks, and runtime scalar publication happens after selected-row diagnostics execute. No new persistent state, retry machine or diagnostic cache is introduced.

The four prior blocker classes are closed: literal warning cardinality; deterministic-expression admission; valid constant consumers; and malformed constant consumers with selected/empty branches and prepared reuse. The latest main's DECIMAL diagnostic interaction needed fresh verification and passes independently.

Exact-head validation with a matching native build and the repository CGO wrapper, Go 1.27.1/darwin-arm64:

  • Complete TestBuiltinConversionWarnings passes (4.68s).
  • Independent actual-SQL neighbor test passes: cast(bit_count('1023x') as decimal(1,0)) over three rows returns 9/9/9 with six warnings; selecting two rows gives four; inactive/empty branches give zero. Valid text is the nearest zero-warning control.
  • The same binary-prepared statement reused across valid, doubly malformed, NULL, singly malformed and valid bindings returns the expected values and 0/6/0/3/0 warnings, without stale results or diagnostics. Both test roots and package exit 0 (8.338s). Temporary probe removed from the worktree.
  • Reused exact-head CI run 38992970982, latest attempt 2: UT/SCA/build/coverage/enabled BVT pass. Retained UT artifact confirms DML embedded race batches and all planner shards terminate successfully; actual BVT log records integer_parameter_coercion.sql 118/118 and its binary-domain control 47/47. The earlier failed UT attempt is not root-caused or relabeled by this review.

Performance boundary: diagnostics add real text-processing cost. Historical unchanged conversion-kernel measurements remain about 9.6 -> 18.1 ns/row for valid-text BIT_COUNT and 18.6 -> 27.0 ns/row for integer conversion; these are not current-head TP measurements. Warning-free constants still fold, numeric/binary conversion fast paths remain, and there is no new I/O/lock/retained queue. The duplicate prefix scan is an optional optimization opportunity; this approval does not claim zero CPU overhead or measured TP throughput equivalence.

APPROVE. No production changes made during review.

@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-17 05:15 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-17 09:41 UTC · at aa8d4278bdb940fe2e2b50a02fc2d9c5c362c3b7 · squash

This pull request spent 4 hours 25 minutes 50 seconds in the queue, including 58 minutes 20 seconds running CI.

Required conditions to merge

Copy link
Copy Markdown
Contributor

合并后独立实测(2026-10-17,冻结 main ba6b31941074cdaaf906ba2ec3883bc3b3eab85f,Linux/amd64、Go 1.27.1、匹配 make cgo 产物):

独立通过真实 MySQL 协议重跑原 issue 的 9 组 SELECT / SHOW WARNINGS,覆盖 17 个 reported built-ins:返回值保持不变,合计 17 条预期 1292 告警;合法文本/数值/二进制、未选分支及空结果对照无多余告警。#30265/#30271 的显式 CAST 旧复现也通过。

完整 function、colexec、plan/rule、plan 普通回归通过;plan 中两个现有 HNSW/Interval setup 跳过项不计通过。SQL/binary prepared 复用、列输入/NULL、分支选择、XML/CEIL 常量消费者、生成列及告警容量回归实际执行。

本 PR 的原始 DML BVT 不全绿:普通/race 均有 4 个新 RETURNING 子场景在宿主机自动 spill cap=1 下失败。保留原断言,仅对测试夹具明确 64 MiB spill 预算的 overlay 对照,普通/race 各 67 个测试/子测试全部通过。该独立的新夹具问题已建 #30480,指派 iamlinjunhong;生产磁盘保护和生产源码未修改。不能把 overlay 对照说成原夹具已修复。

原 issue 报告的 main 修复范围已验证,按约定转给 @Ariznawlll;新增独立问题继续由其单独 issue 跟踪。

This branch was previously deployed

1 inactive deployment
ci — 749153ee 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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants