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

Improve helper function checks for consistency and lower overhead #680

Open
wants to merge 1 commit into
base: refactor-input-helpers
Choose a base branch
from

Conversation

lfittl
Copy link
Member

@lfittl lfittl commented Feb 17, 2025

This moves the checking for the presence of helper functions to the collection helper, and relies on an upfront querying of pg_proc, instead of querying for each helper individually. Note that we have to support this both for the main database (for all server-wide data points), as well as for each database to get column/extended statistics information.

In passing this also improves the support for checking for different (potentially overloaded) versions of the same functions, by requiring passing the function argument types to the lookup. That is specifically necessary for the multiple historic variants of get_stat_statements that may be present on the same database server, and lets us remove special casing that code.

On top of #679.

This moves the checking for the presence of helper functions to the
collection helper, and relies on an upfront querying of pg_proc, instead
of querying for each helper individually. Note that we have to support
this both for the main database (for all server-wide data points), as
well as for each database to get column/extended statistics information.

In passing we also improves the support for checking for different
(potentially overloaded) versions of the same functions, by requiring
passing the function argument types to the lookup. That is specifically
necessary for the multiple historic variants of get_stat_statements that
may be present on the same database server, and lets us remove special
casing that code.
return state.PostgresFunction{}, false
}

func (s CollectionHelper) HelperExists(name string, inputTypes []string) bool {
Copy link
Member Author

@lfittl lfittl Feb 17, 2025

Choose a reason for hiding this comment

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

For context, I plan to add additional behavior here soon that warns the user (and flags the SelfTest logic) in case the function ownership is not as expected (e.g. you created a helper function with the pganalyze user as the owner, instead of a quasi-superuser/etc). To keep reviews easy I've not yet added this here.

@@ -80,7 +80,12 @@ func runQueryOnDatabase(ctx context.Context, server *state.Server, collectionOpt
}
defer db.Close()

if postgres.StatsHelperExists(ctx, db, "explain_analyze") {
h, err := postgres.NewCollectionHelper(ctx, logger, server, collectionOpts, db)
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe consider adding a different constructor or argument here to initialize without the data that's not needed (like Postgres version in this case).

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