@@ -44,6 +44,7 @@ void _PG_init(void);
44
44
static bool shmem_initialized = false;
45
45
46
46
/* Hooks */
47
+ static ExecutorStart_hook_type prev_ExecutorStart = NULL ;
47
48
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL ;
48
49
static planner_hook_type planner_hook_next = NULL ;
49
50
@@ -67,6 +68,7 @@ static PlannedStmt *pgws_planner_hook(Query *parse,
67
68
const char * query_string ,
68
69
#endif
69
70
int cursorOptions , ParamListInfo boundParams );
71
+ static void pgws_ExecutorStart (QueryDesc * queryDesc , int eflags );
70
72
static void pgws_ExecutorEnd (QueryDesc * queryDesc );
71
73
72
74
/*
@@ -402,6 +404,8 @@ _PG_init(void)
402
404
shmem_startup_hook = pgws_shmem_startup ;
403
405
planner_hook_next = planner_hook ;
404
406
planner_hook = pgws_planner_hook ;
407
+ prev_ExecutorStart = ExecutorStart_hook ;
408
+ ExecutorStart_hook = pgws_ExecutorStart ;
405
409
prev_ExecutorEnd = ExecutorEnd_hook ;
406
410
ExecutorEnd_hook = pgws_ExecutorEnd ;
407
411
}
@@ -906,6 +910,40 @@ pgws_planner_hook(Query *parse,
906
910
cursorOptions , boundParams );
907
911
}
908
912
913
+ /*
914
+ * ExecutorStart hook: save queryId for collector
915
+ */
916
+ static void
917
+ pgws_ExecutorStart (QueryDesc * queryDesc , int eflags )
918
+ {
919
+ int i ;
920
+ uint64 saved_queryid ;
921
+ bool restore_queryid = false;
922
+
923
+ if (MyProc )
924
+ {
925
+ i = MyProc - ProcGlobal -> allProcs ;
926
+ #if PG_VERSION_NUM >= 110000
927
+ /*
928
+ * since we depend on queryId we need to check that its size
929
+ * is uint64 as we coded in pg_wait_sampling
930
+ */
931
+ StaticAssertExpr (sizeof (queryDesc -> plannedstmt -> queryId ) == sizeof (uint64 ),
932
+ "queryId size is not uint64" );
933
+ #else
934
+ StaticAssertExpr (sizeof (queryDesc -> plannedstmt -> queryId ) == sizeof (uint32 ),
935
+ "queryId size is not uint32" );
936
+ #endif
937
+ if (!pgws_proc_queryids [i ])
938
+ pgws_proc_queryids [i ] = parse -> queryId ;
939
+ }
940
+
941
+ if (prev_ExecutorStart )
942
+ prev_ExecutorStart (queryDesc , eflags );
943
+ else
944
+ standard_ExecutorStart (queryDesc , eflags );
945
+ }
946
+
909
947
/*
910
948
* ExecutorEnd hook: clear queryId
911
949
*/
0 commit comments