From 43caf2946fbb4fb5a5e934a7927798dc7bde137a Mon Sep 17 00:00:00 2001 From: Shlok Kyal Date: Sat, 11 Apr 2026 23:02:18 +0530 Subject: [PATCH v2 1/3] Rename identifiers to use generic relation-oriented names Some identifiers are named assuming table-specific usage, but they can also used for other relation types such as sequences. Rename them to use more generic names. --- src/backend/catalog/pg_publication.c | 8 +-- src/backend/commands/publicationcmds.c | 76 ++++++++++++------------ src/backend/parser/gram.y | 81 +++++++++++++------------- src/include/catalog/pg_publication.h | 4 +- src/include/nodes/parsenodes.h | 9 +-- src/tools/pgindent/typedefs.list | 2 +- 6 files changed, 91 insertions(+), 89 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index a43d385c605..13ae2439be9 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -978,7 +978,7 @@ GetIncludedPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt) * This should only be used FOR ALL TABLES publications. */ List * -GetExcludedPublicationTables(Oid pubid, PublicationPartOpt pub_partopt) +GetExcludedPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt) { Assert(GetPublication(pubid)->alltables); @@ -1048,9 +1048,9 @@ GetAllPublicationRelations(Oid pubid, char relkind, bool pubviaroot) /* EXCEPT filtering applies only to relations, not sequences */ if (relkind == RELKIND_RELATION) - exceptlist = GetExcludedPublicationTables(pubid, pubviaroot ? - PUBLICATION_PART_ROOT : - PUBLICATION_PART_LEAF); + exceptlist = GetExcludedPublicationRelations(pubid, pubviaroot ? + PUBLICATION_PART_ROOT : + PUBLICATION_PART_LEAF); classRel = table_open(RelationRelationId, AccessShareLock); diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 440adb356ad..1cae5f10331 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -61,11 +61,11 @@ typedef struct rf_context Oid parentid; /* relid of the parent relation */ } rf_context; -static List *OpenTableList(List *tables); -static void CloseTableList(List *rels); +static List *OpenRelationList(List *tables); +static void CloseRelationList(List *rels); static void LockSchemaList(List *schemalist); -static void PublicationAddTables(Oid pubid, List *rels, bool if_not_exists, - AlterPublicationStmt *stmt); +static void PublicationAddRelations(Oid pubid, List *rels, bool if_not_exists, + AlterPublicationStmt *stmt); static void PublicationDropTables(Oid pubid, List *rels, bool missing_ok); static void PublicationAddSchemas(Oid pubid, List *schemas, bool if_not_exists, AlterPublicationStmt *stmt); @@ -177,11 +177,11 @@ parse_publication_options(ParseState *pstate, /* * Convert the PublicationObjSpecType list into schema oid list and - * PublicationTable list. + * PublicationRelation list. */ static void ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate, - List **rels, List **exceptrels, List **schemas) + List **rels, List **excepttbls, List **schemas) { ListCell *cell; PublicationObjSpec *pubobj; @@ -199,12 +199,12 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate, switch (pubobj->pubobjtype) { case PUBLICATIONOBJ_EXCEPT_TABLE: - pubobj->pubtable->except = true; - *exceptrels = lappend(*exceptrels, pubobj->pubtable); + pubobj->pubrelation->except = true; + *excepttbls = lappend(*excepttbls, pubobj->pubrelation); break; case PUBLICATIONOBJ_TABLE: - pubobj->pubtable->except = false; - *rels = lappend(*rels, pubobj->pubtable); + pubobj->pubrelation->except = false; + *rels = lappend(*rels, pubobj->pubrelation); break; case PUBLICATIONOBJ_TABLES_IN_SCHEMA: schemaid = get_namespace_oid(pubobj->name, false); @@ -849,7 +849,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) char publish_generated_columns; AclResult aclresult; List *relations = NIL; - List *exceptrelations = NIL; + List *excepttbls = NIL; List *schemaidlist = NIL; /* must have CREATE privilege on database */ @@ -936,18 +936,18 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) /* Associate objects with the publication. */ ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations, - &exceptrelations, &schemaidlist); + &excepttbls, &schemaidlist); if (stmt->for_all_tables) { /* Process EXCEPT table list */ - if (exceptrelations != NIL) + if (excepttbls != NIL) { List *rels; - rels = OpenTableList(exceptrelations); - PublicationAddTables(puboid, rels, true, NULL); - CloseTableList(rels); + rels = OpenRelationList(excepttbls); + PublicationAddRelations(puboid, rels, true, NULL); + CloseRelationList(rels); } /* @@ -969,7 +969,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) { List *rels; - rels = OpenTableList(relations); + rels = OpenRelationList(relations); TransformPubWhereClauses(rels, pstate->p_sourcetext, publish_via_partition_root); @@ -977,8 +977,8 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) schemaidlist != NIL, publish_via_partition_root); - PublicationAddTables(puboid, rels, true, NULL); - CloseTableList(rels); + PublicationAddRelations(puboid, rels, true, NULL); + CloseRelationList(rels); } if (schemaidlist != NIL) @@ -1255,7 +1255,7 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, if (!tables && stmt->action != AP_SetObjects) return; - rels = OpenTableList(tables); + rels = OpenRelationList(tables); if (stmt->action == AP_AddObjects) { @@ -1266,7 +1266,7 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, CheckPubRelationColumnList(stmt->pubname, rels, publish_schema, pubform->pubviaroot); - PublicationAddTables(pubid, rels, false, stmt); + PublicationAddRelations(pubid, rels, false, stmt); } else if (stmt->action == AP_DropObjects) PublicationDropTables(pubid, rels, false); @@ -1289,8 +1289,8 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, */ if (pubform->puballtables) { - oldrelids = GetExcludedPublicationTables(pubid, - PUBLICATION_PART_ROOT); + oldrelids = GetExcludedPublicationRelations(pubid, + PUBLICATION_PART_ROOT); } } else @@ -1363,8 +1363,8 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, /* * Validate the column list. If the column list or WHERE * clause changes, then the validation done here will be - * duplicated inside PublicationAddTables(). The validation - * is cheap enough that that seems harmless. + * duplicated inside PublicationAddRelations(). The + * validation is cheap enough that that seems harmless. */ newcolumns = pub_collist_validate(newpubrel->relation, newpubrel->columns); @@ -1410,12 +1410,12 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, * Don't bother calculating the difference for adding, we'll catch and * skip existing ones when doing catalog update. */ - PublicationAddTables(pubid, rels, true, stmt); + PublicationAddRelations(pubid, rels, true, stmt); - CloseTableList(delrels); + CloseRelationList(delrels); } - CloseTableList(rels); + CloseRelationList(rels); } /* @@ -1651,7 +1651,7 @@ AlterPublicationAllFlags(AlterPublicationStmt *stmt, Relation rel, * Alter the existing publication. * * This is dispatcher function for AlterPublicationOptions, - * AlterPublicationSchemas and AlterPublicationTables. + * AlterPublicationSchemas and AlterPublicationRelations. */ void AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt) @@ -1683,12 +1683,12 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt) else { List *relations = NIL; - List *exceptrelations = NIL; + List *excepttbls = NIL; List *schemaidlist = NIL; Oid pubid = pubform->oid; ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations, - &exceptrelations, &schemaidlist); + &excepttbls, &schemaidlist); CheckAlterPublication(stmt, tup, relations, schemaidlist); @@ -1711,7 +1711,7 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt) errmsg("publication \"%s\" does not exist", stmt->pubname)); - relations = list_concat(relations, exceptrelations); + relations = list_concat(relations, excepttbls); AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext, schemaidlist != NIL); AlterPublicationSchemas(stmt, tup, schemaidlist); @@ -1830,12 +1830,12 @@ RemovePublicationSchemaById(Oid psoid) } /* - * Open relations specified by a PublicationTable list. + * Open relations specified by a PublicationRelation list. * The returned tables are locked in ShareUpdateExclusiveLock mode in order to * add them to a publication. */ static List * -OpenTableList(List *tables) +OpenRelationList(List *tables) { List *relids = NIL; List *rels = NIL; @@ -1848,7 +1848,7 @@ OpenTableList(List *tables) */ foreach(lc, tables) { - PublicationTable *t = lfirst_node(PublicationTable, lc); + PublicationRelation *t = lfirst_node(PublicationRelation, lc); bool recurse = t->relation->inh; Relation rel; Oid myrelid; @@ -1987,7 +1987,7 @@ OpenTableList(List *tables) * Close all relations in the list. */ static void -CloseTableList(List *rels) +CloseRelationList(List *rels) { ListCell *lc; @@ -2035,8 +2035,8 @@ LockSchemaList(List *schemalist) * Add listed tables to the publication. */ static void -PublicationAddTables(Oid pubid, List *rels, bool if_not_exists, - AlterPublicationStmt *stmt) +PublicationAddRelations(Oid pubid, List *rels, bool if_not_exists, + AlterPublicationStmt *stmt) { ListCell *lc; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2d1b19d1f53..a6352186363 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -457,7 +457,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); TriggerTransitions TriggerReferencing vacuum_relation_list opt_vacuum_relation_list drop_option_list pub_obj_list pub_all_obj_type_list - pub_except_obj_list opt_pub_except_clause + pub_except_tbl_list opt_pub_except_tbl_clause %type returning_clause %type returning_option @@ -597,7 +597,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type var_value zone_value %type auth_ident RoleSpec opt_granted_by %type PublicationObjSpec -%type PublicationExceptObjSpec +%type PublicationExceptTblSpec %type PublicationAllObjSpec %type unreserved_keyword type_func_name_keyword @@ -11327,10 +11327,10 @@ PublicationObjSpec: { $$ = makeNode(PublicationObjSpec); $$->pubobjtype = PUBLICATIONOBJ_TABLE; - $$->pubtable = makeNode(PublicationTable); - $$->pubtable->relation = $2; - $$->pubtable->columns = $3; - $$->pubtable->whereClause = $4; + $$->pubrelation = makeNode(PublicationRelation); + $$->pubrelation->relation = $2; + $$->pubrelation->columns = $3; + $$->pubrelation->whereClause = $4; } | TABLES IN_P SCHEMA ColId { @@ -11351,7 +11351,7 @@ PublicationObjSpec: $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION; /* * If either a row filter or column list is specified, create - * a PublicationTable object. + * a PublicationRelation object. */ if ($2 || $3) { @@ -11361,10 +11361,10 @@ PublicationObjSpec: * error will be thrown later via * preprocess_pubobj_list(). */ - $$->pubtable = makeNode(PublicationTable); - $$->pubtable->relation = makeRangeVar(NULL, $1, @1); - $$->pubtable->columns = $2; - $$->pubtable->whereClause = $3; + $$->pubrelation = makeNode(PublicationRelation); + $$->pubrelation->relation = makeRangeVar(NULL, $1, @1); + $$->pubrelation->columns = $2; + $$->pubrelation->whereClause = $3; } else { @@ -11376,10 +11376,10 @@ PublicationObjSpec: { $$ = makeNode(PublicationObjSpec); $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION; - $$->pubtable = makeNode(PublicationTable); - $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner); - $$->pubtable->columns = $3; - $$->pubtable->whereClause = $4; + $$->pubrelation = makeNode(PublicationRelation); + $$->pubrelation->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner); + $$->pubrelation->columns = $3; + $$->pubrelation->whereClause = $4; $$->location = @1; } /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */ @@ -11387,10 +11387,10 @@ PublicationObjSpec: { $$ = makeNode(PublicationObjSpec); $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION; - $$->pubtable = makeNode(PublicationTable); - $$->pubtable->relation = $1; - $$->pubtable->columns = $2; - $$->pubtable->whereClause = $3; + $$->pubrelation = makeNode(PublicationRelation); + $$->pubrelation->relation = $1; + $$->pubrelation->columns = $2; + $$->pubrelation->whereClause = $3; } | CURRENT_SCHEMA { @@ -11406,17 +11406,17 @@ pub_obj_list: PublicationObjSpec { $$ = lappend($1, $3); } ; -opt_pub_except_clause: - EXCEPT '(' TABLE pub_except_obj_list ')' { $$ = $4; } +opt_pub_except_tbl_clause: + EXCEPT '(' TABLE pub_except_tbl_list ')' { $$ = $4; } | /*EMPTY*/ { $$ = NIL; } ; PublicationAllObjSpec: - ALL TABLES opt_pub_except_clause + ALL TABLES opt_pub_except_tbl_clause { $$ = makeNode(PublicationAllObjSpec); $$->pubobjtype = PUBLICATION_ALL_TABLES; - $$->except_tables = $3; + $$->except_relations = $3; $$->location = @1; } | ALL SEQUENCES @@ -11433,21 +11433,21 @@ pub_all_obj_type_list: PublicationAllObjSpec { $$ = lappend($1, $3); } ; -PublicationExceptObjSpec: +PublicationExceptTblSpec: relation_expr { $$ = makeNode(PublicationObjSpec); $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_TABLE; - $$->pubtable = makeNode(PublicationTable); - $$->pubtable->except = true; - $$->pubtable->relation = $1; + $$->pubrelation = makeNode(PublicationRelation); + $$->pubrelation->except = true; + $$->pubrelation->relation = $1; $$->location = @1; } ; -pub_except_obj_list: PublicationExceptObjSpec +pub_except_tbl_list: PublicationExceptTblSpec { $$ = list_make1($1); } - | pub_except_obj_list ',' opt_table PublicationExceptObjSpec + | pub_except_tbl_list ',' opt_table PublicationExceptTblSpec { $$ = lappend($1, $4); } ; @@ -20765,7 +20765,7 @@ preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects, parser_errposition(obj->location)); *all_tables = true; - *pubobjects = list_concat(*pubobjects, obj->except_tables); + *pubobjects = list_concat(*pubobjects, obj->except_relations); } else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES) { @@ -20777,6 +20777,7 @@ preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects, parser_errposition(obj->location)); *all_sequences = true; + *pubobjects = list_concat(*pubobjects, obj->except_relations); } } } @@ -20812,8 +20813,8 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE) { - /* relation name or pubtable must be set for this type of object */ - if (!pubobj->name && !pubobj->pubtable) + /* relation name or pubrelation must be set for this type of object */ + if (!pubobj->name && !pubobj->pubrelation) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("invalid table name"), @@ -20821,12 +20822,12 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) if (pubobj->name) { - /* convert it to PublicationTable */ - PublicationTable *pubtable = makeNode(PublicationTable); + /* convert it to PublicationRelation */ + PublicationRelation *pubrelation = makeNode(PublicationRelation); - pubtable->relation = + pubrelation->relation = makeRangeVar(NULL, pubobj->name, pubobj->location); - pubobj->pubtable = pubtable; + pubobj->pubrelation = pubrelation; pubobj->name = NULL; } } @@ -20834,14 +20835,14 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA) { /* WHERE clause is not allowed on a schema object */ - if (pubobj->pubtable && pubobj->pubtable->whereClause) + if (pubobj->pubrelation && pubobj->pubrelation->whereClause) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("WHERE clause not allowed for schema"), parser_errposition(pubobj->location)); /* Column list is not allowed on a schema object */ - if (pubobj->pubtable && pubobj->pubtable->columns) + if (pubobj->pubrelation && pubobj->pubrelation->columns) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("column specification not allowed for schema"), @@ -20849,11 +20850,11 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner) /* * We can distinguish between the different type of schema objects - * based on whether name and pubtable is set. + * based on whether name and pubrelation is set. */ if (pubobj->name) pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA; - else if (!pubobj->name && !pubobj->pubtable) + else if (!pubobj->name && !pubobj->pubrelation) pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA; else ereport(ERROR, diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h index 89b4bb14f62..e4da55d8b71 100644 --- a/src/include/catalog/pg_publication.h +++ b/src/include/catalog/pg_publication.h @@ -177,8 +177,8 @@ typedef enum PublicationPartOpt extern List *GetIncludedPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt); -extern List *GetExcludedPublicationTables(Oid pubid, - PublicationPartOpt pub_partopt); +extern List *GetExcludedPublicationRelations(Oid pubid, + PublicationPartOpt pub_partopt); extern List *GetAllTablesPublications(void); extern List *GetAllPublicationRelations(Oid pubid, char relkind, bool pubviaroot); extern List *GetPublicationSchemas(Oid pubid); diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 91377a6cde3..60a7e84d2c0 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -4465,14 +4465,14 @@ typedef struct AlterTSConfigurationStmt bool missing_ok; /* for DROP - skip error if missing? */ } AlterTSConfigurationStmt; -typedef struct PublicationTable +typedef struct PublicationRelation { NodeTag type; RangeVar *relation; /* publication relation */ Node *whereClause; /* qualifications */ List *columns; /* List of columns in a publication table */ bool except; /* True if listed in the EXCEPT clause */ -} PublicationTable; +} PublicationRelation; /* * Publication object type @@ -4492,7 +4492,7 @@ typedef struct PublicationObjSpec NodeTag type; PublicationObjSpecType pubobjtype; /* type of this publication object */ char *name; - PublicationTable *pubtable; + PublicationRelation *pubrelation; ParseLoc location; /* token location, or -1 if unknown */ } PublicationObjSpec; @@ -4509,7 +4509,8 @@ typedef struct PublicationAllObjSpec { NodeTag type; PublicationAllObjType pubobjtype; /* type of this publication object */ - List *except_tables; /* tables specified in the EXCEPT clause */ + List *except_relations; /* relations specified in the EXCEPT + * clause */ ParseLoc location; /* token location, or -1 if unknown */ } PublicationAllObjSpec; diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index ea95e7984bc..ff20501223c 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -2461,7 +2461,7 @@ PublicationPartOpt PublicationRelInfo PublicationRelKind PublicationSchemaInfo -PublicationTable +PublicationRelation PublishGencolsType PullFilter PullFilterOps -- 2.34.1