Rename field "relkind" to "objtype" for CTAS and ALTER TABLE nodes
authorMichael Paquier <michael@paquier.xyz>
Sat, 11 Jul 2020 04:32:28 +0000 (13:32 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 11 Jul 2020 04:32:28 +0000 (13:32 +0900)
"relkind" normally refers to the char field from pg_class.  However, in
the parse nodes AlterTableStmt and CreateTableAsStmt, "relkind" was used
for a field of type enum ObjectType, that could refer to other object
types than those possible for a relkind.  Such fields being usually
named "objtype", switch the name in both structures to make things more
consistent.  Note that this led to some confusion in functions that
also operate on a RangeTableEntry object, which also has a field named
"relkind".

This naming goes back to commit 09d4e96, where only OBJECT_TABLE and
OBJECT_INDEX were used.  This got extended later to use as well
OBJECT_TYPE with e440e12, not really a relation kind.

Author: Mark Dilger
Reviewed-by: Daniel Gustafsson, Álvaro Herrera, Michael Paquier
Discussion: https://postgr.es/m/609181AE-E399-47C7-9221-856E0F96BF93@enterprisedb.com

src/backend/commands/tablecmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/analyze.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/backend/tcop/utility.c
src/include/nodes/parsenodes.h

index 26700da278912afa7156d1099d48fac6bd71b380..ed553f73841c5f0b1eb8a7127ab6621f311e0964 100644 (file)
@@ -4709,7 +4709,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
                                         -1);
        atstmt->relation->inh = recurse;
        atstmt->cmds = list_make1(cmd);
-       atstmt->relkind = OBJECT_TABLE; /* needn't be picky here */
+       atstmt->objtype = OBJECT_TABLE; /* needn't be picky here */
        atstmt->missing_ok = false;
 
        /* Transform the AlterTableStmt */
@@ -15594,7 +15594,7 @@ RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, Oid oldrelid,
                reltype = ((AlterObjectSchemaStmt *) stmt)->objectType;
 
        else if (IsA(stmt, AlterTableStmt))
-               reltype = ((AlterTableStmt *) stmt)->relkind;
+               reltype = ((AlterTableStmt *) stmt)->objtype;
        else
        {
                elog(ERROR, "unrecognized node type: %d", (int) nodeTag(stmt));
index d8cf87e6d0886eaf177b0d7cbca0988c0889752e..89c409de6640a90ab6794336c6c191ac4bd10c0f 100644 (file)
@@ -3204,7 +3204,7 @@ _copyAlterTableStmt(const AlterTableStmt *from)
 
        COPY_NODE_FIELD(relation);
        COPY_NODE_FIELD(cmds);
-       COPY_SCALAR_FIELD(relkind);
+       COPY_SCALAR_FIELD(objtype);
        COPY_SCALAR_FIELD(missing_ok);
 
        return newnode;
@@ -3980,7 +3980,7 @@ _copyCreateTableAsStmt(const CreateTableAsStmt *from)
 
        COPY_NODE_FIELD(query);
        COPY_NODE_FIELD(into);
-       COPY_SCALAR_FIELD(relkind);
+       COPY_SCALAR_FIELD(objtype);
        COPY_SCALAR_FIELD(is_select_into);
        COPY_SCALAR_FIELD(if_not_exists);
 
index 627b026b195e570d964be44b45bb15614f342b53..e3f33c40be53c2a6b00bed109da793a8c3a43d33 100644 (file)
@@ -1087,7 +1087,7 @@ _equalAlterTableStmt(const AlterTableStmt *a, const AlterTableStmt *b)
 {
        COMPARE_NODE_FIELD(relation);
        COMPARE_NODE_FIELD(cmds);
-       COMPARE_SCALAR_FIELD(relkind);
+       COMPARE_SCALAR_FIELD(objtype);
        COMPARE_SCALAR_FIELD(missing_ok);
 
        return true;
@@ -1735,7 +1735,7 @@ _equalCreateTableAsStmt(const CreateTableAsStmt *a, const CreateTableAsStmt *b)
 {
        COMPARE_NODE_FIELD(query);
        COMPARE_NODE_FIELD(into);
-       COMPARE_SCALAR_FIELD(relkind);
+       COMPARE_SCALAR_FIELD(objtype);
        COMPARE_SCALAR_FIELD(is_select_into);
        COMPARE_SCALAR_FIELD(if_not_exists);
 
index 401da5dedf73b5c0076dd0144e1530819e2da9df..c159fb2957bad1a2a2cd4001e2082a5d3734edf3 100644 (file)
@@ -229,7 +229,7 @@ transformOptionalSelectInto(ParseState *pstate, Node *parseTree)
 
                        ctas->query = parseTree;
                        ctas->into = stmt->intoClause;
-                       ctas->relkind = OBJECT_TABLE;
+                       ctas->objtype = OBJECT_TABLE;
                        ctas->is_select_into = true;
 
                        /*
@@ -2572,7 +2572,7 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
        stmt->query = (Node *) query;
 
        /* additional work needed for CREATE MATERIALIZED VIEW */
-       if (stmt->relkind == OBJECT_MATVIEW)
+       if (stmt->objtype == OBJECT_MATVIEW)
        {
                /*
                 * Prohibit a data-modifying CTE in the query used to create a
index 1ea1fba43acc497af0efcf841395bb72850f4b85..dbb47d498290b394b7f73dad44cbb1a17868c112 100644 (file)
@@ -1844,7 +1844,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = $4;
-                                       n->relkind = OBJECT_TABLE;
+                                       n->objtype = OBJECT_TABLE;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1853,7 +1853,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $5;
                                        n->cmds = $6;
-                                       n->relkind = OBJECT_TABLE;
+                                       n->objtype = OBJECT_TABLE;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -1862,7 +1862,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = list_make1($4);
-                                       n->relkind = OBJECT_TABLE;
+                                       n->objtype = OBJECT_TABLE;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1871,7 +1871,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $5;
                                        n->cmds = list_make1($6);
-                                       n->relkind = OBJECT_TABLE;
+                                       n->objtype = OBJECT_TABLE;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -1902,7 +1902,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = $4;
-                                       n->relkind = OBJECT_INDEX;
+                                       n->objtype = OBJECT_INDEX;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1911,7 +1911,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $5;
                                        n->cmds = $6;
-                                       n->relkind = OBJECT_INDEX;
+                                       n->objtype = OBJECT_INDEX;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -1920,7 +1920,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = list_make1($4);
-                                       n->relkind = OBJECT_INDEX;
+                                       n->objtype = OBJECT_INDEX;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1951,7 +1951,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = $4;
-                                       n->relkind = OBJECT_SEQUENCE;
+                                       n->objtype = OBJECT_SEQUENCE;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1960,7 +1960,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $5;
                                        n->cmds = $6;
-                                       n->relkind = OBJECT_SEQUENCE;
+                                       n->objtype = OBJECT_SEQUENCE;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -1969,7 +1969,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $3;
                                        n->cmds = $4;
-                                       n->relkind = OBJECT_VIEW;
+                                       n->objtype = OBJECT_VIEW;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1978,7 +1978,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $5;
                                        n->cmds = $6;
-                                       n->relkind = OBJECT_VIEW;
+                                       n->objtype = OBJECT_VIEW;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -1987,7 +1987,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $4;
                                        n->cmds = $5;
-                                       n->relkind = OBJECT_MATVIEW;
+                                       n->objtype = OBJECT_MATVIEW;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -1996,7 +1996,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $6;
                                        n->cmds = $7;
-                                       n->relkind = OBJECT_MATVIEW;
+                                       n->objtype = OBJECT_MATVIEW;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -2027,7 +2027,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $4;
                                        n->cmds = $5;
-                                       n->relkind = OBJECT_FOREIGN_TABLE;
+                                       n->objtype = OBJECT_FOREIGN_TABLE;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
                                }
@@ -2036,7 +2036,7 @@ AlterTableStmt:
                                        AlterTableStmt *n = makeNode(AlterTableStmt);
                                        n->relation = $6;
                                        n->cmds = $7;
-                                       n->relkind = OBJECT_FOREIGN_TABLE;
+                                       n->objtype = OBJECT_FOREIGN_TABLE;
                                        n->missing_ok = true;
                                        $$ = (Node *)n;
                                }
@@ -2856,7 +2856,7 @@ AlterCompositeTypeStmt:
                                        /* can't use qualified_name, sigh */
                                        n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
                                        n->cmds = $4;
-                                       n->relkind = OBJECT_TYPE;
+                                       n->objtype = OBJECT_TYPE;
                                        $$ = (Node *)n;
                                }
                        ;
@@ -4072,7 +4072,7 @@ CreateAsStmt:
                                        CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
                                        ctas->query = $6;
                                        ctas->into = $4;
-                                       ctas->relkind = OBJECT_TABLE;
+                                       ctas->objtype = OBJECT_TABLE;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = false;
                                        /* cram additional flags into the IntoClause */
@@ -4085,7 +4085,7 @@ CreateAsStmt:
                                        CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
                                        ctas->query = $9;
                                        ctas->into = $7;
-                                       ctas->relkind = OBJECT_TABLE;
+                                       ctas->objtype = OBJECT_TABLE;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = true;
                                        /* cram additional flags into the IntoClause */
@@ -4131,7 +4131,7 @@ CreateMatViewStmt:
                                        CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
                                        ctas->query = $7;
                                        ctas->into = $5;
-                                       ctas->relkind = OBJECT_MATVIEW;
+                                       ctas->objtype = OBJECT_MATVIEW;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = false;
                                        /* cram additional flags into the IntoClause */
@@ -4144,7 +4144,7 @@ CreateMatViewStmt:
                                        CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
                                        ctas->query = $10;
                                        ctas->into = $8;
-                                       ctas->relkind = OBJECT_MATVIEW;
+                                       ctas->objtype = OBJECT_MATVIEW;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = true;
                                        /* cram additional flags into the IntoClause */
@@ -10695,7 +10695,7 @@ ExecuteStmt: EXECUTE name execute_param_clause
                                        n->params = $8;
                                        ctas->query = (Node *) n;
                                        ctas->into = $4;
-                                       ctas->relkind = OBJECT_TABLE;
+                                       ctas->objtype = OBJECT_TABLE;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = false;
                                        /* cram additional flags into the IntoClause */
@@ -10712,7 +10712,7 @@ ExecuteStmt: EXECUTE name execute_param_clause
                                        n->params = $11;
                                        ctas->query = (Node *) n;
                                        ctas->into = $7;
-                                       ctas->relkind = OBJECT_TABLE;
+                                       ctas->objtype = OBJECT_TABLE;
                                        ctas->is_select_into = false;
                                        ctas->if_not_exists = true;
                                        /* cram additional flags into the IntoClause */
index 0e4caa6ad47b54eaf758ac18a1bf2f27e00661e5..25abc544fc7214229624e4cabac812951e4a6232 100644 (file)
@@ -829,7 +829,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
                stmt = makeNode(AlterTableStmt);
                stmt->relation = cxt->relation;
                stmt->cmds = NIL;
-               stmt->relkind = OBJECT_FOREIGN_TABLE;
+               stmt->objtype = OBJECT_FOREIGN_TABLE;
                stmt->cmds = lappend(stmt->cmds, cmd);
 
                cxt->alist = lappend(cxt->alist, stmt);
@@ -2508,7 +2508,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
 
                alterstmt->relation = copyObject(cxt->relation);
                alterstmt->cmds = notnullcmds;
-               alterstmt->relkind = OBJECT_TABLE;
+               alterstmt->objtype = OBJECT_TABLE;
                alterstmt->missing_ok = false;
 
                cxt->alist = lappend(cxt->alist, alterstmt);
@@ -2610,7 +2610,7 @@ transformFKConstraints(CreateStmtContext *cxt,
 
                alterstmt->relation = cxt->relation;
                alterstmt->cmds = NIL;
-               alterstmt->relkind = OBJECT_TABLE;
+               alterstmt->objtype = OBJECT_TABLE;
 
                foreach(fkclist, cxt->fkconstraints)
                {
index 97cbaa3072b0d0b8d6f240b9a4c0d495038ccf40..9b0c376c8cb5f112e40830966a15a390e222b083 100644 (file)
@@ -2574,7 +2574,7 @@ CreateCommandTag(Node *parsetree)
                        break;
 
                case T_AlterTableStmt:
-                       tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
+                       tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->objtype);
                        break;
 
                case T_AlterDomainStmt:
@@ -2752,7 +2752,7 @@ CreateCommandTag(Node *parsetree)
                        break;
 
                case T_CreateTableAsStmt:
-                       switch (((CreateTableAsStmt *) parsetree)->relkind)
+                       switch (((CreateTableAsStmt *) parsetree)->objtype)
                        {
                                case OBJECT_TABLE:
                                        if (((CreateTableAsStmt *) parsetree)->is_select_into)
index 5e1ffafb91b17e3a3de94eebf3b0e4a5725ae45f..151bcdb7ef5b96540cdb9606822ac8f824181f0b 100644 (file)
@@ -1776,7 +1776,7 @@ typedef struct AlterTableStmt
        NodeTag         type;
        RangeVar   *relation;           /* table to work on */
        List       *cmds;                       /* list of subcommands */
-       ObjectType      relkind;                /* type of object */
+       ObjectType      objtype;                /* type of object */
        bool            missing_ok;             /* skip error if table missing */
 } AlterTableStmt;
 
@@ -3275,7 +3275,7 @@ typedef struct CreateTableAsStmt
        NodeTag         type;
        Node       *query;                      /* the query (see comments above) */
        IntoClause *into;                       /* destination table */
-       ObjectType      relkind;                /* OBJECT_TABLE or OBJECT_MATVIEW */
+       ObjectType      objtype;                /* OBJECT_TABLE or OBJECT_MATVIEW */
        bool            is_select_into; /* it was written as SELECT INTO */
        bool            if_not_exists;  /* just do nothing if it already exists? */
 } CreateTableAsStmt;