-
Notifications
You must be signed in to change notification settings - Fork 22
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-5479: Fix queryId calculation for queries with grouping clause #1119
Conversation
087afe3
to
ffb89d2
Compare
contrib/pg_stat_statements/expected/disable_pg_stat_statements.out
Outdated
Show resolved
Hide resolved
56dfd47
to
255da63
Compare
This comment was marked as resolved.
This comment was marked as resolved.
a258684
to
2e77455
Compare
Why do we need a new test file? Why can't we use an existing one? |
This test file is completely unrelated to the existing one: |
I'm not sure how good an idea it is to take the description of the commit from 6X as it is and just add a list of changes at the end. Considering that the patch is significantly different from the 6X. It seems to me that the description should be updated. |
Problem description: if 'pg_stat_statements' extension is enabled and a query containing GROUP BY clause with ROLLUP, CUBE or GROUPING SETS or with GROUPING function is executed, queryId calculation doesn't take into account these grouping clause parameters and GROUPING functions. So, semantically different queries are treated by pg_stat_statements as equivalent queries. Plus warning messages appear during jumbling. Also, jumbling logic doesn't handle properly queries with group_id() function call and calls of functions with 'anytable' parameter. First type of queries causes warnings. Second type of query causes error message "unrecognized RTE kind: 7". Expected correct behavior: queries with different grouping clauses or different usage of the GROUPING function are treated by pg_stat_statements as different queries, and no warning messages appear during the query execution. Cause: In JumbleExpr there is no handling for node tag and T_TableValueExpr and T_GroupingSet is handled incorrectly. Jumble hashing is used as queryId. Error message "unrecognized RTE kind: 7" caused by not handled range table type RTE_TABLEFUNCTION in JumbleRangeTable. Fix: Handling logic for missed node tags was added. According to comments in queryjumble.c, main guideline how to handle query tree is: "Rule of thumb for what to include is that we should ignore anything not semantically significant (such as alias names) as well as anything that can be deduced from child nodes (else we'd just be double- hashing that piece of information)." For T_GroupingSet we append to the jumble the grouping type and list of groupsets. Field 'location' is not appended to the jumble because it is the textual location from parser and is not semantically significant. For RTE_TABLEFUNCTION - 'functions' field of RangeTblEntry was added to the jumble. RangeTblEntry in case of RTE_TABLEFUNCTION uses 'functions' and 'subquery' fields (other significant fields are null). But 'subquery' is duplicated in TableValueExpr below, so do not jumble it. For T_TableValueExpr - 'subquery' field of TableValueExpr (the subquery that is inside "TABLE()" statement) was added to the jumble. Changes from original commit: 1. Cases for T_GroupId and T_GroupingFunc are already present, no fix needed. 2. Remove case for T_Integer because it is not necessary since GPDB 7 uses T_IntList instead. 3. T_GroupingClause is now named T_GroupingSet. Its case was not correct in GPDB 7, change to match implementation from GPDB 6. 4. Rename test to jumble since there were already tests present in GPDB 7. 5. The tests in pg_stat_statements were disabled before because they do not set up shared_preload_libraries and they don't disable optimizer. Add files enable_pg_stat_statements and disable_pg_stat_statements to adapt pg_stat_statements tests to current testing utilities. This allows to remove some initialization and cleanup from the new test. 6. Fix test output for GPDB 7. Notably, ROLLUP now outputs 1 row even if the table has no rows in it. (cherry picked from commit fa44e50)
2e77455
to
939ba2b
Compare
Fix queryId calculation for queries with grouping clause (#665)
Problem description:
if 'pg_stat_statements' extension is enabled and a query containing GROUP BY
clause with ROLLUP, CUBE or GROUPING SETS or with GROUPING function is
executed, queryId calculation doesn't take into account these grouping clause
parameters and GROUPING functions. So, semantically different queries are
treated by pg_stat_statements as equivalent queries. Plus warning messages
appear during jumbling.
Also, jumbling logic doesn't handle properly queries with group_id() function
call and calls of functions with 'anytable' parameter.
First type of queries causes warnings.
Second type of query causes error message "unrecognized RTE kind: 7".
Expected correct behavior: queries with different grouping clauses or different
usage of the GROUPING function are treated by pg_stat_statements as different
queries, and no warning messages appear during the query execution.
Cause:
In JumbleExpr there is no handling for node tag and T_TableValueExpr and
T_GroupingSet is handled incorrectly. Jumble hashing is used as queryId.
Error message "unrecognized RTE kind: 7" caused by not handled range table
type RTE_TABLEFUNCTION in JumbleRangeTable.
Fix:
Handling logic for missed node tags was added.
According to comments in queryjumble.c, main guideline how to handle
query tree is: "Rule of thumb for what to include is that we should ignore
anything not semantically significant (such as alias names) as well as
anything that can be deduced from child nodes (else we'd just be double-
hashing that piece of information)."
For T_GroupingSet we append to the jumble the grouping type
and list of groupsets. Field 'location' is not appended to the jumble because
it is the textual location from parser and is not semantically significant.
For RTE_TABLEFUNCTION - 'functions' field of RangeTblEntry was added to the
jumble. RangeTblEntry in case of RTE_TABLEFUNCTION uses 'functions' and
'subquery' fields (other significant fields are null). But 'subquery' is
duplicated in TableValueExpr below, so do not jumble it.
For T_TableValueExpr - 'subquery' field of TableValueExpr (the subquery
that is inside "TABLE()" statement) was added to the jumble.
Changes from original commit:
T_IntList instead.
GPDB 7, change to match implementation from GPDB 6.
set up shared_preload_libraries and they don't disable optimizer. Add files
enable_pg_stat_statements and disable_pg_stat_statements to adapt
pg_stat_statements tests to current testing utilities. This allows to
remove some initialization and cleanup from the new test.
the table has no rows in it.
(cherry picked from commit fa44e50)
Note: Do not squash to preserve authorship
To test comment out the
NO_INSTALLCHECK = 1
incontrib/pg_stat_statements/Makefile
, and then run