25
25
#include "storage/shm_mq.h"
26
26
#include "storage/shm_toc.h"
27
27
#include "storage/spin.h"
28
+ #include "tcop/utility.h"
28
29
#include "utils/builtins.h"
29
30
#include "utils/datetime.h"
30
31
#include "utils/guc_tables.h"
@@ -47,6 +48,7 @@ static ExecutorRun_hook_type prev_ExecutorRun = NULL;
47
48
static ExecutorFinish_hook_type prev_ExecutorFinish = NULL ;
48
49
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL ;
49
50
static planner_hook_type planner_hook_next = NULL ;
51
+ static ProcessUtility_hook_type prev_ProcessUtility = NULL ;
50
52
51
53
/* Current nesting depth of planner/Executor calls */
52
54
static int nesting_level = 0 ;
@@ -77,6 +79,21 @@ static void pgws_ExecutorRun(QueryDesc *queryDesc,
77
79
uint64 count , bool execute_once );
78
80
static void pgws_ExecutorFinish (QueryDesc * queryDesc );
79
81
static void pgws_ExecutorEnd (QueryDesc * queryDesc );
82
+ static void pgws_ProcessUtility (PlannedStmt * pstmt ,
83
+ const char * queryString ,
84
+ #if PG_VERSION_NUM >= 140000
85
+ bool readOnlyTree ,
86
+ #endif
87
+ ProcessUtilityContext context ,
88
+ ParamListInfo params ,
89
+ QueryEnvironment * queryEnv ,
90
+ DestReceiver * dest ,
91
+ #if PG_VERSION_NUM >= 130000
92
+ QueryCompletion * qc
93
+ #else
94
+ char * completionTag
95
+ #endif
96
+ );
80
97
81
98
/*
82
99
* Calculate max processes count.
@@ -424,6 +441,8 @@ _PG_init(void)
424
441
ExecutorFinish_hook = pgws_ExecutorFinish ;
425
442
prev_ExecutorEnd = ExecutorEnd_hook ;
426
443
ExecutorEnd_hook = pgws_ExecutorEnd ;
444
+ prev_ProcessUtility = ProcessUtility_hook ;
445
+ ProcessUtility_hook = pgws_ProcessUtility ;
427
446
}
428
447
429
448
/*
@@ -1024,3 +1043,68 @@ pgws_ExecutorEnd(QueryDesc *queryDesc)
1024
1043
else
1025
1044
standard_ExecutorEnd (queryDesc );
1026
1045
}
1046
+
1047
+ static void
1048
+ pgws_ProcessUtility (PlannedStmt * pstmt ,
1049
+ const char * queryString ,
1050
+ #if PG_VERSION_NUM >= 140000
1051
+ bool readOnlyTree ,
1052
+ #endif
1053
+ ProcessUtilityContext context ,
1054
+ ParamListInfo params ,
1055
+ QueryEnvironment * queryEnv ,
1056
+ DestReceiver * dest ,
1057
+ #if PG_VERSION_NUM >= 130000
1058
+ QueryCompletion * qc
1059
+ #else
1060
+ char * completionTag
1061
+ #endif
1062
+ )
1063
+ {
1064
+ int i = MyProc - ProcGlobal -> allProcs ;
1065
+
1066
+ if (nesting_level == 0 )
1067
+ pgws_proc_queryids [i ] = pstmt -> queryId ;
1068
+
1069
+ nesting_level ++ ;
1070
+ PG_TRY ();
1071
+ {
1072
+ if (prev_ProcessUtility )
1073
+ prev_ProcessUtility (pstmt , queryString ,
1074
+ #if PG_VERSION_NUM >= 140000
1075
+ readOnlyTree ,
1076
+ #endif
1077
+ context , params , queryEnv ,
1078
+ dest ,
1079
+ #if PG_VERSION_NUM >= 130000
1080
+ qc
1081
+ #else
1082
+ completionTag
1083
+ #endif
1084
+ );
1085
+ else
1086
+ standard_ProcessUtility (pstmt , queryString ,
1087
+ #if PG_VERSION_NUM >= 140000
1088
+ readOnlyTree ,
1089
+ #endif
1090
+ context , params , queryEnv ,
1091
+ dest ,
1092
+ #if PG_VERSION_NUM >= 130000
1093
+ qc
1094
+ #else
1095
+ completionTag
1096
+ #endif
1097
+ );
1098
+ nesting_level -- ;
1099
+ if (nesting_level == 0 )
1100
+ pgws_proc_queryids [i ] = UINT64CONST (0 );
1101
+ }
1102
+ PG_CATCH ();
1103
+ {
1104
+ nesting_level -- ;
1105
+ if (nesting_level == 0 )
1106
+ pgws_proc_queryids [i ] = UINT64CONST (0 );
1107
+ PG_RE_THROW ();
1108
+ }
1109
+ PG_END_TRY ();
1110
+ }
0 commit comments