Fix wrong results bug with count over mixed aggregation#23013
Merged
rschlussel merged 1 commit intoprestodb:masterfrom Jun 18, 2024
Merged
Fix wrong results bug with count over mixed aggregation#23013rschlussel merged 1 commit intoprestodb:masterfrom
rschlussel merged 1 commit intoprestodb:masterfrom
Conversation
Fix a wrong results bug with count over an aggregation that had a mix of global and non-global grouping sets. We were not checking for single global aggregations correctly in QueryCardinalityUtil, so we would return that the plan was scalar if there were *any* empty grouping sets rather than if the empty grouping set was the only grouping set. we have now fixed this to return that if all of the grouping sets are global, then the cardinality will be the number of grouping sets, and otherwise it is at least the number of global grouping sets. This fixes queries like the following: SELECT COUNT(*) FROM (SELECT count(*) FROM tpch.sf1.nation GROUP BY GROUPING SETS (nationkey, ())); previously we would incorrectly return 1. And now we return 26. This change may also fix bugs with correlated subqueries, as those also use the isScalar() utility function.
6370057 to
7c925ce
Compare
jaystarshot
approved these changes
Jun 17, 2024
34 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix a wrong results bug with count over an aggregation that had a mix of global and non-global grouping sets.
We were not checking for single global aggregations correctly in QueryCardinalityUtil, so we would return that the plan was scalar if there were any empty grouping sets rather than if the empty grouping set was the only grouping set. we have now fixed this to return that if all of the grouping sets are global, then the cardinality will be the number of grouping sets, and otherwise it is at least the number of global grouping sets.
This fixes queries like the following:
previously we would incorrectly return 1. And now we return 26.
This change may also fix bugs with correlated subqueries, as those also use the isScalar() utility function.
Motivation and Context
Fixes #22977
Impact
Fixes wrong results for queries with counts over mixed global and grouped aggregations .e.g.
SELECT COUNT(*) FROM (SELECT count(*) FROM tpch.sf1.nation GROUP BY GROUPING SETS (nationkey, ()));Test Plan
added unit tests
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.