Skip to content
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

Normalize: Match GROUP BY against target list and re-use param refs #124

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

lfittl
Copy link
Member

@lfittl lfittl commented Oct 11, 2021

This avoids "columns ... must appear in the GROUP BY clause ..." type
errors when the normalize result is utilized as a parameterized query
with Postgres. We reuse the pg_query fingerprinting logic to determine
whether a target list element is identical with a GROUP BY element.

Note that query data coming from pg_stat_statements normalizes the target
list, but not the GROUP BY list.

Additionally, this overly optimizes for reusing param refs, specifically
when the target list contains elements that are similar, but not 100%
identical, we err on matching them (based on the pg_query fingerprint),
instead of requiring full equivalency. e.g. the target list may contain
a certain string constant and we would consider any other string constant
in the GROUP BY to be equivalent (since they have the same fingerprint).

@lfittl lfittl force-pushed the 13-latest-normalize-group-by-targetlist-match branch 2 times, most recently from 176bfb2 to 9680717 Compare October 11, 2021 18:41
This avoids "columns ... must appear in the GROUP BY clause ..." type
errors when the normalize result is utilized as a parameterized query
with Postgres. We reuse the pg_query fingerprinting logic to determine
whether a target list element is identical with a GROUP BY element.

Note that query data coming from pg_stat_statements normalizes the target
list, but not the GROUP BY list.

Additionally, this overly optimizes for reusing param refs, specifically
when the target list contains elements that are similar, but not 100%
identical, we err on matching them (based on the pg_query fingerprint),
instead of requiring full equivalency. e.g. the target list may contain
a certain string constant and we would consider any other string constant
in the GROUP BY to be equivalent (since they have the same fingerprint).
@lfittl lfittl force-pushed the 13-latest-normalize-group-by-targetlist-match branch from 9680717 to b47233d Compare October 12, 2021 18:07
@lfittl lfittl merged commit 6ad28d6 into 13-latest Oct 12, 2021
@lfittl lfittl deleted the 13-latest-normalize-group-by-targetlist-match branch October 12, 2021 19:33
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