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

Implement fingerprinting version 3.1 #155

Merged

Conversation

lfittl
Copy link
Member

@lfittl lfittl commented Nov 2, 2022

Consider lists that have a single NIL element as being present for determining
whether the parent field should be included in the fingerprint. In particular,
this matters for fingerprinting "SELECT DISTINCT" without columns specified.

Additionally, ignore more DDL attributes to avoid a lot of unique fingerprints:

(ListenStmt | UnlistenStmt | NotifyStmt).conditionname
=> This groups all LISTEN, UNLISTEN and NOTIFY statements together.
Channels are often made unique to notify about different per end user
objects, causing a lot of unique condition names.

CreateFunctionStmt.options and FunctionParameter.name
=> Some ORMs, like Sequelize.js, have a pattern where they repeatedely
create functions with the exact name and types, but different function
bodies -- this groups all these creations together. We may be more
sophisticated in the future and introduce a "PL/pgSQL fingerprint".

DoStmt.args
=> This groups all anonymous DO code blocks together, since we don't
have a good way to separate them otherwise, for now.

Additionally, fix a few normalization issues.

Consider lists that have a single NIL element as being present for determining
whether the parent field should be included in the fingerprint. In particular,
this matters for fingerprinting "SELECT DISTINCT" without columns specified.

Additionally, ignore more DDL attributes to avoid a lot of unique fingerprints:

(ListenStmt | UnlistenStmt | NotifyStmt).conditionname
=> This groups all LISTEN, UNLISTEN and NOTIFY statements together.
   Channels are often made unique to notify about different per end user
   objects, causing a lot of unique condition names.

CreateFunctionStmt.options and FunctionParameter.name
=> Some ORMs, like Sequelize.js, have a pattern where they repeatedely
   create functions with the exact name and types, but different function
   bodies -- this groups all these creations together. We may be more
   sophisticated in the future and introduce a "PL/pgSQL fingerprint".

DoStmt.args
=> This groups all anonymous DO code blocks together, since we don't
   have a good way to separate them otherwise, for now.
This normalizes arguments to CreateFunctionStmt, DoStmt,
CreateSubscriptionStmt, AlterSubscriptionStmt, CreateUserMapping and
AlterUserMapping.

Note that this is different from pg_stat_statements itself, which does
not normalize utility statements at all today.

In passing, add a helper function to output the JSON of individual parse
nodes, used for debugging only.
sprintf(buffer, "%d", node->relationOid);
_fingerprintString(ctx, "relationOid");
_fingerprintString(ctx, buffer);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the relation oid to the fingerprint if non-zero? Is this part of one of the changes in the description?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting. I wonder how that got in there. That seems more by accident than intentional. Will review (and likely remove). Thanks for noticing!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further review, this looks like it was missed in a prior update. The relationOid is always 0 in the raw parser, so this is effectively a no-op.

test/normalize_tests.c Show resolved Hide resolved
@lfittl lfittl merged commit da177d0 into 13-latest Nov 2, 2022
@lfittl lfittl deleted the 13-latest-fingerprinting-normalization-improvements branch November 2, 2022 23:45
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.

3 participants