From fe591f8bf68db9bf81f278acce6239ee68cd4ed6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 23 Dec 2016 13:35:11 -0500 Subject: [PATCH] Replace enum InhOption with simple boolean. Now that it has only INH_NO and INH_YES values, it's just weird that it's not a plain bool, so make it that way. Also rename RangeVar.inhOpt to "inh", to be like RangeTblEntry.inh. My recollection is that we gave it a different name specifically because it had a different representation than the derived bool value, but it no longer does. And this is a good forcing function to be sure we catch any places that are affected by the change. Bump catversion because of possible effect on stored RangeVar nodes. I'm not exactly convinced that we ever store RangeVar on disk, but we have a readfuncs function for it, so be cautious. (If we do do so, then commit e13486eba was in error not to bump catversion.) Follow-on to commit e13486eba. Discussion: http://postgr.es/m/CA+TgmoYe+EG7LdYX6pkcNxr4ygkP4+A=jm9o-CPXyOvRiCNwaQ@mail.gmail.com --- src/backend/commands/lockcmds.c | 2 +- src/backend/commands/tablecmds.c | 11 +++++------ src/backend/nodes/copyfuncs.c | 3 +-- src/backend/nodes/equalfuncs.c | 2 +- src/backend/nodes/makefuncs.c | 2 +- src/backend/nodes/outfuncs.c | 2 +- src/backend/nodes/readfuncs.c | 2 +- src/backend/parser/analyze.c | 4 ++-- src/backend/parser/gram.y | 10 +++++----- src/backend/parser/parse_clause.c | 3 +-- src/include/catalog/catversion.h | 2 +- src/include/nodes/primnodes.h | 10 ++-------- 12 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c index ba1414ba64..5cf535b7a6 100644 --- a/src/backend/commands/lockcmds.c +++ b/src/backend/commands/lockcmds.c @@ -54,7 +54,7 @@ LockTableCommand(LockStmt *lockstmt) foreach(p, lockstmt->relations) { RangeVar *rv = (RangeVar *) lfirst(p); - bool recurse = (rv->inhOpt == INH_YES); + bool recurse = rv->inh; Oid reloid; reloid = RangeVarGetRelidExtended(rv, lockstmt->mode, false, diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 0e7601fd94..a7ac85e7ab 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1184,7 +1184,7 @@ ExecuteTruncate(TruncateStmt *stmt) { RangeVar *rv = lfirst(cell); Relation rel; - bool recurse = (rv->inhOpt == INH_YES); + bool recurse = rv->inh; Oid myrelid; rel = heap_openrv(rv, AccessExclusiveLock); @@ -2655,7 +2655,7 @@ renameatt(RenameStmt *stmt) renameatt_internal(relid, stmt->subname, /* old att name */ stmt->newname, /* new att name */ - (stmt->relation->inhOpt == INH_YES), /* recursive? */ + stmt->relation->inh, /* recursive? */ false, /* recursing? */ 0, /* expected inhcount */ stmt->behavior); @@ -2807,7 +2807,8 @@ RenameConstraint(RenameStmt *stmt) rename_constraint_internal(relid, typid, stmt->subname, stmt->newname, - (stmt->relation && stmt->relation->inhOpt == INH_YES), /* recursive? */ + (stmt->relation && + stmt->relation->inh), /* recursive? */ false, /* recursing? */ 0 /* expected inhcount */ ); @@ -3049,9 +3050,7 @@ AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt *stmt) CheckTableNotInUse(rel, "ALTER TABLE"); - ATController(stmt, - rel, stmt->cmds, (stmt->relation->inhOpt == INH_YES), - lockmode); + ATController(stmt, rel, stmt->cmds, stmt->relation->inh, lockmode); } /* diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index d9732259ae..6955298577 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -1112,7 +1112,7 @@ _copyRangeVar(const RangeVar *from) COPY_STRING_FIELD(catalogname); COPY_STRING_FIELD(schemaname); COPY_STRING_FIELD(relname); - COPY_SCALAR_FIELD(inhOpt); + COPY_SCALAR_FIELD(inh); COPY_SCALAR_FIELD(relpersistence); COPY_NODE_FIELD(alias); COPY_LOCATION_FIELD(location); @@ -4192,7 +4192,6 @@ _copyAlterPolicyStmt(const AlterPolicyStmt *from) static PartitionSpec * _copyPartitionSpec(const PartitionSpec *from) { - PartitionSpec *newnode = makeNode(PartitionSpec); COPY_STRING_FIELD(strategy); diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index edc1797c42..548a2aa876 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -108,7 +108,7 @@ _equalRangeVar(const RangeVar *a, const RangeVar *b) COMPARE_STRING_FIELD(catalogname); COMPARE_STRING_FIELD(schemaname); COMPARE_STRING_FIELD(relname); - COMPARE_SCALAR_FIELD(inhOpt); + COMPARE_SCALAR_FIELD(inh); COMPARE_SCALAR_FIELD(relpersistence); COMPARE_NODE_FIELD(alias); COMPARE_LOCATION_FIELD(location); diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index b64f7c6a85..c97532b348 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -423,7 +423,7 @@ makeRangeVar(char *schemaname, char *relname, int location) r->catalogname = NULL; r->schemaname = schemaname; r->relname = relname; - r->inhOpt = INH_YES; + r->inh = true; r->relpersistence = RELPERSISTENCE_PERMANENT; r->alias = NULL; r->location = location; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 7258c0357d..9fe98739c1 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -939,7 +939,7 @@ _outRangeVar(StringInfo str, const RangeVar *node) */ WRITE_STRING_FIELD(schemaname); WRITE_STRING_FIELD(relname); - WRITE_ENUM_FIELD(inhOpt, InhOption); + WRITE_BOOL_FIELD(inh); WRITE_CHAR_FIELD(relpersistence); WRITE_NODE_FIELD(alias); WRITE_LOCATION_FIELD(location); diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index d608530c6e..63f633634c 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -449,7 +449,7 @@ _readRangeVar(void) READ_STRING_FIELD(schemaname); READ_STRING_FIELD(relname); - READ_ENUM_FIELD(inhOpt, InhOption); + READ_BOOL_FIELD(inh); READ_CHAR_FIELD(relpersistence); READ_NODE_FIELD(alias); READ_LOCATION_FIELD(location); diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 601e22abfa..a558083f43 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -380,7 +380,7 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt) /* set up range table with just the result rel */ qry->resultRelation = setTargetTable(pstate, stmt->relation, - (stmt->relation->inhOpt == INH_YES), + stmt->relation->inh, true, ACL_DELETE); @@ -2177,7 +2177,7 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt) } qry->resultRelation = setTargetTable(pstate, stmt->relation, - (stmt->relation->inhOpt == INH_YES), + stmt->relation->inh, true, ACL_UPDATE); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 931bc9aca6..834a00971a 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11250,28 +11250,28 @@ relation_expr: { /* inheritance query, implicitly */ $$ = $1; - $$->inhOpt = INH_YES; + $$->inh = true; $$->alias = NULL; } | qualified_name '*' { - /* inheritance query */ + /* inheritance query, explicitly */ $$ = $1; - $$->inhOpt = INH_YES; + $$->inh = true; $$->alias = NULL; } | ONLY qualified_name { /* no inheritance */ $$ = $2; - $$->inhOpt = INH_NO; + $$->inh = false; $$->alias = NULL; } | ONLY '(' qualified_name ')' { /* no inheritance, SQL99-style syntax */ $$ = $3; - $$->inhOpt = INH_NO; + $$->inh = false; $$->alias = NULL; } ; diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index a96b3f9280..f7bb09701e 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -412,8 +412,7 @@ transformTableEntry(ParseState *pstate, RangeVar *r) RangeTblEntry *rte; /* We need only build a range table entry */ - rte = addRangeTableEntry(pstate, r, r->alias, - (r->inhOpt == INH_YES), true); + rte = addRangeTableEntry(pstate, r, r->alias, r->inh, true); return rte; } diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 7d15189ead..45596abe76 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201612202 +#define CATALOG_VERSION_NO 201612231 #endif diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index d11f1120b0..717d8220d2 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -42,12 +42,6 @@ typedef struct Alias List *colnames; /* optional list of column aliases */ } Alias; -typedef enum InhOption -{ - INH_NO, /* Do NOT scan child tables */ - INH_YES /* DO scan child tables */ -} InhOption; - /* What to do at commit time for temporary relations */ typedef enum OnCommitAction { @@ -61,7 +55,7 @@ typedef enum OnCommitAction * RangeVar - range variable, used in FROM clauses * * Also used to represent table names in utility statements; there, the alias - * field is not used, and inhOpt shows whether to apply the operation + * field is not used, and inh tells whether to apply the operation * recursively to child tables. In some contexts it is also useful to carry * a TEMP table indication here. */ @@ -71,7 +65,7 @@ typedef struct RangeVar char *catalogname; /* the catalog (database) name, or NULL */ char *schemaname; /* the schema name, or NULL */ char *relname; /* the relation/sequence name */ - InhOption inhOpt; /* expand rel by inheritance? recursively act + bool inh; /* expand rel by inheritance? recursively act * on children? */ char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */ Alias *alias; /* table alias & optional column aliases */