diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-10-01 08:56:21 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-10-01 08:56:21 +0900 |
commit | 5deb56387e3a1d08e1e62bed031258db267a0ab5 (patch) | |
tree | 9b69323da51cb561dadaf1f2b16b1c0996287717 /src/backend/executor/execMain.c | |
parent | 102de3be73345a8de443355e055c10762b08cc4c (diff) | |
download | postgresql-5deb56387e3a1d08e1e62bed031258db267a0ab5.tar.gz postgresql-5deb56387e3a1d08e1e62bed031258db267a0ab5.zip |
Expand assertion check for query ID reporting in executor
As formulated, the assertion added in the executor by 24f520594809 to
check that a query ID is set had two problems:
- track_activities may be disabled while compute_query_id is enabled,
causing the query ID to not be reported to pg_stat_activity.
- debug_query_string may not be set in some context. The only path
where this would matter is visibly autovacuum, should parallel workers
be enabled there at some point. This is not the case currently.
There was no test showing the interactions between the query ID and
track_activities, so let's add one based on a scan of pg_stat_activity.
This assertion is still an experimentation at this stage, but let's see
if this shows more paths where query IDs are not properly set while they
should.
Discussion: https://postgr.es/m/Zvn5616oYXmpXyHI@paquier.xyz
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 728cdee480b..b5fbd8af97e 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -71,6 +71,18 @@ ExecutorEnd_hook_type ExecutorEnd_hook = NULL; /* Hook for plugin to get control in ExecCheckPermissions() */ ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook = NULL; +/* + * Check that the query ID is set, which is something that happens only + * if compute_query_id is enabled (or a module forced it), if track_activities + * is enabled, and if a client provided a query string to map with the query + * ID computed from it. + */ +#define EXEC_CHECK_QUERY_ID \ +do { \ + Assert(!IsQueryIdEnabled() || !pgstat_track_activities || \ + !debug_query_string || pgstat_get_my_query_id() != 0); \ +} while(0) + /* decls for local routines only used within this module */ static void InitPlan(QueryDesc *queryDesc, int eflags); static void CheckValidRowMarkRel(Relation rel, RowMarkType markType); @@ -297,7 +309,7 @@ ExecutorRun(QueryDesc *queryDesc, bool execute_once) { /* If enabled, the query ID should be set. */ - Assert(!IsQueryIdEnabled() || pgstat_get_my_query_id() != 0); + EXEC_CHECK_QUERY_ID; if (ExecutorRun_hook) (*ExecutorRun_hook) (queryDesc, direction, count, execute_once); @@ -408,7 +420,7 @@ void ExecutorFinish(QueryDesc *queryDesc) { /* If enabled, the query ID should be set. */ - Assert(!IsQueryIdEnabled() || pgstat_get_my_query_id() != 0); + EXEC_CHECK_QUERY_ID; if (ExecutorFinish_hook) (*ExecutorFinish_hook) (queryDesc); @@ -471,7 +483,7 @@ void ExecutorEnd(QueryDesc *queryDesc) { /* If enabled, the query ID should be set. */ - Assert(!IsQueryIdEnabled() || pgstat_get_my_query_id() != 0); + EXEC_CHECK_QUERY_ID; if (ExecutorEnd_hook) (*ExecutorEnd_hook) (queryDesc); |