Skip to content

docs: correct embedded Sirius numeric semantics - #29449

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
aunjgr:feature/28968-exact-numeric-design-v2
Sep 29, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
aunjgr:feature/28968-exact-numeric-design-v2

Conversation

@aunjgr

@aunjgr aunjgr commented Sep 28, 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:

Refs #28968 and #28966. This design amendment does not enable exact-numeric offload or close either issue.

Review notes

This design-only amendment resolves the later #29210 review and two exact-head findings on this PR. Please review design blob 42a89f09a1d168d02b9583cb3ea7b4de6dbb5634 at head 78c587bb0b04c2ee9426d31a56085cbb781e6d6e before numeric production code begins.

The scalar-versus-aggregate correction preserves distinct MO public error classes with two typed C statuses and operation-owned mapping. The new division correction removes the obsolete fixed-scale rule: MO binds precision, scale, physical type, and operand casts from div_precision_increment before export; Sirius validates and executes at that serialized result type, without a runtime session carrier or independent type inference. The differential matrix now covers increments 0/4/10/30, prepared execution after setting changes, scale-30 cap below the left input scale, and precision cap. The reviewed 512-bit multiplication, Decimal256 precision, SELECT-only admission, and fail-closed cast scope remain intact.

XuPeng-SH ran the relevant MO division type/execution tests and inspected the public issue_28594_div_precision BVT at the previous head. The fresh-main merge for this head changed only unrelated fulltext files; division owners and these oracles are unchanged, so that source-level evidence remains applicable. The Q1-Q22 exporter inventory passed on the prior base. A local inventory rerun on the intervening head stopped before tests because the shared checkout held GPU native artifacts from the bridge branch; it is not counted as a pass or failure. Fresh PR CI owns the current-head check. No production code or test oracle changed. The MO-reader-only parent design in #29209 still requires separate exact-revision approval.

What this PR does / why we need it:

Correct the embedded Sirius exact-numeric design to match MatrixOne multiplication, division, and SQL-visible error semantics, and define SELECT-only admission plus a versioned native capability before implementation.

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

@mergify mergify Bot added the kind/documentation Improvements or additions to documentation label Sep 28, 2026
@matrix-meow matrix-meow added the size/XS Denotes a PR that changes [1, 9] lines label Sep 28, 2026

@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 · d83b71f

范围:base d99187d7b3bfda8744088b3ae8cf16739b690aa0 → 当前 head,完整阅读唯一变更文件及相关 MO 标量、聚合、exporter 和前端错误消费者。未使用 subagent。

结论:REQUEST_CHANGES;numeric design v2 暂不批准。 这是设计契约阻塞,不是声称这个 docs-only PR 已引入线上执行回归。

[P1] 聚合溢出不能复用标量的统一 OutOfRange 映射

见行内评论。独立真实 MySQL 协议测试在当前 head 上确认:

  • 表中存放 DECIMAL(65,0) 最大正值(65 个 9)与 1;SELECT SUM(v) 返回 20301 / HY000(ErrInvalidInput)。
  • 同一最大值执行 v + CAST(1 AS DECIMAL(65,0)) 返回 1690 / 22003(ErrOutOfRange)。
  • SUM(v) WHERE v > 1 与最大值加零两个最近正常对照均返回完整的 65 位最大值。

根因不是字符串差异:sumavg2.go:validateDecimal256SumResult 直接产生 ErrInvalidInput,聚合 Flush 不经过 decimalBatchArith。后者对标量的错误转换不能推广到整个 v1 family。当前 §5 指定所有 declared-precision failures → status 12 → ErrOutOfRange,会使 Sirius 的 SUM 和 MO 在公开错误码/SQLSTATE 上不同,违反 §1,且 §6 要求的错误等价无法通过。

建议按已准入的标量/聚合/转换签名明确公开错误分类,让 native typed error carrier 能保留这些区别;不要从 message 推断,也不要为了 offload 在本 docs PR 隐式改变 MO 的既有 SQL 行为。若要统一 MO 公开错误类,应另行批准其兼容性变化,再更新本契约。

设计与历史问题复核

  • 旧 #29210 的 raw-product >256 位问题:512-bit scratch → 单次缩放舍入 → 最终物理/声明精度检查的修订与当前 MO 路径一致。
  • 旧 Decimal256 除法精度问题:当前调用 decimal256BatchArith,新的描述已对齐。
  • SELECT-only admission / DML、IGNORE 上下文:把 DML 排除在准备/读者启动前是合理范围收敛;不需要为未支持的 DML 先增加通用上下文框架。
  • 错误 carrier:标量部分有所修正,但上述聚合反例说明尚未完整关闭。
  • 固定宽度 representation、完整签名协商、准备前拒绝、运行中不 replay 的方向合理;没有理由为此引入 float/narrowing/fallback。内存/GPU/性能仍是后续实现验收,不由 docs CI 或本次 native-MO probe 证明。

验证范围

新增私有 reviewer probe TestReviewerNumericErrorContract,走隔离 embedded 集群的真实 SQL/MySQL 协议;确认测试 -count=2 全部通过(即两次均确认上述不同错误码),同一服务重复创建/清理 QA 库。初次探索对 generic error 的 wire code 预期为 1105,实测 20301 后按前端映射确认并修正探针;不把初次失败隐去或当成产品测试通过。

Darwin/arm64 Go 1.26.4,当前 head Go 源码,复用源码输入一致且 provenance 验证通过的 native 库。未修改 PR 生产代码。私有证据:/private/tmp/mo-review-29449-29393-fJeHAY/numeric-confirmed.log。文档 CI 通过,但生产测试为 skipped,不据此宣称 native Sirius parity 已验证。

Comment thread docs/design/sirius-numeric.md Resolved

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

Design re-review of head 509b675bf4cfa19f59135a7d03242eb36b458827, design blob 30702075a6a5640e4c88ada701d67d1cd966524b, against declared base/merge-base 1ded9fc914803cb2ffc1215be353703d640b3f02. Read the complete numeric design and sole-file diff, its parent contracts, prior review/reply, and the relevant MO binding, arithmetic, cast, aggregate and native ABI consumers. No subagents.

Decision: REQUEST_CHANGES — the overall architecture is reasonable, but this exact design revision still has one blocking semantic contradiction: its division type/scale rule is obsolete. See the inline finding. This is a design approval blocker, not a claim that this documentation-only PR has changed production execution.

Architectural judgment

  • Keep the MO bound plan as the sole authority for physical width, precision, scale and nullability. A versioned exact-decimal extension is justified by MO's wider domain and observable differences from generic decimal coercion. Using the same type across expressions, grouping, comparisons and results avoids incompatible conversions inside one expression closure.
  • Fixed-width coefficients, bounded scratch and no per-row host callbacks are appropriate. The 512-bit multiplication scratch fixes a real intermediate-overflow boundary without introducing arbitrary-precision objects per row. It must round once at the selected result scale.
  • Keep pre-reader validation, explicit capability rejection and terminal execution errors. The added numeric error statuses fit the existing ABI's typed status mechanism; a separate exception framework or message parsing is unnecessary.
  • SELECT-only admission and explicit restrictions on cast modes are a sensible finite scope. The complete advertised family must still be implemented and validated before setting its capability; individual kernel progress is not permission to advertise full support.
  • The performance contract identifies fixed-width buffers, charged aggregate state and kernel/end-to-end measurements. It does not prove GPU throughput, occupancy or spill performance today. Those remain implementation/rollout gates. Approval of this numeric document would also not substitute for the separately revised embedding parent design's review.

Previous findings

The previous scalar-versus-aggregate error-class finding is resolved in the design: status 12 preserves scalar ErrOutOfRange, status 13 preserves checked SUM/AVG and normal exact-decimal cast ErrInvalidInput, and the failing operation retains ownership even inside an aggregate. The relevant arithmetic/cast/aggregate owner implementations are unchanged from the previous reviewed head, so the prior real-MySQL error-code evidence remains applicable. The new ownership counterexamples are useful.

The prior 512-bit multiplication, Decimal256 final precision check and SELECT/DML admission corrections are also retained coherently. The remaining division-rule finding is separate; the earlier review did not catch it.

Verification

  • At this head, locally ran and passed TestDecimalDivisionTypeUsesPrecisionIncrement, TestDecimalDivisionExecutionUsesBoundResultScale, TestDecimal256DivisionExecutionUsesBoundResultScale, TestDecimalDivisionScaleCapBelowInputScale, and TestDecimal256DivisionDeclaredPrecision. These directly establish the contradiction, including session settings, bound-scale execution and the scale-30 cap.
  • Independently reran TestTPCHNumericEligibilityInventory: all 22 subtests selected and passed, confirming the documented 8 eligible / 14 declined baseline on this head. These are exporter outcomes, not successful execution of all 22 queries on Sirius.
  • Darwin/arm64, Go 1.26.4, count=1, CPU native artifacts with verified provenance and unchanged native build/source inputs. Diff whitespace check passed; the isolated worktree has no source edits.
  • Exact-head documentation CI is successful; production CI jobs are skipped. No GPU or full SQL parity claim follows from that result.

Please update the division contract and its oracle to consume MO's already-bound result type. This should remain a focused design correction; no extra session carrier or independent native type-inference subsystem is needed.

Comment thread docs/design/sirius-numeric.md Resolved

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

Design re-review · 78c587bb0b04

APPROVE the numeric design revision 42a89f09a1d168d02b9583cb3ea7b4de6dbb5634. Reviewed the complete document and sole-file PR diff against base/merge-base e6e3af58ce5693c33517b4e85bf51d0bc609b7b8, both previous findings and author replies, the relevant MO owners, and the referenced embedding ownership/resource contract. No subagents.

Both prior substantive findings are resolved in this design:

  • Scalar versus aggregate errors remain owned by the failing operation. Native statuses 12/13 preserve ErrOutOfRange versus ErrInvalidInput, including a scalar or cast failure inside an aggregate; the bridge does not infer error classes from message text or outer query shape. The earlier aggregate thread is still marked unresolved in GitHub, but its technical issue is closed by this revision.
  • Division now consumes MO's already-bound result type, operand casts, precision and scale. Sections 4.1/4.4/6 agree with decimalDivisionReturnType, applyDivPrecisionIncrement, the AtScale execution kernels, and the declared-precision check. The old fixed-scale formula and scale-eight example have been removed. The counterexamples include increments 0/4/10/30, a scale cap below the input scale, precision cap, and prepared execution after setting changes. A second native session carrier/type-inference subsystem is unnecessary.

The retained design choices are coherent and proportionate:

  • One versioned exact-decimal type throughout an admitted expression closure preserves width/precision/scale/nullability across scan, arithmetic, comparisons, grouping and result publication. The proposed extension is justified by MO's wider domain and observable differences from generic decimal coercion.
  • Fixed-width 512-bit multiplication scratch permits a raw product wider than 256 bits when the once-rounded final result fits; physical and declared-result overflow remain distinct boundaries. This avoids arbitrary-precision allocation per row.
  • SELECT-only admission and the restricted cast/negation signatures provide a finite contract. Unsupported modes and malformed signatures fail before readers; execution failures remain terminal, with no replay or fallback after admission.
  • Typed errors and bounded buffers reuse the parent ABI/lifecycle model. Numeric state is charged to existing admission/spill limits; cancellation and cleanup remain owned by the parent query lifecycle. A full capability is advertised only after its complete signature family is implemented and validated.
  • The alternatives and staged rollout are explicit. Kernel/query performance measurements, exact SQL metadata/error parity and GPU evidence remain implementation acceptance gates; this document's approval does not claim those results already exist.

Evidence reuse is deliberate: since the previous reviewed head 509b675bf4cf, only this document and unrelated fulltext files changed. The division/cast/aggregate owners, test oracles, and exporter inventory relevant here are unchanged. I verified and reused the prior five passing division type/execution/precision tests, all 22 selected inventory subtests, and the earlier real-MySQL scalar/aggregate error-code probes. I also inspected the existing public division BVT's session-setting and prepared-execution controls. No unrelated package rerun was needed for this documentation-only change. Current-head documentation CI and diff whitespace checks pass; skipped production jobs are not runtime validation.

This supersedes my previous numeric-design REQUEST_CHANGES. It does not approve the separately revised #29209 embedding parent, enable exact-numeric production lowering, or close #28968/#28966. Implementation PRs must pin this exact approved design revision and satisfy its native, public-SQL, GPU, resource and performance gates.

@mergify mergify Bot added the queued label Sep 29, 2026
@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-29 01:30 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-29 01:31 UTC · at 087000434fedf24aaa7f0b2192c34c2aaaf3a9e8 · squash

This pull request spent 1 minute 2 seconds in the queue, including 46 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation Improvements or additions to documentation size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants