Skip to content

Commit 639f014

Browse files
author
Maksim Milyutin
committed
Refactor pathman_process_utility_callback
1 parent 6187a4e commit 639f014

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

src/hooks.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -755,24 +755,25 @@ pathman_relcache_hook(Datum arg, Oid relid)
755755
*/
756756
void
757757
#if PG_VERSION_NUM >= 100000
758-
pathman_process_utility_hook(PlannedStmt *pstmt,
758+
pathman_process_utility_hook(PlannedStmt *first_arg,
759759
const char *queryString,
760760
ProcessUtilityContext context,
761761
ParamListInfo params,
762762
QueryEnvironment *queryEnv,
763763
DestReceiver *dest, char *completionTag)
764764
{
765-
Node *parsetree = pstmt->utilityStmt;
766-
int stmt_location = pstmt->stmt_location,
767-
stmt_len = pstmt->stmt_len;
765+
Node *parsetree = first_arg->utilityStmt;
766+
int stmt_location = first_arg->stmt_location,
767+
stmt_len = first_arg->stmt_len;
768768
#else
769-
pathman_process_utility_hook(Node *parsetree,
769+
pathman_process_utility_hook(Node *first_arg,
770770
const char *queryString,
771771
ProcessUtilityContext context,
772772
ParamListInfo params,
773773
DestReceiver *dest,
774774
char *completionTag)
775775
{
776+
Node *parsetree = first_arg;
776777
int stmt_location = -1,
777778
stmt_len = 0;
778779
#endif
@@ -825,27 +826,9 @@ pathman_process_utility_hook(Node *parsetree,
825826
}
826827
}
827828

828-
#if PG_VERSION_NUM >= 100000
829-
/* Call hooks set by other extensions if needed */
830-
if (process_utility_hook_next)
831-
process_utility_hook_next(pstmt, queryString,
832-
context, params, queryEnv,
833-
dest, completionTag);
834-
/* Else call internal implementation */
835-
else
836-
standard_ProcessUtility(pstmt, queryString,
837-
context, params, queryEnv,
838-
dest, completionTag);
839-
#else
840-
/* Call hooks set by other extensions if needed */
841-
if (process_utility_hook_next)
842-
process_utility_hook_next(parsetree, queryString,
843-
context, params,
844-
dest, completionTag);
845-
/* Else call internal implementation */
846-
else
847-
standard_ProcessUtility(parsetree, queryString,
848-
context, params,
849-
dest, completionTag);
850-
#endif
829+
/* 'first_arg' is PlannedStmt in pg10 or Node parsetree in pg9.6 and lower */
830+
call_process_utility_compat(
831+
(process_utility_hook_next) ? process_utility_hook_next :
832+
standard_ProcessUtility,
833+
first_arg, queryString, context, params, queryEnv, dest, completionTag);
851834
}

src/include/compat/pg_compat.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@
9797
#endif
9898

9999

100+
/*
101+
* call_process_utility_compat()
102+
*
103+
* the parameter 'first_arg' is:
104+
* - in pg 10 PlannedStmt object
105+
* - in pg 9.6 and lower Node parsetree
106+
*/
107+
#if PG_VERSION_NUM >= 100000
108+
#define call_process_utility_compat(process_utility, first_arg, query_string, \
109+
context, params, query_env, dest, \
110+
completion_tag) \
111+
(process_utility)((first_arg), (query_string), (context), (params), \
112+
(query_env), (dest), (completion_tag))
113+
#elif PG_VERSION_NUM >= 90500
114+
#define call_process_utility_compat(process_utility, first_arg, query_string, \
115+
context, params, query_env, dest, \
116+
completion_tag) \
117+
(process_utility)((first_arg), (query_string), (context), (params), \
118+
(dest), (completion_tag))
119+
#endif
120+
121+
100122
/*
101123
* CatalogIndexInsert()
102124
*/

0 commit comments

Comments
 (0)