Skip to content

fix: enforce recursive CTE decimal precision - #29280

Merged
XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
ck89119:issue-29137-main
Sep 24, 2026
Merged

XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
ck89119:issue-29137-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 23, 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:

issue #29137

What this PR does / why we need it:

Recursive CTE members are cast back to the anchor column type, but same-scale DECIMAL casts incorrectly used a direct-copy fast path when the target precision was narrower. This relabeled values without validating the target range, allowing values such as 1000.00 to be stored in DECIMAL(5,2) columns.

This change:

  • restricts direct-copy DECIMAL64/128/256 casts to precision-preserving widening conversions;
  • keeps DECIMAL128 source vector metadata immutable when reusing values;
  • rejects both positive and negative precision endpoints (+/-10^p) consistently;
  • adds executor and planner regression tests;
  • adds recursive CTE BVT coverage for SELECT, atomic INSERT failure, CTAS cleanup, DECIMAL64/128 boundaries, and prepared execution.

Validation:

  • go test -mod=readonly -count=1 -timeout=120s ./pkg/container/types
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan/function ./pkg/sql/plan
  • go vet -mod=readonly ./pkg/container/types ./pkg/sql/plan/function ./pkg/sql/plan
  • golangci-lint run -c .golangci.yml --new-from-rev "$(git merge-base HEAD mo/main)" ./pkg/container/types ./pkg/sql/plan/function ./pkg/sql/plan
  • mo-tester normal comparison mode twice for recursive_cte_decimal_precision.sql (20/20 passed each run)

@matrix-meow matrix-meow added size/XXL Denotes a PR that changes 2000+ lines and removed size/L Denotes a PR that changes [500,999] lines labels Sep 24, 2026
@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 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.

GPT-6 High deep review — APPROVE at exact head 9b264a1.

Reviewed the complete change against the current main merge-base (d7d940e); the PR API's base SHA was stale, and the actual outstanding diff is the 15 decimal-related files. Decimal narrowing/scale growth enforces target precision and preserves source metadata; scale reduction rounds exact coefficients once; cross-width operations retain sign/capacity; equality, null-safe equality, in_range, and Decimal256 executor consumers align on the common decimal domain. Recursive CTE castback and SQL failure/rollback paths have focused planner and BVT coverage. Exact-head CI, SCA, race-enabled planner/function UTs, and relevant multi-CN BVTs are green. No blocking findings.

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

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-24 09:56 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-24 11:23 UTC · at bbc65d2ecf6380f163579130d69e45c7aa334915

This pull request spent 1 hour 26 minutes 32 seconds in the queue, with no time running CI.

Reason

Pull request #29280 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

> The author needs to enable ["Allow edits from maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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 size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants