Introduces ProcessUtility macros for readOnlyTree parameter

New macros: standard_ProcessUtility_compat, ProcessUtility_compat, ColumnarProcessUtility_compat, PrevProcessUtilityHook_compat

The functions now have a new bool parameter: readOnlyTree
These new macros give us the ability to use this new parameter for PG14 and it doesn't give the parameter for previous versions

In multi_ProcessUtility and ColumnarProcessUtility, before doing anything else, we check if readOnlyTree parameter is true and create a copy of pstmt
Existing readOnlyTree parameters are set to false since we already handle the read only case at multi_ProcessUtility and ColumnarProcessUtility

Relevant PG commit:
7c337b6b527b7052e6a751f966d5734c56f668b5
pull/5209/head
Halil Ozan Akgul 2021-08-13 19:48:50 +03:00 committed by Sait Talha Nisanci
parent 5df6251619
commit 82858ca8fe
5 changed files with 59 additions and 15 deletions

View File

@ -118,6 +118,9 @@ static void ColumnarTableAMObjectAccessHook(ObjectAccessType access, Oid classId
void *arg); void *arg);
static void ColumnarProcessUtility(PlannedStmt *pstmt, static void ColumnarProcessUtility(PlannedStmt *pstmt,
const char *queryString, const char *queryString,
#if PG_VERSION_NUM >= PG_VERSION_14
bool readOnlyTree,
#endif
ProcessUtilityContext context, ProcessUtilityContext context,
ParamListInfo params, ParamListInfo params,
struct QueryEnvironment *queryEnv, struct QueryEnvironment *queryEnv,
@ -2006,12 +2009,23 @@ ColumnarTableAMObjectAccessHook(ObjectAccessType access, Oid classId, Oid object
static void static void
ColumnarProcessUtility(PlannedStmt *pstmt, ColumnarProcessUtility(PlannedStmt *pstmt,
const char *queryString, const char *queryString,
#if PG_VERSION_NUM >= PG_VERSION_14
bool readOnlyTree,
#endif
ProcessUtilityContext context, ProcessUtilityContext context,
ParamListInfo params, ParamListInfo params,
struct QueryEnvironment *queryEnv, struct QueryEnvironment *queryEnv,
DestReceiver *dest, DestReceiver *dest,
QueryCompletionCompat *completionTag) QueryCompletionCompat *completionTag)
{ {
#if PG_VERSION_NUM >= PG_VERSION_14
if (readOnlyTree)
{
pstmt = copyObject(pstmt);
}
#endif
Node *parsetree = pstmt->utilityStmt; Node *parsetree = pstmt->utilityStmt;
if (IsA(parsetree, IndexStmt)) if (IsA(parsetree, IndexStmt))
@ -2034,7 +2048,7 @@ ColumnarProcessUtility(PlannedStmt *pstmt,
RelationClose(rel); RelationClose(rel);
} }
PrevProcessUtilityHook(pstmt, queryString, context, PrevProcessUtilityHook_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
} }

View File

@ -111,7 +111,7 @@ ProcessUtilityParseTree(Node *node, const char *queryString, ProcessUtilityConte
plannedStmt->commandType = CMD_UTILITY; plannedStmt->commandType = CMD_UTILITY;
plannedStmt->utilityStmt = node; plannedStmt->utilityStmt = node;
ProcessUtility(plannedStmt, queryString, context, params, NULL, dest, ProcessUtility_compat(plannedStmt, queryString, false, context, params, NULL, dest,
completionTag); completionTag);
} }
@ -128,13 +128,25 @@ ProcessUtilityParseTree(Node *node, const char *queryString, ProcessUtilityConte
void void
multi_ProcessUtility(PlannedStmt *pstmt, multi_ProcessUtility(PlannedStmt *pstmt,
const char *queryString, const char *queryString,
#if PG_VERSION_NUM >= PG_VERSION_14
bool readOnlyTree,
#endif
ProcessUtilityContext context, ProcessUtilityContext context,
ParamListInfo params, ParamListInfo params,
struct QueryEnvironment *queryEnv, struct QueryEnvironment *queryEnv,
DestReceiver *dest, DestReceiver *dest,
QueryCompletionCompat *completionTag) QueryCompletionCompat *completionTag)
{ {
Node *parsetree = pstmt->utilityStmt; Node *parsetree;
#if PG_VERSION_NUM >= PG_VERSION_14
if (readOnlyTree)
{
pstmt = copyObject(pstmt);
}
#endif
parsetree = pstmt->utilityStmt;
if (IsA(parsetree, TransactionStmt) || if (IsA(parsetree, TransactionStmt) ||
IsA(parsetree, LockStmt) || IsA(parsetree, LockStmt) ||
@ -154,7 +166,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
* that state. Since we never need to intercept transaction statements, * that state. Since we never need to intercept transaction statements,
* skip our checks and immediately fall into standard_ProcessUtility. * skip our checks and immediately fall into standard_ProcessUtility.
*/ */
standard_ProcessUtility(pstmt, queryString, context, standard_ProcessUtility_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
return; return;
@ -173,7 +185,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
* Ensure that utility commands do not behave any differently until CREATE * Ensure that utility commands do not behave any differently until CREATE
* EXTENSION is invoked. * EXTENSION is invoked.
*/ */
standard_ProcessUtility(pstmt, queryString, context, standard_ProcessUtility_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
return; return;
@ -205,7 +217,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
PG_TRY(); PG_TRY();
{ {
standard_ProcessUtility(pstmt, queryString, context, standard_ProcessUtility_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
StoredProcedureLevel -= 1; StoredProcedureLevel -= 1;
@ -229,7 +241,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
PG_TRY(); PG_TRY();
{ {
standard_ProcessUtility(pstmt, queryString, context, standard_ProcessUtility_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
DoBlockLevel -= 1; DoBlockLevel -= 1;
@ -566,7 +578,7 @@ ProcessUtilityInternal(PlannedStmt *pstmt,
citusCanBeUpdatedToAvailableVersion = !InstalledAndAvailableVersionsSame(); citusCanBeUpdatedToAvailableVersion = !InstalledAndAvailableVersionsSame();
} }
standard_ProcessUtility(pstmt, queryString, context, standard_ProcessUtility_compat(pstmt, queryString, false, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);
/* /*

View File

@ -13,7 +13,15 @@
#define COLUMNAR_COMPAT_H #define COLUMNAR_COMPAT_H
#if PG_VERSION_NUM >= PG_VERSION_14 #if PG_VERSION_NUM >= PG_VERSION_14
#define ColumnarProcessUtility_compat(a, b, c, d, e, f, g, h) \
ColumnarProcessUtility(a, b, c, d, e, f, g, h)
#define PrevProcessUtilityHook_compat(a, b, c, d, e, f, g, h) \
PrevProcessUtilityHook(a, b, c, d, e, f, g, h)
#else #else
#define ColumnarProcessUtility_compat(a, b, c, d, e, f, g, h) \
ColumnarProcessUtility(a, b, d, e, f, g, h)
#define PrevProcessUtilityHook_compat(a, b, c, d, e, f, g, h) \
PrevProcessUtilityHook(a, b, d, e, f, g, h)
#endif #endif
#define ACLCHECK_OBJECT_TABLE OBJECT_TABLE #define ACLCHECK_OBJECT_TABLE OBJECT_TABLE

View File

@ -64,6 +64,9 @@ typedef struct DDLJob
extern void multi_ProcessUtility(PlannedStmt *pstmt, const char *queryString, extern void multi_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
#if PG_VERSION_NUM >= PG_VERSION_14
bool readOnlyTree,
#endif
ProcessUtilityContext context, ParamListInfo params, ProcessUtilityContext context, ParamListInfo params,
struct QueryEnvironment *queryEnv, DestReceiver *dest, struct QueryEnvironment *queryEnv, DestReceiver *dest,
QueryCompletionCompat *completionTag QueryCompletionCompat *completionTag

View File

@ -50,6 +50,10 @@
#define IsReindexWithParam_compat(reindex, param) IsReindexWithParam(reindex, param) #define IsReindexWithParam_compat(reindex, param) IsReindexWithParam(reindex, param)
#define CopyFromState_compat CopyFromState #define CopyFromState_compat CopyFromState
#define BeginCopyFrom_compat(a, b, c, d, e, f, g, h) BeginCopyFrom(a, b, c, d, e, f, g, h) #define BeginCopyFrom_compat(a, b, c, d, e, f, g, h) BeginCopyFrom(a, b, c, d, e, f, g, h)
#define standard_ProcessUtility_compat(a, b, c, d, e, f, g, h) \
standard_ProcessUtility(a, b, c, d, e, f, g, h)
#define ProcessUtility_compat(a, b, c, d, e, f, g, h) \
ProcessUtility(a, b, c, d, e, f, g, h)
#else #else
#define AlterTableStmtObjType(a) ((a)->relkind) #define AlterTableStmtObjType(a) ((a)->relkind)
#define F_NEXTVAL_COMPAT F_NEXTVAL_OID #define F_NEXTVAL_COMPAT F_NEXTVAL_OID
@ -73,6 +77,9 @@
false)) false))
#define CopyFromState_compat CopyState #define CopyFromState_compat CopyState
#define BeginCopyFrom_compat(a, b, c, d, e, f, g, h) BeginCopyFrom(a, b, d, e, f, g, h) #define BeginCopyFrom_compat(a, b, c, d, e, f, g, h) BeginCopyFrom(a, b, d, e, f, g, h)
#define standard_ProcessUtility_compat(a, b, c, d, e, f, g, h) \
standard_ProcessUtility(a, b, d, e, f, g, h)
#define ProcessUtility_compat(a, b, c, d, e, f, g, h) ProcessUtility(a, b, d, e, f, g, h)
#endif #endif
#if PG_VERSION_NUM >= PG_VERSION_13 #if PG_VERSION_NUM >= PG_VERSION_13