Skip to content

feat: support prepared percentile expressions - #29130

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
daviszhen:codex/issue-25110-percentile-expr
Sep 20, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
daviszhen:codex/issue-25110-percentile-expr

Conversation

@daviszhen

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 #25110

What this PR does / why we need it:

Extends percentile configuration to accept execution-invariant prepared
expressions such as ? / 100.0 for APPROX_PERCENTILE, PERCENTILE_CONT, and
PERCENTILE_DISC.

  • Allows prepared parameters, numeric literals, arithmetic, unary signs, and
    numeric casts.
  • Rejects columns, variables, subqueries, unrelated functions, volatile
    functions, and nonnumeric casts.
  • Converts the complete prepared expression to FLOAT64 before aggregate
    overload selection and evaluates it as fixed configuration for each
    EXECUTE.
  • Reuses the existing percentile configuration encoding and does not mutate
    the cached prepared plan.
  • Keeps invalid NULL, non-finite, out-of-range, and arithmetic results on the
    existing preflight error path, including queries with empty input.

Validation:

  • go test ./pkg/sql/plan -count=1
  • go test ./pkg/sql/compile -count=1
  • Added distributed SQL coverage for grouped CONT/DISC expressions,
    valid-error-valid prepared reuse, and invalid empty-input preflight. The BVT
    file was not executed locally and is left for CI validation.

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

Request changes for exact head 45cf5402b312d26ef24c6dfee50f2a5ae18f55bb.

[P2] Preserve DECIMAL percentile precision before range validation.

pkg/sql/plan/base_binder.go:5020-5031 still wraps prepared CAST(? AS DECIMAL(19,18)) in FLOAT64. With ordered values {10,20}, percentile 0.500000000000000001 becomes 0.5), so PERCENTILE_DISCselects 10 instead of 20. Likewise1.000000000000000001becomes1.0` and is accepted because the range check sees the already-rounded value.

Preserve supported numeric expression types and apply FLOAT64 normalization only where needed for untyped/text markers. Add prepared decimal precision and out-of-range regressions. No additional P0–P2 findings were found in repeated execution, aggregate/window cleanup, scalar/vector handling, serialization, or non-prepared paths.

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

APPROVE — reviewed exact head 6d91ed4. The previous DECIMAL percentile precision issue is fixed: prepared DECIMAL expressions retain exact configuration text, precise discrete ranking works, and out-of-range values are rejected. Prepared/repeated execution, group/window reset, scalar/vector, serialization and cleanup paths show no actionable P0–P2 findings. Exact-head UT/race, SCA and BVT passed; upgrade and combined prepared-window parity evidence remain gaps.

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

mergify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-20 09:22 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-20 09:50 UTC · at 1b8c159fea32fc69ace7c9e7adafd4a8cccf7b2a

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

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 48d6dea into matrixorigin:main Sep 20, 2026
24 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 20, 2026

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/feature size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants