-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADBDEV-6314: Fix unexpected output for empty grouping set #1117
base: adb-6.x-dev
Are you sure you want to change the base?
Conversation
Allure report https://allure.adsw.io/launch/86054 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wrote, that changes are similar to Postgres 9.5, but I did not find the same sources there. Can you give the commit, which is example of your patch? Or can you backport such commit?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
f3d3118 introduces support in PG 9.5. Also in GPDB7.
I discussed this issue with @Stolb27. I only need to correct the parser behavior without porting. My changes only concern the ungrouped columns check. Whereas the patch in PostgreSQL makes changes to the planner and much more. |
Tests for GPDB6 is run with "optimizer_enable_table_alias=off". You do not need to set GUC in the test. gpdb/concourse/scripts/common.bash Line 92 in c69f669
|
I fixed the typo and the use of tense. I hope the meaning of "grouping expressions" and expressions (Vars) does not overlap. I will also correct the comment in the code. |
src/backend/parser/parse_agg.c
Outdated
*/ | ||
List* | ||
get_com_grouping_ressortgroupref(Query *qry, bool *hasGrouping, List *grp_tles){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excessive line
This comment was marked as resolved.
This comment was marked as resolved.
* check_ungrouped_columns(). | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we replace the entire loop below with a walker similar to CQueryMutators::GetGroupUniqueTleReferencesWalker ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is very similar to what we need. But in this cycle we need to get TLE, not refsortgroupref. Because in further processing either TLE or expr is used.
Followins query:
On Postgres 17 works ok:
while on your branch it reports an error:
Can you please check? |
Also runs in PG 9.5. Maybe I should make a list of common attributes for a specific grouping expression. |
Allure report https://allure.adsw.io/launch/86371 |
Also testcases are added
It is necessary to select common attributes among top-level groupings.
It is necessary to take into account nesting. This query also degenerates into a regular GROUP BY and works: This query does not work: With a composite key it works differently (does not work): |
I have changed the behavior. Please check. Pay attention to the tests. |
Allure report https://allure.adsw.io/launch/86406 |
Prohibiting grouping sets with ungrouped attributes in TargetList
Problem:
Queries with grouping expressions and ungrouped attributes in TL could
produce unexpected output if the group did not have a primary key.
Example with 3 columns where "a" is a primary key:
SELECT a,b,c FROM t GROUP BY GROUPING SETS((a),(b));
Grouping "(a)" had correct output of columns "a", "b", "c". Attribute "b" in
group "(b)" is not a primary key, so it is not unique, so it can be grouped.
In this case, the output of column "c" was undefined. This also applied to
"GROUPING SETS ((a),())", ROLLUP and CUBE (detailed behavior is
described in tests with ungrouped check).
Grouping expressions were introduced in PostgreSQL 9.5 and such queries
were prohibited. And this patch aligns the behavior with that.
Solution:
Improve parse-stage validation for ungrouped columns when using grouping
expressions.
Changes:
Similar to PostgreSQL, the parsing stage for queries with grouping
expressions reads common attributes for all groups. If any, they are placed in
"groupClauseCommonVars". In case of ungrouped attributes in TL, this list is
used to check for PK in groups.
Compared to the original, the "groupClauses" list uses TargetEntry rather than
an expression. Added function to get common refsortgroupref in grouping
clauses. At the beginning, the function assumes that all expressions are found
in grouping clauses. By running through the groupings, missing expressions
are excluded from the common refs list. The patch does not change the
behavior of regular GROUP BY.