Skip to content

fix(plan): infer prepared SUM and AVG parameters - #26534

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-26019-prepared-sum-avg
Aug 1, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-26019-prepared-sum-avg

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26019

What this PR does / why we need it:

Prepared SUM and AVG bound a bare parameter marker as TEXT before aggregate overload resolution, so SQL and binary PREPARE failed before an execution value could be supplied.

This change applies the existing prepared numeric-inference contract to SUM and AVG in direct and window aggregates. It also propagates aggregate numeric intent through derived tables and ordinary or recursive CTE projections before those sources are bound. Compatible targets from multiple consumers are merged to a safe common numeric type; existing assignment-conflict behavior is unchanged.

The parameter keeps the existing dynamic T_any / MYSQL_TYPE_NULL transport metadata and is cast to the inferred computation type in the plan. Ordinary VARCHAR aggregate inputs and explicit character casts remain rejected, while explicit numeric casts keep their declared type. Repeated fill preserves the canonical prepared plan.

Tested with:

  • full pkg/sql/plan and pkg/frontend tests
  • full pkg/sql/plan and pkg/frontend tests under race
  • focused race stress, count 100, for planner and binary metadata regressions
  • configured go build and go vet for both packages
  • git diff --check
  • added distributed SQL fixture for direct, window, recursive, repeated numeric-string, NULL, and invalid-string execution; local mo-tester was unavailable

@LeftHandCold
LeftHandCold requested a review from a user July 31, 2026 17:50
@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.

Deep-reviewed exact head dc83a3b. The fix establishes a static numeric contract for SUM/AVG markers, keeps transport metadata dynamic, and propagates only parameter-bearing numeric intent through derived/CTE projections. Ordinary VARCHAR aggregate inputs and explicit character casts remain rejected; explicit numeric casts, recursive CTE common types, window aggregates, repeated fill, and multiple compatible consumers preserve their contracts. I found no blocking correctness, unhappy-path, state-ownership, or material performance issue. Local verification: focused planner and binary-protocol tests under race count=100; full pkg/sql/plan and pkg/frontend under race; scoped go vet; diff check; latest CI green.

@XuPeng-SH
XuPeng-SH merged commit 08d71ea into matrixorigin:main Aug 1, 2026
25 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26019

## What this PR does / why we need it:

Prepared SUM and AVG bound a bare parameter marker as TEXT before
aggregate overload resolution, so SQL and binary PREPARE failed before
an execution value could be supplied.

This change applies the existing prepared numeric-inference contract to
SUM and AVG in direct and window aggregates. It also propagates
aggregate numeric intent through derived tables and ordinary or
recursive CTE projections before those sources are bound. Compatible
targets from multiple consumers are merged to a safe common numeric
type; existing assignment-conflict behavior is unchanged.

The parameter keeps the existing dynamic T_any / MYSQL_TYPE_NULL
transport metadata and is cast to the inferred computation type in the
plan. Ordinary VARCHAR aggregate inputs and explicit character casts
remain rejected, while explicit numeric casts keep their declared type.
Repeated fill preserves the canonical prepared plan.

Tested with:

- full pkg/sql/plan and pkg/frontend tests
- full pkg/sql/plan and pkg/frontend tests under race
- focused race stress, count 100, for planner and binary metadata
regressions
- configured go build and go vet for both packages
- git diff --check
- added distributed SQL fixture for direct, window, recursive, repeated
numeric-string, NULL, and invalid-string execution; local mo-tester was
unavailable

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26019

## What this PR does / why we need it:

Prepared SUM and AVG bound a bare parameter marker as TEXT before
aggregate overload resolution, so SQL and binary PREPARE failed before
an execution value could be supplied.

This change applies the existing prepared numeric-inference contract to
SUM and AVG in direct and window aggregates. It also propagates
aggregate numeric intent through derived tables and ordinary or
recursive CTE projections before those sources are bound. Compatible
targets from multiple consumers are merged to a safe common numeric
type; existing assignment-conflict behavior is unchanged.

The parameter keeps the existing dynamic T_any / MYSQL_TYPE_NULL
transport metadata and is cast to the inferred computation type in the
plan. Ordinary VARCHAR aggregate inputs and explicit character casts
remain rejected, while explicit numeric casts keep their declared type.
Repeated fill preserves the canonical prepared plan.

Tested with:

- full pkg/sql/plan and pkg/frontend tests
- full pkg/sql/plan and pkg/frontend tests under race
- focused race stress, count 100, for planner and binary metadata
regressions
- configured go build and go vet for both packages
- git diff --check
- added distributed SQL fixture for direct, window, recursive, repeated
numeric-string, NULL, and invalid-string execution; local mo-tester was
unavailable

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26019

## What this PR does / why we need it:

Prepared SUM and AVG bound a bare parameter marker as TEXT before
aggregate overload resolution, so SQL and binary PREPARE failed before
an execution value could be supplied.

This change applies the existing prepared numeric-inference contract to
SUM and AVG in direct and window aggregates. It also propagates
aggregate numeric intent through derived tables and ordinary or
recursive CTE projections before those sources are bound. Compatible
targets from multiple consumers are merged to a safe common numeric
type; existing assignment-conflict behavior is unchanged.

The parameter keeps the existing dynamic T_any / MYSQL_TYPE_NULL
transport metadata and is cast to the inferred computation type in the
plan. Ordinary VARCHAR aggregate inputs and explicit character casts
remain rejected, while explicit numeric casts keep their declared type.
Repeated fill preserves the canonical prepared plan.

Tested with:

- full pkg/sql/plan and pkg/frontend tests
- full pkg/sql/plan and pkg/frontend tests under race
- focused race stress, count 100, for planner and binary metadata
regressions
- configured go build and go vet for both packages
- git diff --check
- added distributed SQL fixture for direct, window, recursive, repeated
numeric-string, NULL, and invalid-string execution; local mo-tester was
unavailable

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>

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.

3 participants