Small cleanups related to PUBLICATION framework code
Discussion: https://postgr.es/m/202112302021.ca7ihogysgh3@alvherre.pgsql
This commit is contained in:
parent
c7cf73eb7b
commit
c9105dd366
@ -287,7 +287,7 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
|
|||||||
Datum values[Natts_pg_publication_rel];
|
Datum values[Natts_pg_publication_rel];
|
||||||
bool nulls[Natts_pg_publication_rel];
|
bool nulls[Natts_pg_publication_rel];
|
||||||
Oid relid = RelationGetRelid(targetrel->relation);
|
Oid relid = RelationGetRelid(targetrel->relation);
|
||||||
Oid prrelid;
|
Oid pubreloid;
|
||||||
Publication *pub = GetPublication(pubid);
|
Publication *pub = GetPublication(pubid);
|
||||||
ObjectAddress myself,
|
ObjectAddress myself,
|
||||||
referenced;
|
referenced;
|
||||||
@ -320,9 +320,9 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
|
|||||||
memset(values, 0, sizeof(values));
|
memset(values, 0, sizeof(values));
|
||||||
memset(nulls, false, sizeof(nulls));
|
memset(nulls, false, sizeof(nulls));
|
||||||
|
|
||||||
prrelid = GetNewOidWithIndex(rel, PublicationRelObjectIndexId,
|
pubreloid = GetNewOidWithIndex(rel, PublicationRelObjectIndexId,
|
||||||
Anum_pg_publication_rel_oid);
|
Anum_pg_publication_rel_oid);
|
||||||
values[Anum_pg_publication_rel_oid - 1] = ObjectIdGetDatum(prrelid);
|
values[Anum_pg_publication_rel_oid - 1] = ObjectIdGetDatum(pubreloid);
|
||||||
values[Anum_pg_publication_rel_prpubid - 1] =
|
values[Anum_pg_publication_rel_prpubid - 1] =
|
||||||
ObjectIdGetDatum(pubid);
|
ObjectIdGetDatum(pubid);
|
||||||
values[Anum_pg_publication_rel_prrelid - 1] =
|
values[Anum_pg_publication_rel_prrelid - 1] =
|
||||||
@ -334,7 +334,8 @@ publication_add_relation(Oid pubid, PublicationRelInfo *targetrel,
|
|||||||
CatalogTupleInsert(rel, tup);
|
CatalogTupleInsert(rel, tup);
|
||||||
heap_freetuple(tup);
|
heap_freetuple(tup);
|
||||||
|
|
||||||
ObjectAddressSet(myself, PublicationRelRelationId, prrelid);
|
/* Register dependencies as needed */
|
||||||
|
ObjectAddressSet(myself, PublicationRelRelationId, pubreloid);
|
||||||
|
|
||||||
/* Add dependency on the publication */
|
/* Add dependency on the publication */
|
||||||
ObjectAddressSet(referenced, PublicationRelationId, pubid);
|
ObjectAddressSet(referenced, PublicationRelationId, pubid);
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/varlena.h"
|
#include "utils/varlena.h"
|
||||||
|
|
||||||
static List *OpenReliIdList(List *relids);
|
static List *OpenRelIdList(List *relids);
|
||||||
static List *OpenTableList(List *tables);
|
static List *OpenTableList(List *tables);
|
||||||
static void CloseTableList(List *rels);
|
static void CloseTableList(List *rels);
|
||||||
static void LockSchemaList(List *schemalist);
|
static void LockSchemaList(List *schemalist);
|
||||||
@ -169,13 +169,13 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
|
|||||||
case PUBLICATIONOBJ_TABLE:
|
case PUBLICATIONOBJ_TABLE:
|
||||||
*rels = lappend(*rels, pubobj->pubtable);
|
*rels = lappend(*rels, pubobj->pubtable);
|
||||||
break;
|
break;
|
||||||
case PUBLICATIONOBJ_TABLE_IN_SCHEMA:
|
case PUBLICATIONOBJ_TABLES_IN_SCHEMA:
|
||||||
schemaid = get_namespace_oid(pubobj->name, false);
|
schemaid = get_namespace_oid(pubobj->name, false);
|
||||||
|
|
||||||
/* Filter out duplicates if user specifies "sch1, sch1" */
|
/* Filter out duplicates if user specifies "sch1, sch1" */
|
||||||
*schemas = list_append_unique_oid(*schemas, schemaid);
|
*schemas = list_append_unique_oid(*schemas, schemaid);
|
||||||
break;
|
break;
|
||||||
case PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA:
|
case PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA:
|
||||||
search_path = fetch_search_path(false);
|
search_path = fetch_search_path(false);
|
||||||
if (search_path == NIL) /* nothing valid in search_path? */
|
if (search_path == NIL) /* nothing valid in search_path? */
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -214,7 +214,7 @@ CheckObjSchemaNotAlreadyInPublication(List *rels, List *schemaidlist,
|
|||||||
|
|
||||||
if (list_member_oid(schemaidlist, relSchemaId))
|
if (list_member_oid(schemaidlist, relSchemaId))
|
||||||
{
|
{
|
||||||
if (checkobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA)
|
if (checkobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("cannot add schema \"%s\" to publication",
|
errmsg("cannot add schema \"%s\" to publication",
|
||||||
@ -499,8 +499,9 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
|
|||||||
Oid pubid = pubform->oid;
|
Oid pubid = pubform->oid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It is quite possible that for the SET case user has not specified any
|
* Nothing to do if no objects, except in SET: for that it is quite
|
||||||
* tables in which case we need to remove all the existing tables.
|
* possible that user has not specified any tables in which case we need
|
||||||
|
* to remove all the existing tables.
|
||||||
*/
|
*/
|
||||||
if (!tables && stmt->action != DEFELEM_SET)
|
if (!tables && stmt->action != DEFELEM_SET)
|
||||||
return;
|
return;
|
||||||
@ -593,8 +594,9 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
|
|||||||
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
|
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It is quite possible that for the SET case user has not specified any
|
* Nothing to do if no objects, except in SET: for that it is quite
|
||||||
* schemas in which case we need to remove all the existing schemas.
|
* possible that user has not specified any schemas in which case we need
|
||||||
|
* to remove all the existing schemas.
|
||||||
*/
|
*/
|
||||||
if (!schemaidlist && stmt->action != DEFELEM_SET)
|
if (!schemaidlist && stmt->action != DEFELEM_SET)
|
||||||
return;
|
return;
|
||||||
@ -610,10 +612,10 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
|
|||||||
List *reloids;
|
List *reloids;
|
||||||
|
|
||||||
reloids = GetPublicationRelations(pubform->oid, PUBLICATION_PART_ROOT);
|
reloids = GetPublicationRelations(pubform->oid, PUBLICATION_PART_ROOT);
|
||||||
rels = OpenReliIdList(reloids);
|
rels = OpenRelIdList(reloids);
|
||||||
|
|
||||||
CheckObjSchemaNotAlreadyInPublication(rels, schemaidlist,
|
CheckObjSchemaNotAlreadyInPublication(rels, schemaidlist,
|
||||||
PUBLICATIONOBJ_TABLE_IN_SCHEMA);
|
PUBLICATIONOBJ_TABLES_IN_SCHEMA);
|
||||||
|
|
||||||
CloseTableList(rels);
|
CloseTableList(rels);
|
||||||
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
|
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
|
||||||
@ -868,7 +870,7 @@ RemovePublicationSchemaById(Oid psoid)
|
|||||||
* add them to a publication.
|
* add them to a publication.
|
||||||
*/
|
*/
|
||||||
static List *
|
static List *
|
||||||
OpenReliIdList(List *relids)
|
OpenRelIdList(List *relids)
|
||||||
{
|
{
|
||||||
ListCell *lc;
|
ListCell *lc;
|
||||||
List *rels = NIL;
|
List *rels = NIL;
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
#include "catalog/pg_inherits.h"
|
#include "catalog/pg_inherits.h"
|
||||||
#include "catalog/pg_namespace.h"
|
#include "catalog/pg_namespace.h"
|
||||||
#include "catalog/pg_opclass.h"
|
#include "catalog/pg_opclass.h"
|
||||||
#include "catalog/pg_tablespace.h"
|
|
||||||
#include "catalog/pg_statistic_ext.h"
|
#include "catalog/pg_statistic_ext.h"
|
||||||
|
#include "catalog/pg_tablespace.h"
|
||||||
#include "catalog/pg_trigger.h"
|
#include "catalog/pg_trigger.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "catalog/storage.h"
|
#include "catalog/storage.h"
|
||||||
@ -15626,7 +15626,6 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
|
|||||||
else
|
else
|
||||||
elog(ERROR, "unexpected identity type %u", stmt->identity_type);
|
elog(ERROR, "unexpected identity type %u", stmt->identity_type);
|
||||||
|
|
||||||
|
|
||||||
/* Check that the index exists */
|
/* Check that the index exists */
|
||||||
indexOid = get_relname_relid(stmt->name, rel->rd_rel->relnamespace);
|
indexOid = get_relname_relid(stmt->name, rel->rd_rel->relnamespace);
|
||||||
if (!OidIsValid(indexOid))
|
if (!OidIsValid(indexOid))
|
||||||
|
@ -9750,14 +9750,14 @@ PublicationObjSpec:
|
|||||||
| ALL TABLES IN_P SCHEMA ColId
|
| ALL TABLES IN_P SCHEMA ColId
|
||||||
{
|
{
|
||||||
$$ = makeNode(PublicationObjSpec);
|
$$ = makeNode(PublicationObjSpec);
|
||||||
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
|
$$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
|
||||||
$$->name = $5;
|
$$->name = $5;
|
||||||
$$->location = @5;
|
$$->location = @5;
|
||||||
}
|
}
|
||||||
| ALL TABLES IN_P SCHEMA CURRENT_SCHEMA
|
| ALL TABLES IN_P SCHEMA CURRENT_SCHEMA
|
||||||
{
|
{
|
||||||
$$ = makeNode(PublicationObjSpec);
|
$$ = makeNode(PublicationObjSpec);
|
||||||
$$->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
|
$$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
|
||||||
$$->location = @5;
|
$$->location = @5;
|
||||||
}
|
}
|
||||||
| ColId
|
| ColId
|
||||||
@ -17411,7 +17411,8 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
|
|||||||
if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
|
if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
errcode(ERRCODE_SYNTAX_ERROR),
|
errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
errmsg("TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)"),
|
errmsg("invalid publication object list"),
|
||||||
|
errdetail("One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name."),
|
||||||
parser_errposition(pubobj->location));
|
parser_errposition(pubobj->location));
|
||||||
|
|
||||||
foreach(cell, pubobjspec_list)
|
foreach(cell, pubobjspec_list)
|
||||||
@ -17433,23 +17434,24 @@ preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
|
|||||||
{
|
{
|
||||||
/* convert it to PublicationTable */
|
/* convert it to PublicationTable */
|
||||||
PublicationTable *pubtable = makeNode(PublicationTable);
|
PublicationTable *pubtable = makeNode(PublicationTable);
|
||||||
pubtable->relation = makeRangeVar(NULL, pubobj->name,
|
|
||||||
pubobj->location);
|
pubtable->relation =
|
||||||
|
makeRangeVar(NULL, pubobj->name, pubobj->location);
|
||||||
pubobj->pubtable = pubtable;
|
pubobj->pubtable = pubtable;
|
||||||
pubobj->name = NULL;
|
pubobj->name = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_SCHEMA ||
|
else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
|
||||||
pubobj->pubobjtype == PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA)
|
pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We can distinguish between the different type of schema
|
* We can distinguish between the different type of schema
|
||||||
* objects based on whether name and pubtable is set.
|
* objects based on whether name and pubtable is set.
|
||||||
*/
|
*/
|
||||||
if (pubobj->name)
|
if (pubobj->name)
|
||||||
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_SCHEMA;
|
pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
|
||||||
else if (!pubobj->name && !pubobj->pubtable)
|
else if (!pubobj->name && !pubobj->pubtable)
|
||||||
pubobj->pubobjtype = PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA;
|
pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
|
||||||
else
|
else
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
errcode(ERRCODE_SYNTAX_ERROR),
|
errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
|
@ -3649,9 +3649,9 @@ typedef struct PublicationTable
|
|||||||
*/
|
*/
|
||||||
typedef enum PublicationObjSpecType
|
typedef enum PublicationObjSpecType
|
||||||
{
|
{
|
||||||
PUBLICATIONOBJ_TABLE, /* Table type */
|
PUBLICATIONOBJ_TABLE, /* A table */
|
||||||
PUBLICATIONOBJ_TABLE_IN_SCHEMA, /* Tables in schema type */
|
PUBLICATIONOBJ_TABLES_IN_SCHEMA, /* All tables in schema */
|
||||||
PUBLICATIONOBJ_TABLE_IN_CUR_SCHEMA, /* Get the first element from
|
PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA, /* All tables in first element of
|
||||||
* search_path */
|
* search_path */
|
||||||
PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
|
PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
|
||||||
} PublicationObjSpecType;
|
} PublicationObjSpecType;
|
||||||
|
@ -509,9 +509,10 @@ RESET SEARCH_PATH;
|
|||||||
-- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
|
-- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
|
||||||
-- is not specified
|
-- is not specified
|
||||||
CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
||||||
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
|
ERROR: invalid publication object list
|
||||||
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
||||||
^
|
^
|
||||||
|
DETAIL: One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name.
|
||||||
-- check create publication on CURRENT_SCHEMA along with FOR TABLE
|
-- check create publication on CURRENT_SCHEMA along with FOR TABLE
|
||||||
CREATE PUBLICATION testpub_forschema1 FOR TABLE CURRENT_SCHEMA;
|
CREATE PUBLICATION testpub_forschema1 FOR TABLE CURRENT_SCHEMA;
|
||||||
ERROR: syntax error at or near "CURRENT_SCHEMA"
|
ERROR: syntax error at or near "CURRENT_SCHEMA"
|
||||||
@ -778,9 +779,10 @@ Tables from schemas:
|
|||||||
-- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
|
-- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
|
||||||
--'FOR TABLE' or 'FOR ALL TABLES'
|
--'FOR TABLE' or 'FOR ALL TABLES'
|
||||||
CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
||||||
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
|
ERROR: invalid publication object list
|
||||||
LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
||||||
^
|
^
|
||||||
|
DETAIL: One of TABLE or ALL TABLES IN SCHEMA must be specified before a standalone table or schema name.
|
||||||
DROP VIEW testpub_view;
|
DROP VIEW testpub_view;
|
||||||
DROP PUBLICATION testpub_default;
|
DROP PUBLICATION testpub_default;
|
||||||
DROP PUBLICATION testpib_ins_trunct;
|
DROP PUBLICATION testpib_ins_trunct;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user