Skip to content

[CALCITE-7687] RelMdSelectivity and RelMdDistinctRowCount for Aggregate can propagate a predicate with wrong references - #5145

Draft
etiennepelissier wants to merge 1 commit into
apache:mainfrom
etiennepelissier:calcite-7687-fix
Draft

[CALCITE-7687] RelMdSelectivity and RelMdDistinctRowCount for Aggregate can propagate a predicate with wrong references#5145
etiennepelissier wants to merge 1 commit into
apache:mainfrom
etiennepelissier:calcite-7687-fix

Conversation

@etiennepelissier

Copy link
Copy Markdown

Jira Link

CALCITE-7687

Changes Proposed

Same defect as CALCITE-4414, in the Aggregate overloads. An Aggregate's output field i is input
field groupSet.nth(i), so a predicate expressed over the aggregate's output must be converted
before it is pushed to the input.

Adds RelOptUtil.pushPastAggregate, alongside the existing pushPastProject / pushPastCalc, and
uses it from RelMdSelectivity.getSelectivity(Aggregate, ...) and
RelMdDistinctRowCount.getDistinctRowCount(Aggregate, ...). The former also has its pushability test
corrected, from getGroupSet() (input indices) to range(getGroupCount()) (output indices).

Three cases added to RelMetadataTest; all three fail without this change. Mechanism, SQL repro and
downstream impact are in the Jira.

…te can propagate a predicate with wrong references

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant