Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c9105dd

Browse files
committed
Small cleanups related to PUBLICATION framework code
Discussion: https://postgr.es/m/202112302021.ca7ihogysgh3@alvherre.pgsql
1 parent c7cf73e commit c9105dd

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

src/backend/catalog/pg_publication.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
287287
Datum values[Natts_pg_publication_rel];
288288
bool nulls[Natts_pg_publication_rel];
289289
Oid relid = RelationGetRelid(targetrel->relation);
290-
Oid prrelid;
290+
Oid pubreloid;
291291
Publication *pub = GetPublication(pubid);
292292
ObjectAddress myself,
293293
referenced;
@@ -320,9 +320,9 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
320320
memset(values, 0, sizeof(values));
321321
memset(nulls, false, sizeof(nulls));
322322

323-
prrelid = GetNewOidWithIndex(rel, PublicationRelObjectIndexId,
324-
Anum_pg_publication_rel_oid);
325-
values[Anum_pg_publication_rel_oid - 1] = ObjectIdGetDatum(prrelid);
323+
pubreloid = GetNewOidWithIndex(rel, PublicationRelObjectIndexId,
324+
Anum_pg_publication_rel_oid);
325+
values[Anum_pg_publication_rel_oid - 1] = ObjectIdGetDatum(pubreloid);
326326
values[Anum_pg_publication_rel_prpubid - 1] =
327327
ObjectIdGetDatum(pubid);
328328
values[Anum_pg_publication_rel_prrelid - 1] =
@@ -334,7 +334,8 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
334334
CatalogTupleInsert(rel, tup);
335335
heap_freetuple(tup);
336336

337-
ObjectAddressSet(myself, PublicationRelRelationId, prrelid);
337+
/* Register dependencies as needed */
338+
ObjectAddressSet(myself, PublicationRelRelationId, pubreloid);
338339

339340
/* Add dependency on the publication */
340341
ObjectAddressSet(referenced, PublicationRelationId, pubid);

src/backend/commands/publicationcmds.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include "utils/syscache.h"
4949
#include "utils/varlena.h"
5050

51-
static List *OpenReliIdList(List *relids);
51+
static List *OpenRelIdList(List *relids);
5252
static List *OpenTableList(List *tables);
5353
static void CloseTableList(List *rels);
5454
static void LockSchemaList(List *schemalist);
@@ -169,13 +169,13 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
169169
case PUBLICATIONOBJ_TABLE:
170170
*rels = lappend(*rels, pubobj->pubtable);
171171
break;
172-
case PUBLICATIONOBJ_TABLE_IN_SCHEMA:
172+
case PUBLICATIONOBJ_TABLES_IN_SCHEMA:
173173
schemaid = get_namespace_oid(pubobj->name, false);
174174

175175
/* Filter out duplicates if user specifies "sch1, sch1" */
176176
*schemas = list_append_unique_oid(*schemas, schemaid);
177177
break;
178-
case PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA:
178+
case PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA:
179179
search_path = fetch_search_path(false);
180180
if (search_path == NIL) /* nothing valid in search_path? */
181181
ereport(ERROR,
@@ -214,7 +214,7 @@ CheckObjSchemaNotAlreadyInPublication(List *rels, List *schemaidlist,
214214

215215
if (list_member_oid(schemaidlist, relSchemaId))
216216
{
217-
if (checkobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA)
217+
if (checkobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA)
218218
ereport(ERROR,
219219
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
220220
errmsg("cannot add schema \"%s\" to publication",
@@ -499,8 +499,9 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
499499
Oid pubid = pubform->oid;
500500

501501
/*
502-
* It is quite possible that for the SET case user has not specified any
503-
* tables in which case we need to remove all the existing tables.
502+
* Nothing to do if no objects, except in SET: for that it is quite
503+
* possible that user has not specified any tables in which case we need
504+
* to remove all the existing tables.
504505
*/
505506
if (!tables && stmt->action != DEFELEM_SET)
506507
return;
@@ -593,8 +594,9 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
593594
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
594595

595596
/*
596-
* It is quite possible that for the SET case user has not specified any
597-
* schemas in which case we need to remove all the existing schemas.
597+
* Nothing to do if no objects, except in SET: for that it is quite
598+
* possible that user has not specified any schemas in which case we need
599+
* to remove all the existing schemas.
598600
*/
599601
if (!schemaidlist && stmt->action != DEFELEM_SET)
600602
return;
@@ -610,10 +612,10 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
610612
List *reloids;
611613

612614
reloids = GetPublicationRelations(pubform->oid, PUBLICATION_PART_ROOT);
613-
rels = OpenReliIdList(reloids);
615+
rels = OpenRelIdList(reloids);
614616

615617
CheckObjSchemaNotAlreadyInPublication(rels, schemaidlist,
616-
PUBLICATIONOBJ_TABLE_IN_SCHEMA);
618+
PUBLICATIONOBJ_TABLES_IN_SCHEMA);
617619

618620
CloseTableList(rels);
619621
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
@@ -813,7 +815,7 @@ RemovePublicationById(Oid pubid)
813815
if (!HeapTupleIsValid(tup))
814816
elog(ERROR, "cache lookup failed for publication %u", pubid);
815817

816-
pubform = (Form_pg_publication)GETSTRUCT(tup);
818+
pubform = (Form_pg_publication) GETSTRUCT(tup);
817819

818820
/* Invalidate relcache so that publication info is rebuilt. */
819821
if (pubform->puballtables)
@@ -868,7 +870,7 @@ RemovePublicationSchemaById(Oid psoid)
868870
* add them to a publication.
869871
*/
870872
static List *
871-
OpenReliIdList(List *relids)
873+
OpenRelIdList(List *relids)
872874
{
873875
ListCell *lc;
874876
List *rels = NIL;

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#include "catalog/pg_inherits.h"
4141
#include "catalog/pg_namespace.h"
4242
#include "catalog/pg_opclass.h"
43-
#include "catalog/pg_tablespace.h"
4443
#include "catalog/pg_statistic_ext.h"
44+
#include "catalog/pg_tablespace.h"
4545
#include "catalog/pg_trigger.h"
4646
#include "catalog/pg_type.h"
4747
#include "catalog/storage.h"
@@ -15626,7 +15626,6 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
1562615626
else
1562715627
elog(ERROR, "unexpected identity type %u", stmt->identity_type);
1562815628

15629-
1563015629
/* Check that the index exists */
1563115630
indexOid = get_relname_relid(stmt->name, rel->rd_rel->relnamespace);
1563215631
if (!OidIsValid(indexOid))

src/backend/parser/gram.y

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9750,14 +9750,14 @@ PublicationObjSpec:
97509750
| ALL TABLES IN_P SCHEMA ColId
97519751
{
97529752
$$ = makeNode(PublicationObjSpec);
9753-
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
9753+
$$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
97549754
$$->name = $5;
97559755
$$->location = @5;
97569756
}
97579757
| ALL TABLES IN_P SCHEMA CURRENT_SCHEMA
97589758
{
97599759
$$ = makeNode(PublicationObjSpec);
9760-
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
9760+
$$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
97619761
$$->location = @5;
97629762
}
97639763
| ColId
@@ -17411,7 +17411,8 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
1741117411
if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
1741217412
ereport(ERROR,
1741317413
errcode(ERRCODE_SYNTAX_ERROR),
17414-
errmsg("TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
17414+
errmsg("invalid publication object list"),
17415+
errdetail("One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name."),
1741517416
parser_errposition(pubobj->location));
1741617417

1741717418
foreach(cell, pubobjspec_list)
@@ -17433,23 +17434,24 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
1743317434
{
1743417435
/* convert it to PublicationTable */
1743517436
PublicationTable *pubtable = makeNode(PublicationTable);
17436-
pubtable->relation = makeRangeVar(NULL, pubobj->name,
17437-
pubobj->location);
17437+
17438+
pubtable->relation =
17439+
makeRangeVar(NULL, pubobj->name, pubobj->location);
1743817440
pubobj->pubtable = pubtable;
1743917441
pubobj->name = NULL;
1744017442
}
1744117443
}
17442-
else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA ||
17443-
pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA)
17444+
else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
17445+
pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
1744417446
{
1744517447
/*
1744617448
* We can distinguish between the different type of schema
1744717449
* objects based on whether name and pubtable is set.
1744817450
*/
1744917451
if (pubobj->name)
17450-
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
17452+
pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
1745117453
else if (!pubobj->name && !pubobj->pubtable)
17452-
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
17454+
pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
1745317455
else
1745417456
ereport(ERROR,
1745517457
errcode(ERRCODE_SYNTAX_ERROR),

src/include/nodes/parsenodes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,10 +3649,10 @@ typedef struct PublicationTable
36493649
*/
36503650
typedef enum PublicationObjSpecType
36513651
{
3652-
PUBLICATIONOBJ_TABLE, /* Table type */
3653-
PUBLICATIONOBJ_TABLE_IN_SCHEMA, /* Tables in schema type */
3654-
PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA, /* Get the first element from
3655-
* search_path */
3652+
PUBLICATIONOBJ_TABLE, /* A table */
3653+
PUBLICATIONOBJ_TABLES_IN_SCHEMA, /* All tables in schema */
3654+
PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA, /* All tables in first element of
3655+
* search_path */
36563656
PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
36573657
} PublicationObjSpecType;
36583658

src/test/regress/expected/publication.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,10 @@ RESET SEARCH_PATH;
509509
-- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
510510
-- is not specified
511511
CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
512-
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
512+
ERROR: invalid publication object list
513513
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
514514
^
515+
DETAIL: One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name.
515516
-- check create publication on CURRENT_SCHEMA along with FOR TABLE
516517
CREATE PUBLICATION testpub_forschema1 FOR TABLE CURRENT_SCHEMA;
517518
ERROR: syntax error at or near "CURRENT_SCHEMA"
@@ -778,9 +779,10 @@ Tables from schemas:
778779
-- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
779780
--'FOR TABLE' or 'FOR ALL TABLES'
780781
CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
781-
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
782+
ERROR: invalid publication object list
782783
LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
783784
^
785+
DETAIL: One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name.
784786
DROP VIEW testpub_view;
785787
DROP PUBLICATION testpub_default;
786788
DROP PUBLICATION testpib_ins_trunct;

0 commit comments

Comments
 (0)