Skip to content

fix: support Decimal256 RANGE window bounds - #28825

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issues-28765-28766-28771-28776-decimal
Sep 20, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issues-28765-28766-28771-28776-decimal

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 13, 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:

Closes #29168
Closes #28765

Follow-up to #28765, #28766, #28771, #28776: the original exact-decimal work
already landed on main through #28830. This PR now contains only the remaining
Decimal256 numeric RANGE gap identified in review, rebased onto that implementation.

What this PR does / why we need it:

A wide exact literal in ORDER BY promotes numeric RANGE bounds to Decimal256.
The scalar plan literal has no Decimal256 variant, so folding previously published
a nil literal and execution reported a missing prepared parameter. Prepared
execution and RANGE searches also lacked Decimal256 support.

  • Preserve exact constant/prepared bounds using the existing singleton vector
    literal encoding; retain decimal protocol provenance through copying/serialization.
  • Validate finite non-negative, non-NULL bounds and use checked 256-bit arithmetic.
    Overflow maps to an insertion boundary instead of wrapping.
  • Handle ASC/DESC, peers, NULL keys, empty frames, and constant-vector singleton
    partitions without indexing physical storage with a logical row number.
  • Reuse existing per-execution frame ownership/reset; no new cache, global state,
    protocol field, persistent data, or optimization path.
  • Preserve original PR protocol-floor regression coverage not yet on main;
    existing decimal BVT files already landed unchanged and are not duplicated.

Validation

Base 5e1e93ae35efc6eea54ae2935f68154493d6e95c, Linux amd64, Go 1.26.4.
Final reviewed tree: b3d42f5fe7441e96a03e1521690a1e2e963c4eb7.
Native provenance verified against primary worktree artifacts rebuilt from the
same native inputs. The initial public reproducer failed on the #29121 candidate
with identical main decimal/window sources; not claimed as a clean-main binary run.

  • Owning packages: PASS (window 2.134s, planner 6.115s), including prepared
    error/reuse, physical overflow, constant partitions and zero-allocation assertion.
  • Preserved protocol-floor and copy/serialization test delta: PASS (0.056s).
  • Incremental SCA: PASS, exit 0 (./pkg/sql/colexec/window ./pkg/sql/plan),
    golangci-lint 2.6.2 built with Go 1.26.4 and repository .golangci.yml.
  • Normal-comparison BVT on an owned, fresh single-CN deployment: PASS twice on
    the same instance, 76/76 each, exit 0, zero failed/ignored/abnormal statements.
    New Decimal256 case 24/24 plus signed integer 15/15, uint64 15/15, temporal
    RANGE 22/22. Hand-calculated oracles; no genrs. Final fixture schema residue 0.
  • Supplemental targeted race: PASS (1.309s), -race -count=1 -timeout=180s -run TestDecimal256Range ./pkg/sql/colexec/window. No new goroutine,
    synchronization, shared mutable state or timing contract; no whole-repository
    race/stress claim. Allocation correctness was also checked in normal mode.
  • GPT-6 (gpt-6-astra, medium) design and independent review found and closed
    the constant-vector indexing counterexample; final exact-commit independent
    source/evidence review: APPROVE.

Risks and rollback

Shared RANGE wrapper changes are covered by existing non-Decimal256 regressions.
Decoder accepts only the bounded singleton encoding produced by the current
vector serializer; malformed/type-mismatched payloads return errors.
Rollback is code-only and restores the unsupported behavior; no data migration.
Single-CN local validation; distributed compose/proxy execution remains CI coverage.

@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

Copy link
Copy Markdown
Contributor Author

Description

VAR_POP, VAR_SAMP, STDDEV_POP, and STDDEV_SAMP accept a DECIMAL256
argument during type checking but the aggregate executor has no
DECIMAL256 implementation. A reachable SQL query therefore panics while
constructing the executor instead of returning the numeric result (or a
documented error).

Minimal reproduction

CREATE TABLE decimal256_variance_repro (
  v DECIMAL(65,30)
);
INSERT INTO decimal256_variance_repro VALUES
  (CAST('12345678901234567890123456789012345.123456789012345678901234567890'
        AS DECIMAL(65,30)));
SELECT VAR_POP(v), VAR_SAMP(v), STDDEV_POP(v), STDDEV_SAMP(v)
FROM decimal256_variance_repro;

The same failure is exposed by a wide unquoted decimal literal after the
literal-preservation change in #28825. The current main path is not a flaky
test: mysqlNumericAggTypeCheck treats DECIMAL256 as a supported numeric
aggregate input through SumSupportedTypes, while
pkg/sql/colexec/aggexec/vardev2.go:makeVarStdDevExec handles only
DECIMAL64 and DECIMAL128 and panics in its default branch.

Expected behavior

Every accepted DECIMAL256 input must execute without a panic and preserve
the aggregate's documented numeric semantics. If Decimal256 is intentionally
outside this aggregate's supported domain, binding must reject it with a
normal SQL error instead; type checking and executor construction must not
disagree.

Scope / regression coverage

Cover all four aliases/functions, ordinary and grouped execution where
applicable, NULL and a single value, positive/negative values near the
Decimal256 boundary, and prepared/runtime Decimal256 input. Keep the fix at
the shared aggregate type/executor boundary rather than changing individual
BVT expected rows. #28825 should remain focused on preserving unquoted
literal precision and can be revalidated after this base fix lands.

Fixes a base contract exposed by #28825.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

CI triage and rebase update:

The failed wide-decimal BVT was a real base defect, not a defect in this PR's literal-preservation implementation: accepted DECIMAL256 inputs reached variance/stddev executors without a Decimal256 implementation and panicked. I opened #28838 and it was fixed by #28841, now merged into main (be30a70fe5).

This PR remains focused on preserving wide unquoted decimal literal precision. I rebased it onto current main (a72a224ce8) without changing its scope; the updated head is 9219ddf7cd6034bb8c2dd58d055db7deb503f82a. The original base failure should be revalidated by the new CI against the merged fix; no additional issue was opened.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Updated head: 9855aaa16d07fab0dd2947da6f07fd60b3849372 (rebased onto main 76e1a9bd9f75480ee76f686c43994f938a15a8d5).

The binder fix preserves raw spelling for target-typed decimal literals (including TIME 0.001) and normalizes only untyped Decimal inference, so leading-zero spelling no longer changes temporal conversion while Decimal256 precision/range checks remain intact.

During rebase, the decimal BVT oracle was aligned with the final 40-digit literal path: it now expects the physical Decimal256 Mul overflow, not the old DECIMAL(65,37) precision error. Focused Decimal/TIME/Decimal256 tests and changed-package golangci-lint (0 issues) pass. The new remote CI run is pending.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Systematic follow-up after rebasing onto latest main (24e66eba12), pushed at e42890b48a:\n\n- Reproduced the FULLTEXT2 20105 root cause from the CI artifacts: bare/passenger MATCH expressions could carry qualified vs unqualified column display names, and decimal comparison provenance could differ on nested MATCH pattern/mode literals. The passenger was therefore not recognized as the served MATCH stream. The fix normalizes only the display-name fallback and ignores only decimal provenance metadata for MATCH pattern/mode identity; it does not broaden unsafe </<= driver harvesting.\n- Added planner regressions for classic and FULLTEXT2 paths, including <, <=, OR residuals, LIMIT, and aggregate-over-subquery shapes.\n- Preserved nullable decimal SQL three-valued semantics. The constant-folding BVT fixtures now declare the asserted price columns NOT NULL, instead of weakening the planner guard or changing expected plans to make CI green.\n- Corrected the post-rebase persisted-expression protocol collision: decimal literal semantics are fenced at MORPC v85; mainline MORPC v84 remains the discrete-percentile contract, with protobuf field numbers unchanged.\n- Addressed the column-identity review concern: same-binding ColPos now takes precedence over normalized display names, with a negative regression for distinct body vs quoted a.body.\n\nValidation in the isolated worktree: full pkg/sql/plan CGo tests passed (5.525s), full pkg/pb/plan CGo tests passed (0.358s), and git diff --check passed. No BVT/race run was added; the new tests are focused planner tests. The branch was force-with-lease pushed and remote HEAD is verified at e42890b48a. Please re-review the new head; CI is currently pending.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Rebased and refreshed on the latest main at 780ef933f2479aa1679faf13d08850ce6c8f7c2f; final head is 635869458e45b7e723838cbe5f402a16ac66966a.

The systematic fix keeps exact DECIMAL literal/cast/comparison semantics, carries the v85 persisted-expression fence without consuming v84's discrete-percentile contract, and fixes the negative Decimal256 trailing-zero early-fold regression by using magnitude only for the planner divisibility predicate. Full pkg/pb/plan and pkg/sql/plan CGo tests, focused race tests, CGo-configured vet, incremental SCA, and the twice-repeated 55-machine public index/query probe pass. The known quantity[3,19,0] versus quantity[3,18,0] mismatch remains a base fixture issue and is unchanged.

GPT-6 medium exact-head review: ACCEPT, no required corrections.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review(head 6358694)

发现 1 个 P2;这是作者自有 PR,本次提交 COMMENT,不提交 APPROVE/REQUEST_CHANGES。

[P2] 宽位数字面量升级为 Decimal256 后,INTERVAL 可能丢失小数时间。引入点见 make.go:84-100,遗漏消费者见 base_binder.go:9028-9031。

反例:

SELECT DATE_ADD(CAST('2026-01-01 00:00:00' AS DATETIME(6)), INTERVAL 1.25000000000000000000000000000000000000 SECOND);

该 literal 被绑定为 Decimal256,但 resetDateFunctionArgs 的小数时间分支未处理 Decimal256,随后落入 INT64 转换路径,1.25 秒可能变成 1 秒;base 中相同输入走 Decimal128 并保留 250000 微秒。建议补齐 Decimal256 到微秒的转换,并增加真实 SQL 结果测试,覆盖短写 1.25、宽尾零、正负值和 prepared 执行。

其余 lexer/parser、精度边界、负数/溢出、prepared 生命周期、持久化编码和资源路径未发现新的确定性阻断问题。当前 head 的 UT、SCA、Compose/BVT 和 CI Required 已通过,但现有测试没有覆盖该 INTERVAL public contract。

源码链接:

if isPlainDecimalLiteral(v) && width > types.T_decimal128.ToType().Width {

isDecimalOrFloat := firstExpr.Typ.Id == int32(types.T_decimal64) ||

CI:https://github.com/matrixorigin/matrixone/actions/runs/35247490690

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Final systematic follow-up

Updated head: 6cd411c55b42fb6aaf0970858e4b173a4666684b; rebased onto current main 780ef933f2479aa1679faf13d08850ce6c8f7c2f (rebase was a no-op).

  • Closed the remaining CAST-contract gap identified during review: Decimal256 interval normalization now reuses the existing normal/explicit decimal CAST token parsers, including explicit overload detection and binary-literal provenance; it no longer calls raw types.ParseDecimal* for CAST chains.
  • Added planner and public BVT parity coverage for standalone versus interval CAST('0b10' AS DECIMAL(40,2)): 2.00 and 2026-01-01 00:00:02.
  • 10.222.1.55 isolated public validation passed for the new pair and all existing Decimal256 interval cases; the task-owned service/staging directory were cleaned up.
  • Exact-head validation passed: full CGo UT for pkg/sql/plan, pkg/pb/plan, and pkg/sql/plan/function; focused interval race; CGo-configured vet; incremental SCA (0 issues); dependency checks; gofmt/diff checks.
  • GPT-6 Astra medium exact-head review: ACCEPT, no actionable P0/P1/P2 findings.

Only the personal fork feature branch was updated; no default branch was touched.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

已完成修复并 rebase 到最新 main(480b91764a94)。

根因:decimal256_interval.result 中 7 个 date_add/date_sub 的 DATETIME 结果 metadata 按字符串断言为 [12,-1,0],但 binder 保留了 typed DATETIME 合约,正确 metadata 是 [93,26,0],值使用 9 位小数;MINUTE 和 interval CAST(0b10 AS DECIMAL(40,2)) 两个 control 也同步修正。仅修改 result fixture,未扩散生产代码。

10.222.1.55 验证:normal metadata mode(无 -n)运行 decimal256_interval.test 两次,均 8/8 通过;task-owned service/workspace 已清理。

当前 head:6ee2babe0fb457d248971ea831f4e2865565b75c。提交前 GPT-6 medium review 结论 ACCEPT,无 P0/P1/P2。新的 CI 已启动,等待 GitHub 结果。

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Coverage follow-up and conflict resolution:

  • Rebasing is complete on current main; the PR is now GitHub-mergeable at 5048806ea47057e325efd8024e3dea47dad91232.
  • Added focused deterministic UT coverage for Decimal64/128/256 interval/cast paths, source carriers, rounding, errors, and decimal provenance.
  • Resolved the protocol conflict semantically: MORPC v85 remains exclusively for integer-parameter coercion; decimal literal provenance uses new MORPC v86, with admission tests rejecting v85 and accepting v86.
  • Preserved provenance through direct and cast Decimal64/128/256 interval and window rewrites, including normalized narrow literals.
  • gofmt, git diff --check, go list, and GOWORK=off go test -c -p 2 ./pkg/sql/plan pass. Runtime tests are not claimed because this Darwin host lacks the source-matched cgo/libmo.dylib.

No BVT, slow/full UT, workflow, threshold, exclusion, retry, or skip changes were added in this update. Remote CI was not awaited.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Fixed and pushed as 915deec685:

  • fixed the SCA failure in pkg/sql/plan/comparison_cast_optimization_test.go (gofmt);
  • the current head already includes the leading-zero normalization requested in the blocking review, with binder/parser regressions for 100 leading integer zeroes and 0. plus 75 fractional zeroes;
  • the Decimal256 interval fractional-second path is covered as well.

Local evidence on the current head:

  • focused planner/binder and Decimal256 interval tests: PASS;
  • go vet ./pkg/sql/plan: PASS;
  • gofmt -l over all changed Go files: clean;
  • git diff --check: PASS.

The CGo test binary used the existing local native artifact via an explicit rpath because the primary checkout has unrelated dirty native artifacts; this is a local-environment limitation, not a source failure.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Final incremental SCA on head 915deec685a5c36b04e46faa49c36adba524a663:

  • Merge-base is c4e81d580b924b6272f988edbd8025dc5cb90da4.
  • Changed-file gofmt and git diff --check pass.
  • go vet and molint pass for the affected planner package; no changed-file molint findings.
  • golangci-lint --new-from-rev reports 0 issues.

Focused Decimal256 normalization/interval tests remain passing.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra medium re-review on current head 915deec.\n\n发现 3 个 P2,未发现 P0/P1:\n\n1. [P2] SQL 一元负号使 Decimal256 interval 绕过微秒归一化,丢失小数部分。位置:pkg/sql/plan/interval_decimal.go:110、pkg/sql/plan/base_binder.go:9138。\n\nSELECT DATE_ADD(CAST('2026-01-01 00:00:00' AS DATETIME(6)), INTERVAL -1.25000000000000000000000000000000000000 SECOND);\n\n预期为 2025-12-31 23:59:58.750000;当前调用链中 decimalIntervalText 不处理 unary_minus,后续 Decimal256→INT64 可能把 -1.25 当作 -1 秒。现有测试只覆盖负数字符串 CAST,没有覆盖 SQL 一元负号。建议让归一化处理真实的带类型常量表达式,并增加公开 SQL 精确结果回归。\n\n2. [P2] interval 的嵌套 CAST 预计算可能改变 FLOAT→DECIMAL 舍入。位置:pkg/sql/plan/interval_decimal.go:113、245。普通执行器的 FLOAT64→Decimal64 与 helper 的 FLOAT64→字符串→Decimal64 路径对 1.005e0 可能分别得到 1.00 和 1.01,导致普通 CAST 与 DATE_ADD INTERVAL 表达同一嵌套 CAST 时结果不一致。建议保留每层 CAST 的源类型并复用执行器转换语义,补充正负半舍入边界差分测试。\n\n3. [P2] negative Decimal128 尾零修复未完整进入 persisted-view v86 protocol fence。位置:pkg/sql/plan/make.go:202。类似 d = -12345678901234567890.00 的比较,base 可能因补码取模误折叠为 false,head 保留正确比较,但当前 literal/folding/source-scale 条件可能不设置 DecimalLiteralSemantics marker,floor=85 的旧 CN 仍可重绑为不同结果。建议 fence 覆盖所有被修正的负 Decimal128 尾零判断,并补充 floor85 拒绝、floor86 接受及旧/新重建结果验证。\n\n固定 head 的 CI 和相关 BVT 已通过;上述公开 SQL 反例及真实混合版本 persisted-view replay 尚未实跑。本 PR 为自有 PR,提交 COMMENT。

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Follow-up: Decimal interval/comparison semantic fixes

Pushed exact head b46e832e149f2c6aa9625d199ac17890d8ba0a56.

This follow-up closes three confirmed planner contract gaps:

  • Decimal256 INTERVAL -<wide-decimal> now applies unary sign before exact rational-to-microsecond conversion, including DATE_ADD/DATE_SUB and negative sub-microsecond window rejection.
  • Nested FLOAT32/FLOAT64 -> DECIMAL64/128/256 casts now reuse the runtime Decimal*FromFloat64 rounding contract at the first decimal cast, including explicit-cast fallback.
  • The v86 persisted-expression fence for signed trailing-zero comparison changes is narrow: only negative values with a proven removable zero suffix are fenced; positive and negative nonzero-suffix controls remain unfenced.

Validation on this exact head:

  • focused planner regressions: PASS;
  • full ./pkg/sql/plan UT: PASS;
  • current-source two-CN public decimal256_interval.test: 11/11 PASS;
  • gofmt, diff check, go list, go vet: PASS;
  • molint: only pre-existing baseline findings, none in changed files;
  • golangci-lint --new-from-rev=c4e81d580b: 0 issues;
  • independent GPT-6 review: ACCEPT, no actionable P0-P3 findings.

The local BVT used a task-owned service built from this exact source head; CI was not awaited. The native CGo library was reused from the primary checkout because the linked worktree has no source-matched native artifact.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra medium re-review on current head b46e832.\n\n上一轮 interval 一元负号和 FLOAT→DECIMAL 舍入问题已闭合;仍有 1 个 P2,未发现 P0/P1:\n\n[P2] v86 fence 遗漏旧尾零判断的反向误判及正数低位溢出。位置:pkg/sql/plan/make.go:251、257。\n\ndecimalComparisonUsesSignedTrailingZeroSemantics 仅在“负数且新算法确认尾缀为零”时设置 fence,但旧/新 decimal128HasTrailingZeros/Mod128 的差异还包括:\n\n- 正数低位超过 int64 的零尾缀,例如系数 9223372036854775810;旧 high==0 分支将低位当 int64,可能误判不可整除,base 折叠为 false,head 保留正确比较,但正数路径不设置 v86 marker;\n- 负数非零尾缀,例如 -12345678901234567896;旧无符号补码取模可能误判可整除,base 缩减 scale 并得到错误匹配,head 正确折叠为 false,但当前 proven && trailingZeros 为 false,同样不设置 fence。\n\n这类 view 在 floor=85 下可被发布,旧 CN 重绑原 SQL 后与 head 得到不同结果。建议根据旧/新尾零判定是否不同设置 fence,覆盖正数低位溢出和负数被误判可整除的情况;补充 floor85 拒绝、floor86 接受及旧/新 view 重绑结果验证。\n\n固定 head 的 UT/BVT 已通过;仍缺真实 v85/v86 混合版本 view replay/restart/recovery 证据。本 PR 为自有 PR,提交 COMMENT。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra medium review on current head 4e31403.\n\n发现 1 个 P2,未发现 P0/P1:\n\n[P2] v86 suffix fence 遗漏 typed IN 和 BETWEEN 路径。marker 目前只在 binary comparison 的 base_binder.go:5325 设置,但修正后的 suffix helper 还被 IN:5728 和 BETWEEN:6161 的 checkNoNeedCast 使用。\n\n例如 d DECIMAL(30,0) NOT NULL:\nCREATE VIEW v AS\nSELECT d IN (-1234567890123456789.0, -10.0) AS matched FROM t;\n\nUnary-minus folding 后的 typed decimal literal 会进入 typed IN vector,绕过 binary-comparison marker;base 的旧 suffix 判断可能将同一候选展开/折叠为不同结果,但 view 不携带 v86 requirement。d BETWEEN -1234567890123456789.6 AND -10.0 存在同类风险。建议在这些 coercion 决策前记录 old/new suffix dependency,并贯穿 vector folding;补充 floor85 拒绝、floor86 接受及 base/head 结果测试。\n\n此前 binary comparison fence、interval unary-sign 和 FLOAT→DECIMAL 舍入问题已闭合。固定 head CI 已通过,但真实 v85/v86 view replay、restart/restore/rollback 仍缺失。本 PR 为自有 PR,提交 COMMENT。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force re-review at exact head 0ad4066.

未发现新增可确认的 P0/P1/P2 代码问题。此前 typed IN/BETWEEN suffix-fence 遗漏已修复:共享 coercion 判定同时记录旧/新 suffix disagreement,覆盖 typed IN/NOT IN、BETWEEN/in_range;provenance 可穿过 scalar/list/vector folding、deep copy、protobuf 和 persisted-view。有效 decimal fence 为 protocol87,同时保留 main86 与 integer85;view lifecycle 测试覆盖 85/86 拒绝、87 接受。

已复查完整 diff 及 lexer/parser、binder、decimal/unary-sign、comparison、interval、folding、prepared、view/regeneration、admission 路径,未确认其他 scoped blocker。

验证证据为核验已有日志、未本轮重跑:dedicated decimal 23/23、interval 11/11;同实例重跑 34/34,teardown 0;已有 v86 -> v87 view/store replay、v87 graceful restart、旧 v86 对 required87 的 admission rejection。legacy decimal 全量仍为 584/690,整体 exit 1;剩余 106 项与真实旧 v86 baseline 完全一致,不能表述为全套 PASS。

尚未看到完整真实 v85 执行矩阵;旧容器 exit137 不能当作 graceful shutdown;mixed-CN、故障注入、backup/restore 矩阵仍不完整。这些是验收覆盖边界,不是已确认代码 defect。

本 PR 为自有 PR,提交 COMMENT。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve decimal provenance when materializing numeric window bounds

In pkg/sql/plan/window_binder.go:1281, GetConstantValue replaces the expression without copying DecimalLiteralRequiresV82. The interval path preserves it, but ordinary numeric RANGE bounds lose it.

Concrete case: with a DECIMAL(20,18) ordering column and an unquoted frame bound containing 80 leading zeroes followed by .123456789012345678, the old path falls back to float64 (0.123456789012345680) while this head normalizes to the exact decimal (0.123456789012345678). With rows 0 and 0.123456789012345679, COUNT(*) OVER (ORDER BY d RANGE BETWEEN <bound> PRECEDING AND CURRENT ROW) can therefore differ.

The direct NumVal → makeWindowFrameConstValue path bypasses the function-binding observer. After materialization, the view pre-optimization scan and persisted protocol calculation do not see the dependency, so a view can omit required protocol87 and be rebound differently by v85/v86.

Please preserve the provenance from e onto c here and add view authoring/regeneration tests that reject this case at 85/86 and retain 87.

Other inspected chains—lexer/parser, decimal arithmetic/casts, interval conversion, typed IN/BETWEEN, folding, hashing/deepcopy, protobuf, Substrait, and remote execution—had no additional verified P0–P2 findings. Exact-head Linux UT/SCA and active multi-CN BVT jobs passed; upgrade compatibility jobs were skipped.

@XuPeng-SH

XuPeng-SH commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebase/update at 0120d9103aa060ff8e7876a67ea0e4070adb1f60

  • Rebased onto current main 3fe7840e34983141e579dee720741fb962847e4c; PR is now MERGEABLE.
  • The only conflict was the MORPC v87 constant collision. Kept main's v87 ROLLUP provenance contract; the PR's decimal-literal fence remains on the same v87 contract. git range-diff shows all 27 PR commits retained with no other semantic delta.
  • Passed: git diff --check, changed-Go-file gofmt, and GOWORK=off go list -mod=readonly ./pkg/pb/plan ./pkg/sql/plan.
  • Reused the prior exact-head CI evidence: all required UT, SCA, coverage, build, and standalone/compose BVT checks passed in run 35453371306.
  • Local CGo rerun is NOT VERIFIED: the worktree and primary checkout lack a source-matched libmo.so provenance stamp and native headers. go vet stopped at missing usearch.h, xxhash.h, roaring.h, and jemalloc.h; golangci-lint also cannot load this Go 1.26.4 target with the installed Go 1.24-built binary.
  • New CI for the rebased head is running; no new product or test-scope changes were added.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 0120d9103aa060ff8e7876a67ea0e4070adb1f60; self-authored PR, so COMMENT only.

[P1] Allocate a distinct decimal protocol version after the rebase.

pkg/sql/plan/persisted_ip.go:102-104 still fences decimal semantics at 87, but main already advertises 87 for grouping transport without these decimal fixes. A main-only v87 CN can therefore pass the persisted-view version check and reparse a wide literal such as 12345678901234567890123456789012345678.1 through the old Decimal128 path. Mixed deployment/rollback can silently change values despite the durable floor. Please allocate an unambiguous newer protocol version and verify rejection with the actual main-v87 binary; v86 rejection does not cover this boundary.

[P2] Preserve decimal provenance when materializing numeric RANGE bounds.

pkg/sql/plan/window_binder.go:1281-1285 replaces e with a fresh literal without copying DecimalLiteralRequiresV82. For a DECIMAL(20,18) ordering column and a bound with 80 leading zeroes followed by .123456789012345678, the direct literal path loses the view compatibility dependency; exact and legacy rounded bounds can produce different frame counts. Preserve the marker from e onto c, and cover view authoring/regeneration at incompatible and supported protocol floors.

No additional verified P0-P2 findings. Exact-head Linux UT/SCA and active multi-CN BVT passed; upgrade jobs were skipped.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (22d43911d3) and pushed exact head 835bca8d0e.

Closed the two requested review findings:

  • Decimal persisted-expression semantics now use distinct MORPC v89; main's v87 grouping and v88 canonical vector-HLL contracts remain unchanged. Admission tests cover v85-v88 rejection and v89 acceptance, and compatibility helper aliases delegate to the v89 contract.
  • Numeric window RANGE-bound materialization now preserves decimal provenance. Focused tests cover marked start/end bounds, floor-v88 rejection, floor-v89 acceptance, and an unmarked control.

Rebase correctness:

  • Regenerated plan.pb.go from the merged plan.proto with gogofast plus the repository postprocessor. This preserves main's Node_ADAPTIVE_TOP = 57, decimal fields, descriptors, marshal/unmarshal paths, and unknown-enum validation.
  • git diff --check origin/main...HEAD: PASS
  • duplicate-test inventory: one TestPersistedViewProtocolAdmissionCapturesBindTimeBetweenFold
  • GPT-6 medium final re-review: no remaining actionable P0-P2 findings

Not verified locally:

  • planner/protobuf runtime tests and incremental SCA: mo-cgo-test refused because the worktree has no cgo/libmo.so and the primary artifact lacks a provenance stamp
  • BVT/mixed-CN/restart/rollback matrices: no owned deployment

Fresh CI has been triggered by the push. Remaining risk is limited to the unexecuted mixed-version lifecycle matrix; the protocol gate is covered structurally and by focused unit tests in the change.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Rerun status: this head already has current main 22d43911d3 as its merge-base, so no no-op force-rebase was performed and its running exact-head CI was left intact. Cross-PR inspection shows #28830 already contains this decimal-literal/provenance closure (including the same decimal v89 contract and overlapping planner/proto/BVT files). With the requested priority #28830 before #28825, this PR should be re-evaluated after #28830 lands; independently merging both current branches would duplicate the same contract rather than require another implementation rewrite.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 835bca8d0e3b8d16a1707d9bfbbeac85c29c4095; self-authored PR, so COMMENT only.

The previous findings are fixed: decimal semantics now require distinct protocol v89, and numeric RANGE materialization preserves DecimalLiteralRequiresV82.

[P2] Decimal256 promotion exposes an unsupported numeric RANGE path. With a wide literal such as 1.25000000000000000000000000000000000000 used as the ordering value, the binder promotes the RANGE offset to Decimal256, but makeWindowFrameConstValue calls GetConstantValue, which has no Decimal256 case and returns a nil literal. The runtime RANGE materializer/validation/search also lack Decimal256 support.

Please complete Decimal256 bound representation and RANGE execution support, with short/wide spelling and prepared-execution regressions. Exact-head CI passed; this finding is source-traced rather than runtime-reproduced, and v88/v89 mixed-version lifecycle evidence remains outstanding.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review status — exact head b3d42f5fe7441e96a03e1521690a1e2e963c4eb7。

当前 review 尚未完成,暂不判定 PASS。远端 PR 元数据/变更核验曾遇到 TLS 超时,Decimal256 RANGE window bounds 的完整 diff、边界行为和 consumer 闭环尚未独立确认。当前没有确认的 P0–P3 功能缺陷;这条 COMMENT 仅表示验证尚未收敛,不代表实现已通过 review。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PASS — exact head b3d42f5fe7441e96a03e1521690a1e2e963c4eb7。

已完整复核 Decimal256 RANGE 从绑定、LiteralVec 序列化、Prepare 到窗口搜索消费者的闭环,覆盖 width/scale、NULL、负数、畸形载荷、ASC/DESC、PRECEDING/FOLLOWING、peers、空 frame、常量向量、溢出边界及 prepared 重用。未发现 P0/P1/P2 blocker。

Exact-head CI 的 UT、SCA、共享构建、PROXY/PESSIMISTIC BVT 和 Required gate 均通过。自有 PR 按规则只提交 COMMENT,不提交 APPROVE。

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/bug Something isn't working kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Decimal256 numeric RANGE window bounds fail as missing parameters [Bug]: unquoted DECIMAL256 literals lose fractional digits before evaluation

3 participants