diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index a0b0f91ef..8934bb1d4 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -15,6 +15,7 @@ #include "distributed/commands.h" #include "distributed/deparser.h" #include "distributed/pg_version_constants.h" +#include "distributed/version_compat.h" static DistributeObjectOps NoDistributeOps = { .deparse = NULL, @@ -772,7 +773,7 @@ GetDistributeObjectOps(Node *node) case T_AlterTableStmt: { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - switch (stmt->relkind) + switch (AlterTableStmtObjType(stmt)) { case OBJECT_TYPE: { diff --git a/src/backend/distributed/commands/sequence.c b/src/backend/distributed/commands/sequence.c index 94c0867f0..10df671a4 100644 --- a/src/backend/distributed/commands/sequence.c +++ b/src/backend/distributed/commands/sequence.c @@ -595,7 +595,7 @@ PreprocessAlterSequenceOwnerStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); ObjectAddress sequenceAddress = GetObjectAddressFromParseTree((Node *) stmt, false); if (!ShouldPropagateObject(&sequenceAddress)) @@ -623,7 +623,7 @@ ObjectAddress AlterSequenceOwnerStmtObjectAddress(Node *node, bool missing_ok) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); RangeVar *sequence = stmt->relation; Oid seqOid = RangeVarGetRelid(sequence, NoLock, missing_ok); @@ -643,7 +643,7 @@ List * PostprocessAlterSequenceOwnerStmt(Node *node, const char *queryString) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); ObjectAddress sequenceAddress = GetObjectAddressFromParseTree((Node *) stmt, false); if (!ShouldPropagateObject(&sequenceAddress)) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index b34d6b25a..f72b1b2bf 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -524,7 +524,7 @@ PreprocessAlterTableStmt(Node *node, const char *alterTableCommand, if (get_rel_relkind(leftRelationId) == RELKIND_SEQUENCE) { AlterTableStmt *stmtCopy = copyObject(alterTableStatement); - stmtCopy->relkind = OBJECT_SEQUENCE; + AlterTableStmtObjType(stmtCopy) = OBJECT_SEQUENCE; return PreprocessAlterSequenceOwnerStmt((Node *) stmtCopy, alterTableCommand, processUtilityContext); } @@ -1617,7 +1617,7 @@ PostprocessAlterTableStmt(AlterTableStmt *alterTableStatement) */ if (get_rel_relkind(relationId) == RELKIND_SEQUENCE) { - alterTableStatement->relkind = OBJECT_SEQUENCE; + AlterTableStmtObjType(alterTableStatement) = OBJECT_SEQUENCE; PostprocessAlterSequenceOwnerStmt((Node *) alterTableStatement, NULL); return; } diff --git a/src/backend/distributed/commands/type.c b/src/backend/distributed/commands/type.c index c170d2129..a2f198c78 100644 --- a/src/backend/distributed/commands/type.c +++ b/src/backend/distributed/commands/type.c @@ -206,7 +206,7 @@ PreprocessAlterTypeStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_TYPE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TYPE); ObjectAddress typeAddress = GetObjectAddressFromParseTree((Node *) stmt, false); if (!ShouldPropagateObject(&typeAddress)) @@ -789,7 +789,7 @@ ObjectAddress AlterTypeStmtObjectAddress(Node *node, bool missing_ok) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_TYPE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TYPE); TypeName *typeName = MakeTypeNameFromRangeVar(stmt->relation); Oid typeOid = LookupTypeNameOid(NULL, typeName, missing_ok); diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index eb10abda5..314c18962 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -473,8 +473,8 @@ ProcessUtilityInternal(PlannedStmt *pstmt, if (IsA(parsetree, AlterTableStmt)) { AlterTableStmt *alterTableStmt = (AlterTableStmt *) parsetree; - if (alterTableStmt->relkind == OBJECT_TABLE || - alterTableStmt->relkind == OBJECT_FOREIGN_TABLE) + if (AlterTableStmtObjType(alterTableStmt) == OBJECT_TABLE || + AlterTableStmtObjType(alterTableStmt) == OBJECT_FOREIGN_TABLE) { ErrorIfAlterDropsPartitionColumn(alterTableStmt); diff --git a/src/backend/distributed/deparser/deparse_sequence_stmts.c b/src/backend/distributed/deparser/deparse_sequence_stmts.c index 3fbabf962..c074a2d95 100644 --- a/src/backend/distributed/deparser/deparse_sequence_stmts.c +++ b/src/backend/distributed/deparser/deparse_sequence_stmts.c @@ -15,6 +15,7 @@ #include "catalog/namespace.h" #include "distributed/deparser.h" +#include "distributed/version_compat.h" #include "utils/acl.h" #include "utils/builtins.h" #include "utils/lsyscache.h" @@ -193,7 +194,7 @@ DeparseAlterSequenceOwnerStmt(Node *node) StringInfoData str = { 0 }; initStringInfo(&str); - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); AppendAlterSequenceOwnerStmt(&str, stmt); @@ -208,7 +209,7 @@ DeparseAlterSequenceOwnerStmt(Node *node) static void AppendAlterSequenceOwnerStmt(StringInfo buf, AlterTableStmt *stmt) { - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); RangeVar *seq = stmt->relation; char *qualifiedSequenceName = quote_qualified_identifier(seq->schemaname, seq->relname); diff --git a/src/backend/distributed/deparser/deparse_table_stmts.c b/src/backend/distributed/deparser/deparse_table_stmts.c index 8b63207f4..83289bc5c 100644 --- a/src/backend/distributed/deparser/deparse_table_stmts.c +++ b/src/backend/distributed/deparser/deparse_table_stmts.c @@ -12,6 +12,7 @@ #include "postgres.h" #include "distributed/deparser.h" +#include "distributed/version_compat.h" #include "nodes/nodes.h" #include "nodes/parsenodes.h" #include "parser/parse_type.h" @@ -63,7 +64,7 @@ DeparseAlterTableStmt(Node *node) StringInfoData str = { 0 }; initStringInfo(&str); - Assert(stmt->relkind == OBJECT_TABLE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TABLE); AppendAlterTableStmt(&str, stmt); return str.data; @@ -82,7 +83,7 @@ AppendAlterTableStmt(StringInfo buf, AlterTableStmt *stmt) stmt->relation->relname); ListCell *cmdCell = NULL; - Assert(stmt->relkind == OBJECT_TABLE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TABLE); appendStringInfo(buf, "ALTER TABLE %s", identifier); foreach(cmdCell, stmt->cmds) diff --git a/src/backend/distributed/deparser/deparse_type_stmts.c b/src/backend/distributed/deparser/deparse_type_stmts.c index 07f84e185..8966f9016 100644 --- a/src/backend/distributed/deparser/deparse_type_stmts.c +++ b/src/backend/distributed/deparser/deparse_type_stmts.c @@ -26,6 +26,7 @@ #include "distributed/citus_ruleutils.h" #include "distributed/commands.h" #include "distributed/deparser.h" +#include "distributed/version_compat.h" #define AlterEnumIsRename(stmt) (stmt->oldVal != NULL) #define AlterEnumIsAddValue(stmt) (stmt->oldVal == NULL) @@ -121,7 +122,7 @@ DeparseAlterTypeStmt(Node *node) StringInfoData str = { 0 }; initStringInfo(&str); - Assert(stmt->relkind == OBJECT_TYPE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TYPE); AppendAlterTypeStmt(&str, stmt); @@ -136,7 +137,7 @@ AppendAlterTypeStmt(StringInfo buf, AlterTableStmt *stmt) stmt->relation->relname); ListCell *cmdCell = NULL; - Assert(stmt->relkind == OBJECT_TYPE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TYPE); appendStringInfo(buf, "ALTER TYPE %s", identifier); foreach(cmdCell, stmt->cmds) diff --git a/src/backend/distributed/deparser/qualify_sequence_stmt.c b/src/backend/distributed/deparser/qualify_sequence_stmt.c index 1ad6a9995..952aa2421 100644 --- a/src/backend/distributed/deparser/qualify_sequence_stmt.c +++ b/src/backend/distributed/deparser/qualify_sequence_stmt.c @@ -18,6 +18,7 @@ #include "postgres.h" #include "distributed/deparser.h" +#include "distributed/version_compat.h" #include "parser/parse_func.h" #include "utils/lsyscache.h" @@ -31,7 +32,7 @@ void QualifyAlterSequenceOwnerStmt(Node *node) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_SEQUENCE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_SEQUENCE); RangeVar *seq = stmt->relation; diff --git a/src/backend/distributed/deparser/qualify_type_stmt.c b/src/backend/distributed/deparser/qualify_type_stmt.c index cc8c2e04e..4728b0032 100644 --- a/src/backend/distributed/deparser/qualify_type_stmt.c +++ b/src/backend/distributed/deparser/qualify_type_stmt.c @@ -25,6 +25,7 @@ #include "catalog/pg_type.h" #include "distributed/commands.h" #include "distributed/deparser.h" +#include "distributed/version_compat.h" #include "nodes/makefuncs.h" #include "parser/parse_type.h" #include "utils/syscache.h" @@ -125,7 +126,7 @@ void QualifyAlterTypeStmt(Node *node) { AlterTableStmt *stmt = castNode(AlterTableStmt, node); - Assert(stmt->relkind == OBJECT_TYPE); + Assert(AlterTableStmtObjType(stmt) == OBJECT_TYPE); if (stmt->relation->schemaname == NULL) { diff --git a/src/include/distributed/version_compat.h b/src/include/distributed/version_compat.h index 50692ad08..66e6add86 100644 --- a/src/include/distributed/version_compat.h +++ b/src/include/distributed/version_compat.h @@ -31,7 +31,9 @@ #endif #if PG_VERSION_NUM >= PG_VERSION_14 +#define AlterTableStmtObjType(a) ((a)->objtype) #else +#define AlterTableStmtObjType(a) ((a)->relkind) #endif #if PG_VERSION_NUM >= PG_VERSION_13