Skip to content

[CALCITE-7912] Prune UNION ALL branches that cannot affect an enclosing aggregate - #5382

Open
sbroeder wants to merge 1 commit into
apache:mainfrom
sbroeder:7912
Open

sbroeder wants to merge 1 commit into
apache:mainfrom
sbroeder:7912

Conversation

@sbroeder

Copy link
Copy Markdown
Contributor

Add AggregateUnionNullBranchRule as CoreRules.AGGREGATE_UNION_NULL_BRANCH. A UNION ALL branch is irrelevant to an enclosing aggregate when every aggregate call ignores NULLs, for example, SUM, SUM0, MIN, MAX, AVG, COUNT(col), and reads a column that the branch produces as constant NULL.

Without GROUP BY the branch is removed, but at least one branch is kept. With GROUP BY the branch is kept because it contributes group keys, but a redundant pure GROUP BY inside it is removed.

COUNT(*), other aggregates, and UNION distinct are not affected.

Jira Link

CALCITE-7912

…ng aggregate

Add AggregateUnionNullBranchRule as CoreRules.AGGREGATE_UNION_NULL_BRANCH.
A UNION ALL branch is irrelevant to an enclosing aggregate when every
aggregate call ignores NULLs, for example, SUM, SUM0, MIN, MAX, AVG, COUNT(col),
and reads a column that the branch produces as constant NULL.

Without GROUP BY the branch is removed, but at least one branch is kept.
With GROUP BY the branch is kept because it contributes group keys, but a
redundant pure GROUP BY inside it is removed.

COUNT(*), other aggregates, and UNION distinct are not affected.
@sonarqubecloud

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