Skip to content

[Subtask]: Preserve sound decimal domains and avoid unnecessary wide arithmetic #30840

Open

Description

@aunjgr

Parent Issue

#30838

Detail of Subtask

Validation update — 2026-11-02

Implementation is delivered; current-main focused decimal tests and public SQL BVT pass. Current optimized cast proof calls are outside row loops, and Q1/Q15 selected-kernel/CPU diagnostics have been collected. Overall performance acceptance remains OPEN for the missing SF100/mixed-I/O and other applicable gates. Server129 validation reuses its existing loaded data in place, with no image copy or reload. Queued work is not a measured pass. See the validation follow-up comment for exact source, executable and scoped evidence.

Evidence reassessment — 2026-10-26

Current delivery/performance status: PARTIAL DELIVERY. #30885 and merged correction #30983 address multiplication dispatch. #31034 merged as 22fab00d7d86b3a2100b164f979aa6132c4fd2f9 for intermediate precision and downstream producer correctness; current validation is recorded above. Historical tested candidates are not current-head performance acceptance.

Observed: Historical SF100 Q1 has about 16.40x as many user instructions as DuckDB with similar IPC, and unnecessary Decimal256 casts/products occur in the pinned plan. This supports inspecting representation and proof placement; it does not justify narrowing every decimal value or adding an expensive speculative scalar dispatcher.

Not yet established: Which wide operations remain necessary after current fixes, and whether every producer publishes a sound coefficient domain. Declared metadata alone is unsafe for known legacy carriers or rounding functions that can grow the domain.

Next discriminating experiment: With #31034 merged and its current correctness checks passing, compare current-main native plans, actual selected kernels and absolute CPU/instructions on unchanged Q1/Q15. Audit producer-to-consumer bounds before trusting narrower metadata, including TIME+BIGINT, negative-position ROUND/CEIL/FLOOR, views and prepared execution.

Measured target: Remove demonstrably unnecessary wide arithmetic in Q1/Q15 and report its effect separately from cast hoists and aggregate-state changes.

Mandatory controls and total cost boundary: Scalar/one-row and unknown/wide domains; asymmetric and swapped operands; signed/unsigned/BIT limits; legacy full coefficients; nested rounding; constants/NULLs; masks/tails; prepared reuse and public metadata.

Performance acceptance and rejection

The retained #31034 delivery decision makes per-query TPC-H Q1-Q22 the primary performance gate and explicitly discloses its few-nanosecond single-row expression costs as accepted scalar tradeoffs. Published measurements and controls remain part of the record. This existing exception does not waive query or larger-batch regressions, allocation increases, or unexpected wider-kernel selection; it is not a general regression tolerance for subsequent changes.

  • Freeze current-main/candidate sources, executables, real caller shapes and effective settings. Use the unchanged qualification SQL and complete result consumption; exclude cold runs and keep profiles separate from latency scoring.
  • Demonstrate the named work/CPU reduction and an attributable uninstrumented target-query improvement. Include the controls below and full Q1-Q22 comparison; component wins, source changes, functional tests, SCA, merging and profile percentages are separate evidence.
  • A confirmed affected/control slowdown fails; unresolved slower signals are inconclusive. Confirm with an independent longer balanced run. No gain elsewhere, favorable average or self-approved tolerance waives a regression.
  • Complete applicable SF10/SF100 and memory/mixed-I/O acceptance before issue closure under the umbrella protocol. Report uncertainty, absolute CPU/instructions/work, allocations/copies and the same whole-application budget, effective cache, I/O/spill/swap/pressure evidence. Benchmark scripts do not verify input/table/schema/row counts/reference results/checksums.

Semantics and lifecycle requirements retained

  • A reviewed design defines the logical-versus-physical type contract, proof lifetime and fallback before changing inference or aggregate state.
  • Independent focused tests cover maximum coefficients, mixed scales, negative values, nulls, overflow, rounding, constant vectors and public result metadata.
  • Native plans/physical-kernel traces and PMU evidence show which unnecessary wide operations disappear, with the original qualification SQL unchanged.
  • Measure warmed Q1/Q15 and a wide-range negative control; retain the correct wider path where the range proof fails.

Describe implementation you've considered

Prefer resolving a proven domain at binding/dispatch over rescanning values per row. Retain a cheap conservative wide route for unknown domains. Precisely derived result metadata may change deliberately and must be tested consistently through CTAS/views/protocols; preserve values, scale/rounding, overflow and NULL contracts.

Coordination: #30839 owns cast invariants; #30847 owns aggregate updates. Rebaseline after prerequisite merges rather than pooling their gains.

Additional information

Pinned implementation / plan references

Activity

  1. self-assigned this
    on Oct 22, 2026
  2. added
    severity/s0
    on Oct 22, 2026
  3. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up from PR #30885 head d8938d60dc96e808cfe132aaf9837ce603412864 (static review; I could not run the local suite here).

    I found no confirmed correctness defect in the implementation. One focused test gap remains: the added TestDecimalMultiplyRangePreservesCoefficientAndMetadata uses the same declared width for both operands, while dispatch carries independent left/right range proofs. Please add a compact asymmetric matrix (for example int32×int64, int32×unknown, int64×unknown, and swapped operand order) with an independent result oracle and a wide/fallback control, or point to existing exact-head tests that cover these combinations. This verifies that a proof for one operand never suppresses the required scan for an unproven peer.

    Please keep the performance claim scoped to the evidence: the reported Q1 result is 0.997× (no demonstrated whole-query gain), Q15 is 1.016×, and the single instruction/cycle diagnostic is explicitly not a significance test. The kernel-level results can still support this focused optimization; they do not establish a broader workload speedup.

    Review update — 2026-10-22

    XuPeng-SH submitted APPROVED on the same head d8938d60dc96e808cfe132aaf9837ce603412864. The review reports 14 supplemental dispatcher scenarios covering mixed operand domains, constants, NULLs, selection, empty batches and overflow, and concludes that no actionable coverage issue remains. This addresses the earlier request for asymmetric operand proof coverage according to the reviewer’s reported validation; I did not run those scenarios independently. Their review also limits whole-query performance conclusions: Q1 showed no demonstrated gain, Q15 a modest gain, and the PMU diagnostic is not a significance test.

    I inspected the PR file list and latest commit: the PR covers the decimal multiplication proof helper, dispatcher wiring, range tests and design doc; the latest commit itself only updates the design doc’s baseline after #30880 merged. No new finding identified. The exact-head combined status is empty; the only returned workflow is unrelated Iceberg Connector E2E (success). This workspace has no MatrixOne checkout or Go runtime, so I could not run the suite.

    Issue #30840 remains open and assigned to aunjgr; no state or assignee change. The prior test-gap note is superseded by the same-head approval and its reported supplemental tests.

  4. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Supplemental Decimal256 SQL correctness challenge for merged PR #30983

    This adds real SQL coverage for asymmetric operand widths and batch/mask boundaries raised in the prior review note. It is correctness evidence only; I did not run a before/after performance benchmark.

    • Target merge: da7b24205ec9b233e48bf030d2f679b6d4407a88.
    • Owned single-node service binary: source 6f773c556d4f3177f5373eb193cd576e080b662f, SHA256 51489b59a60310e79eddcf1182c582685b2c60f800f35a0a625eb5359469349b. The tested function files arithmetic.go, arith_decimal_fast.go, arith_decimal_wide_test.go, decimal_multiply_dispatch_test.go, and decimal_multiply_range_test.go are byte-identical at pinned main 0abc1d317aea608f3a228297d68e1ae4e619a3a2; no 0abc runtime build was made.
    • Asymmetric DECIMAL(9), DECIMAL(18), DECIMAL(39), and DECIMAL(64) products, including swapped operands and scalar multiplication, matched independent Python integer results.
    • A 257-row/tail batch, filtered scalar multiply, NULL propagation, CASE-generated NULL masks, constant multiplication, and DECIMAL(40,20) × DECIMAL(40,15) CTAS metadata/value all matched their oracles; the CTAS product was DECIMAL(65,20).
    • A filtered query over a value whose product overflows returned zero rows without error. Evaluating it produced error 1690, and the same connection worked afterward.
    • Temporary database cleanup was verified by readback.

    The broader performance acceptance remains unmeasured by this run. Issue #30840 remains open and assigned to aunjgr; assignment unchanged.

    Evidence: /workspace/qa-challenge/validation-main-6f773-30983.json.

  5. changed the title [-][Subtask]: Select range-proven decimal arithmetic kernels while preserving SQL precision[/-] [+][Subtask]: Preserve sound decimal domains and avoid unnecessary wide arithmetic[/+] on Oct 25, 2026
  6. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA status for merged #31034 (22fab00d7d86b3a2100b164f979aa6132c4fd2f9): git diff --check passed, but no current-head function/planner, prepared SQL, catalog/DUMP or benchmark was run in this environment; resource headroom under the existing guard is insufficient for a safe large link or service build. The PR's author-reported correctness and SF10 measurements are separate evidence, not local results here.

    The issue's delivery plan explicitly retains the current-main Q1/Q15 native-plan and selected-kernel comparison plus producer-domain audit after #31034; the earlier asymmetric-operand review request in #30840 (comment) was superseded by its recorded review update. Keep the existing owner for the remaining performance follow-up; no measured regression or current correctness failure is inferred.

  7. aunjgr commented on Nov 2, 2026

    @aunjgr
    ContributorAuthor

    Validation follow-up — 2026-11-02: #31034 is merged; issue stays OPEN pending remaining performance acceptance.

    #31034 merged as 22fab00d7d86b3a2100b164f979aa6132c4fd2f9. Its current domain/physical-width tests, planner/prepared/rounding tests and public SQL cases pass. The contract is precise inference with conservative fallback, not unconditional removal of Decimal256: DECIMAL(15,2) * DECIMAL(15,2) has a Decimal128 result (30,4), while price * (1-discount) retains the full integer-literal domain and yields Decimal128 (37,4). Genuinely wider tax products and existing SUM headroom still use the correct wider carrier.

    Current Q1 callchains reach both d128Mul through the Decimal128 batch arithmetic path and d256Mul through decimal256Multiply; Q1/Q15 also reach d64MulInline through the explicitly guarded decimal multiply/subtract aggregate executor. These are observed selected-kernel paths. They are not a per-expression call count or proof that every remaining wide operation is unnecessary. Fresh SF100 native-plan/CPU evidence is queued separately; the current-main profile includes other merged optimizations and cannot attribute their combined improvement to this issue.

    Reuse the separately controlled local SF10 #31034 evidence: six balanced normal-source process triplets, full Q1-Q22, cold excluded and profiling separate. Q1 ordinary main -> shipped candidate medians 1.445703 -> 1.319379 s, paired -9.04%, ratio interval [0.9034, 0.9245]. Under fixed alignment the precision-only paired change is -8.42%, interval [0.9011, 0.9361]. Q15 remains inconclusive. The isolated #30983 dispatcher campaign has no confirmed whole-query Q1/Q15 gain; do not present its component win as one.

    Current-main validation snapshot: be8eb40ad8bb7b35cbd3c1f50a5a6d23e1f6da1e. Normal release build, Go 1.27.1, GOAMD64=v3, GOEXPERIMENT=simd, no source overlays/PGO. Executable SHA256: 0f4f07c1d39b32e08dcd0c100531cb50843500d74ae6380bd3704a7596647aae. This is current-code correctness/kernel evidence, not a before/after latency comparison of all changes merged since the original fixes.

    Focused function/planner/Substrait decimal tests pass (483 named top-level tests in the selected output, including producer-domain, legacy carrier, scale/rounding, prepared-execution and precision controls). SQL BVT passes 450/450 distinct statements on each of two same-instance runs: decimal intermediate precision 58, decimal multiply/subtract 18, casts 374; zero failures/ignores. The owned service stopped cleanly with SIGINT. These are semantic tests; the benchmark worker performs execution/draining only, with no input/table/schema/row/reference/result/checksum verification.

    Separate warm CPU/PMU diagnostics, 16 completed calls/query after the selected cold call was excluded:

    Query Whole-application CPU seconds/call User instructions/call Conservative whole-application peak, GiB
    Q1 6.746071 155,514,649,774 7.448
    Q15 1.672838 23,689,671,853 6.891

    Both local SF10 profiles satisfy the existing all-memory gates: eight physical application CPUs, 16 GiB effective CN SHARED cache, 32 GiB whole-application budget including native image/pinned software, zero measured physical reads/writes, spill, swap, OOM, major faults, direct reclaim and measured memory-pressure stalls. Profiling is separate from scored latency. Raw PMU counts include the measured application process scope; sample percentages are user-space diagnostics, not savings estimates.

    Server129 already retains the loaded SF100 database. The revised runner reuses it in place, sequentially, with no image/data transfer, copy or reload. It uses all 64 CPUs, a 200 GiB application / 192 GiB CN cache all-memory context and a 32 GiB / 16 GiB warm disk-backed context; actual I/O is recorded. A warm run is accepted as all-memory only if measured physical I/O/spill/swap are zero. Tiny configuration and diagnostic-output files are separate from the database. PSI availability limitations remain explicit.

    The queued SF100 work is currently waiting for a quiet resource window; no benchmark service has launched. These queued jobs supplement the isolated #30981/#30983 Q1/Q15 evidence and current-main kernel/plan evidence. They do not claim that #31034's SF100 effect, every full-suite/context requirement or this issue's complete performance acceptance has already passed. A resource-rejected arm is retained and is not silently staged or relabeled.

  8. XuPeng-SH commented on Nov 2, 2026

    @XuPeng-SH
    Contributor

    QA handoff — decimal-domain implementation delivered; performance acceptance pending

    #31034 is merged into main as 22fab00d7d86b3a2100b164f979aa6132c4fd2f9, following the multiplication-dispatch correction #30983 (da7b24205ec9b233e48bf030d2f679b6d4407a88). This transfers the implemented decimal-domain subtask for QA verification, not the broader #30838 umbrella and not acceptance or closure.

    The 2026-11-02 validation update and current issue introduction explicitly report implementation delivered. They now record producer-domain/physical-width, planner/prepared/rounding tests and public SQL coverage, plus actual Q1/Q15 selected-kernel callchains on be8eb40ad8bb7b35cbd3c1f50a5a6d23e1f6da1e. This supplies the current-code evidence absent from the earlier retention note. The older asymmetric-operand test request was already superseded by its same-head review update and subsequent SQL challenge; it is not an unfinished development request. No current verified correctness counterexample or outstanding code change was identified in the complete discussion.

    Evidence and limits: this round verified remote merge state, fix scope and all issue comments; no local test or benchmark was run here. The author reports 483 focused named tests and 450/450 SQL statements on each of two runs. Historical isolated #31034 SF10 measurements report Q1 improvement; Q15 remains inconclusive, and #30983 has no confirmed whole-query Q1/Q15 gain. These are attributed reports on their recorded builds, not new tests of the present main SHA and not additive gains from all intervening optimizations.

    Remaining QA scope: verify sound producer-to-consumer domains and conservative wide fallback with asymmetric/swapped operands, legacy full coefficients, TIME/BIGINT/BIT, nested ROUND/CEIL/FLOOR, NULL/constants, masks/tails, views/prepared execution and public metadata. Retaining genuinely wide Decimal256/SUM carriers is intended, not itself a failure. Complete the applicable SF100, mixed-I/O and full-query performance gates using pinned sources/binaries, unchanged SQL, independent result checks and whole-application resource accounting. Fresh SF100 native-plan/CPU work is queued, not measured; current profiles do not prove every wide operation unnecessary or attribute combined gains to this subtask. Resource limitations and unmeasured acceptance do not themselves block QA handoff.

    Handing to @Ariznawlll as the sole assignee for validation. Keep the issue open until its own acceptance criteria are met; no 4.2 backport requirement is introduced.

  9. aunjgr commented on Nov 2, 2026

    @aunjgr
    ContributorAuthor

    SF100 validation coverage follow-up

    The initial queued target checks covered #30981 and #30983 but did not isolate #31034. I corrected that gap before any benchmark arm started. The SF100 queue now also includes six balanced process triplets in each resource context, using:

    Build Source Alignment Purpose
    Original main 28e8760905a7f39dba2ce436357ea75492f30512 Normal committed policy Shipped-change baseline
    Same main same source/tree Explicit 64-byte diagnostic link policy Isolate alignment from precision
    Precision change 317c769e03e832c2a226c3339fe8e385ab123ff3 Committed 64-byte policy Isolate precision and measure the delivered change

    These are normal clean-source builds with source-bound native artifacts, matching the completed isolated SF10 experiment; no Go source overlay or stacked candidate. Each timed process excludes its first selected cold calls and executes three warm Q1/Q15 calls. Separate native-plan and CPU/PMU captures cover the corresponding builds. The existing loaded SF100 database is reused directly; no dataset/image copy or reload is scheduled. All 64 CPUs and the original memory/cache/resource gates remain in force.

    The current-main source audit finds the six selected multiplication/result-width helpers unchanged from the tested precision source. The domain helper additionally handles BOOL as the exact 0/1 domain; current decimal/integer/BIT branches remain intact. All five corrected cast loops are unchanged from #30981; their proof helper now calls the shared function with the same 18/38/76 limits. This supports scoped evidence reuse and does not assert whole-binder or whole-executable equivalence.

    The issue checklist now records the already-reviewed design and the passing focused semantic tests. I also made the retained #31034 acceptance policy explicit: TPC-H is the primary indicator, and its disclosed few-nanosecond scalar costs remain an accepted tradeoff. The existing publication retains the exact samples, uncertainties and unchanged allocation counts. Query/batch regressions, allocation increases and unexpected wider execution still fail; the old scalar results will not be rerun or relabeled.

    No SF100 performance result is claimed by this update. The server has unrelated active MO workloads, so measurement still waits for a quiet window. The issue remains OPEN pending the remaining acceptance evidence.

  10. Ariznawlll commented on Nov 16, 2026

    @Ariznawlll
    Collaborator

    QA 验证补充:decimal 域功能正确性已验证(性能验收门仍未完成,issue 保持 OPEN)

    测试版本

    功能验证(SQL 黑盒 + CTAS/view/prepared 元数据)

    交付的精确推断 + 保守回退契约逐项核对通过:

    1. DECIMAL(15,2) * DECIMAL(15,2):CTAS 元数据为 decimal(30,4)(Decimal128,非无条件 Decimal256),乘积值精确(含 99999999999.99² = 9999999999998000000000.0001)。
    2. 字面量折叠:price * (1 - 0.5) 推断为 decimal(16,3)(0.5 的精确域),值 61.725。
    3. 列操作数保守回退:price * (1 - discount)(discount 为 decimal(15,2) 列)推断为 decimal(37,4),与交接契约逐字一致,值 61.7250。
    4. 真正更宽的乘积:DECIMAL(18,6) * DECIMAL(20,10) 保留更宽 carrier,tax * big_mul 值精确(如 999999.999999 * 9999.9999999999 = 9999999999.989900000000)。
    5. 四次连乘 price^4 超出 Decimal128 时正确回退更宽路径,结果精确到 ...0000.00000001。
    6. 除法混合 scale、SUM 聚合 headroom、round/ceil/floor(含负位置 round)、NULL 传播、prepared 复用、view 元数据全部正确。

    白盒核对

    核对 #31034 的 producer-domain 推断与保守回退路径(decimal_intermediate_precision_test.go 同族覆盖),以及 #30983 乘法分派修正;未发现功能反例。

    Go 单测

    TestDecimal|TestArithDecimal(pkg/sql/plan/function,含 domain/physical-width 测试)本地 ok(1.35s)。

    回归测试

    SQL 级功能契约已固定到 matrixorigin/motr#349:14_issue_regression/issue_30840_decimal_domain(37 语句,含 #30839 的 cast 契约),与既有 issue_30840_decimal_domain_controls(TIME+BIGINT 域边界)互补、库名隔离。PR 4 项 CI 全部成功,用例标记 @target-branch: main。

    验证边界(保持 OPEN 的原因)

    本次仅完成功能正确性与 SQL 可见元数据契约验证。本子任务所属的 #30838 umbrella 验收协议要求的 TPC-H SF10/SF100 Q1/Q15 及全 Q1–Q22 对照、mixed-I/O/内存预算、PMU/CPU/指令数归因、分配与拷贝预算均未在本地执行——这些需要在具备基准环境的机器上按既定冻结源/二进制/平衡运行协议完成。功能通过不等于性能验收通过,issue 维持 OPEN,待性能验收数据补齐后再评估关闭。

  11. Ariznawlll commented on Nov 18, 2026

    @Ariznawlll
    Collaborator

    Note

    QA 性能面补充验证:大数据量真机基准已实测(main 517e169538),功能面此前已通过。本 subtask 的可测性能证据已交付;最终"目标倍数"裁定权在研发/负责人,QA 证据供其引用。保持 OPEN 至父项策略裁定。

    QA 补充:大数据量真机基准(#30839 cast invariant hoist / #30840 decimal 域)

    此前功能面验证(2026-11-16)已通过。本.comment 补性能面证据。

    测试环境

    • main 隔离实例 517e1695388cbaf1135238d5ab0c19a4556fb551(git_version() 实测确认),1 LOG / 1 TN / 1 CN,Darwin arm64 8 核 16GB。
    • 数据集:qa_big.lineitem 5,498,998 行(1M 订单、DECIMAL(15,2) 价量),partsupp 800,000 行 ⋈ part 200,000 行。

    大数据量计时(warm 1 + 3 轮,取 best)

    工作负载 触及修复路径 结果
    5.5M 行 l_extendedprice * l_quantity 乘法 + 全量 GROUP SUM(三组,组值达 4.06e12,超 DECIMAL(15,2) 单行域宽——域拓宽分派正确) #30840 sound domains / #30839 cast hoist best=0.131s,三组值与真值一致(A 1.157e12 / B 1.159e12 / C 4.055e12)
    1M 组 shuffle 聚合 group by l_orderkey + sum(price*qty) 同上 best=0.139s
    白盒:pkg/sql/plan 定向 219 项 Decimal/Cast 单测 #30839/#30840 代码路径 全部 PASS(ok 1.75s,0 FAIL)
    白盒:aggexec(聚合执行核心)全包 #30840 PASS(3.17s)

    结论

    • 大数据量(550 万行)下 decimal 乘法+聚合、百万组 shuffle 聚合均在亚秒级完成,结果精确;此前功能面已证明精确推断/保守回退契约。性能面证据:Load 下无法对照修复前版本(修复 PR 早早合入且父项要求 SF10/SF100 专机对照),本基准作为当前 head 的实测性能记录,供研发对照其历史 SF10 数字评估是否达成目标。
    • 无回归、无 panic、无精度丢失(4e12 量级总值仍精确表示)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/subtaskseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions