Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit174a786

Browse files
author
Oleg Tselebrovskiy
committed
Add ExecutorStart hook to track top-level queryId for prepared queries
and more precisely in general
1 parent92097fd commit174a786

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎pg_wait_sampling.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void_PG_init(void);
4444
staticboolshmem_initialized= false;
4545

4646
/* Hooks */
47+
staticExecutorStart_hook_typeprev_ExecutorStart=NULL;
4748
staticExecutorEnd_hook_typeprev_ExecutorEnd=NULL;
4849
staticplanner_hook_typeplanner_hook_next=NULL;
4950

@@ -67,6 +68,7 @@ static PlannedStmt *pgws_planner_hook(Query *parse,
6768
constchar*query_string,
6869
#endif
6970
intcursorOptions,ParamListInfoboundParams);
71+
staticvoidpgws_ExecutorStart(QueryDesc*queryDesc,inteflags);
7072
staticvoidpgws_ExecutorEnd(QueryDesc*queryDesc);
7173

7274
/*
@@ -402,6 +404,8 @@ _PG_init(void)
402404
shmem_startup_hook=pgws_shmem_startup;
403405
planner_hook_next=planner_hook;
404406
planner_hook=pgws_planner_hook;
407+
prev_ExecutorStart=ExecutorStart_hook;
408+
ExecutorStart_hook=pgws_ExecutorStart;
405409
prev_ExecutorEnd=ExecutorEnd_hook;
406410
ExecutorEnd_hook=pgws_ExecutorEnd;
407411
}
@@ -906,6 +910,38 @@ pgws_planner_hook(Query *parse,
906910
cursorOptions,boundParams);
907911
}
908912

913+
/*
914+
* ExecutorStart hook: save queryId for collector
915+
*/
916+
staticvoid
917+
pgws_ExecutorStart(QueryDesc*queryDesc,inteflags)
918+
{
919+
inti;
920+
921+
if (MyProc)
922+
{
923+
i=MyProc-ProcGlobal->allProcs;
924+
#ifPG_VERSION_NUM >=110000
925+
/*
926+
* since we depend on queryId we need to check that its size
927+
* is uint64 as we coded in pg_wait_sampling
928+
*/
929+
StaticAssertExpr(sizeof(queryDesc->plannedstmt->queryId)==sizeof(uint64),
930+
"queryId size is not uint64");
931+
#else
932+
StaticAssertExpr(sizeof(queryDesc->plannedstmt->queryId)==sizeof(uint32),
933+
"queryId size is not uint32");
934+
#endif
935+
if (!pgws_proc_queryids[i])
936+
pgws_proc_queryids[i]=queryDesc->plannedstmt->queryId;
937+
}
938+
939+
if (prev_ExecutorStart)
940+
prev_ExecutorStart(queryDesc,eflags);
941+
else
942+
standard_ExecutorStart(queryDesc,eflags);
943+
}
944+
909945
/*
910946
* ExecutorEnd hook: clear queryId
911947
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp