-
Notifications
You must be signed in to change notification settings - Fork 65
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
base: refactor-input-helpers
Are you sure you want to change the base?
Conversation
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 { |
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.
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) |
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.
Maybe consider adding a different constructor or argument here to initialize without the data that's not needed (like Postgres version in this case).
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.