Introduces IsReindexWithParam_compat macro

In ReindexStmt concurrent field is moved to options and then options are converted to params list.
This macro uses previous fields for previous versions and the new params list with a new function named IsReindexWithParam for PG14

Relevant PG commits:
844c05abc3f1c1703bf17cf44ab66351ed9711d2
b5913f6120792465f4394b93c15c2e2ac0c08376
pg14_support_after_rebase
Halil Ozan Akgul 2021-08-13 10:42:00 +03:00 committed by Sait Talha Nisanci
parent 66606843b3
commit c19faedce6
4 changed files with 46 additions and 7 deletions

View File

@ -529,8 +529,8 @@ PreprocessReindexStmt(Node *node, const char *reindexCommand,
{
Relation relation = NULL;
Oid relationId = InvalidOid;
LOCKMODE lockmode = reindexStatement->concurrent ? ShareUpdateExclusiveLock :
AccessExclusiveLock;
LOCKMODE lockmode = IsReindexWithParam_compat(reindexStatement, "concurrently") ?
ShareUpdateExclusiveLock : AccessExclusiveLock;
MemoryContext relationContext = NULL;
Assert(reindexStatement->kind == REINDEX_OBJECT_INDEX ||
@ -539,7 +539,8 @@ PreprocessReindexStmt(Node *node, const char *reindexCommand,
if (reindexStatement->kind == REINDEX_OBJECT_INDEX)
{
struct ReindexIndexCallbackState state;
state.concurrent = reindexStatement->concurrent;
state.concurrent = IsReindexWithParam_compat(reindexStatement,
"concurrently");
state.locked_table_oid = InvalidOid;
Oid indOid = RangeVarGetRelidExtended(reindexStatement->relation,
@ -590,8 +591,10 @@ PreprocessReindexStmt(Node *node, const char *reindexCommand,
{
DDLJob *ddlJob = palloc0(sizeof(DDLJob));
ddlJob->targetRelationId = relationId;
ddlJob->concurrentIndexCmd = reindexStatement->concurrent;
ddlJob->startNewTransaction = reindexStatement->concurrent;
ddlJob->concurrentIndexCmd = IsReindexWithParam_compat(reindexStatement,
"concurrently");
ddlJob->startNewTransaction = IsReindexWithParam_compat(reindexStatement,
"concurrently");
ddlJob->commandString = reindexCommand;
ddlJob->taskList = CreateReindexTaskList(relationId, reindexStatement);

View File

@ -39,6 +39,7 @@
#include "commands/defrem.h"
#include "commands/extension.h"
#include "distributed/citus_ruleutils.h"
#include "distributed/commands.h"
#include "distributed/listutils.h"
#include "distributed/multi_partitioning_utils.h"
#include "distributed/metadata_cache.h"
@ -740,7 +741,8 @@ deparse_shard_reindex_statement(ReindexStmt *origStmt, Oid distrelid, int64 shar
{
ReindexStmt *reindexStmt = copyObject(origStmt); /* copy to avoid modifications */
char *relationName = NULL;
const char *concurrentlyString = reindexStmt->concurrent ? "CONCURRENTLY " : "";
const char *concurrentlyString =
IsReindexWithParam_compat(reindexStmt, "concurrently") ? "CONCURRENTLY " : "";
if (reindexStmt->kind == REINDEX_OBJECT_INDEX ||
@ -754,7 +756,7 @@ deparse_shard_reindex_statement(ReindexStmt *origStmt, Oid distrelid, int64 shar
appendStringInfoString(buffer, "REINDEX ");
if (reindexStmt->options == REINDEXOPT_VERBOSE)
if (IsReindexWithParam_compat(reindexStmt, "verbose"))
{
appendStringInfoString(buffer, "(VERBOSE) ");
}
@ -1237,3 +1239,29 @@ RoleSpecString(RoleSpec *spec, bool withQuoteIdentifier)
}
}
}
#if PG_VERSION_NUM >= PG_VERSION_14
/*
* IsReindexWithParam searches the ReindexStmt's params for paramName
* and returns true if it exists and value of param is true and returns
* false otherwise
*/
bool
IsReindexWithParam(ReindexStmt *stmt, char *paramName)
{
ListCell *lc;
foreach(lc, stmt->params)
{
DefElem *opt = (DefElem *) lfirst(lc);
if (strcmp(opt->defname, paramName) == 0)
{
return defGetBoolean(opt);
}
}
return false;
}
#endif

View File

@ -288,6 +288,9 @@ extern void ErrorIfUnsupportedAlterIndexStmt(AlterTableStmt *alterTableStatement
extern void MarkIndexValid(IndexStmt *indexStmt);
extern List * ExecuteFunctionOnEachTableIndex(Oid relationId, PGIndexProcessor
pgIndexProcessor, int flags);
#if PG_VERSION_NUM >= PG_VERSION_14
extern bool IsReindexWithParam(ReindexStmt *stmt, char *paramName);
#endif
/* objectaddress.c - forward declarations */
extern ObjectAddress CreateExtensionStmtObjectAddress(Node *stmt, bool missing_ok);

View File

@ -47,6 +47,7 @@
#define VACOPTVALUE_UNSPECIFIED_COMPAT VACOPTVALUE_UNSPECIFIED
#define VACOPTVALUE_DISABLED_COMPAT VACOPTVALUE_DISABLED
#define VACOPTVALUE_ENABLED_COMPAT VACOPTVALUE_ENABLED
#define IsReindexWithParam_compat(reindex, param) IsReindexWithParam(reindex, param)
#else
#define AlterTableStmtObjType(a) ((a)->relkind)
#define F_NEXTVAL_COMPAT F_NEXTVAL_OID
@ -64,6 +65,10 @@
#define VACOPTVALUE_UNSPECIFIED_COMPAT VACOPT_TERNARY_DEFAULT
#define VACOPTVALUE_DISABLED_COMPAT VACOPT_TERNARY_DISABLED
#define VACOPTVALUE_ENABLED_COMPAT VACOPT_TERNARY_ENABLED
#define IsReindexWithParam_compat(reindex, param) \
((strcmp(param, "concurrently") == 0) ? ((reindex)->concurrent) : \
((strcmp(param, "verbose") == 0) ? ((reindex)->options == REINDEXOPT_VERBOSE) : \
false))
#endif
#if PG_VERSION_NUM >= PG_VERSION_13