Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d6fbc3

Browse files
committed
Refactor routines for subscription and publication lookups
Those routines gain a missing_ok argument, allowing a caller to get aNULL result instead of an error if set to true. This is part of alarger refactoring effort for objectaddress.c where trying to check fornon-existing objects does not result in cache lookup failures.Author: Michael PaquierReviewed-by: Aleksander Alekseev, Álvaro HerreraDiscussion:https://postgr.es/m/CAB7nPqSZxrSmdHK-rny7z8mi=EAFXJ5J-0RbzDw6aus=wB5azQ@mail.gmail.com
1 parent07a3af0 commit1d6fbc3

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,8 @@ getObjectDescription(const ObjectAddress *object)
35083508
caseOCLASS_PUBLICATION:
35093509
{
35103510
appendStringInfo(&buffer,_("publication %s"),
3511-
get_publication_name(object->objectId));
3511+
get_publication_name(object->objectId,
3512+
false));
35123513
break;
35133514
}
35143515

@@ -3526,7 +3527,7 @@ getObjectDescription(const ObjectAddress *object)
35263527
object->objectId);
35273528

35283529
prform= (Form_pg_publication_rel)GETSTRUCT(tup);
3529-
pubname=get_publication_name(prform->prpubid);
3530+
pubname=get_publication_name(prform->prpubid, false);
35303531

35313532
initStringInfo(&rel);
35323533
getRelationDescription(&rel,prform->prrelid);
@@ -3542,7 +3543,8 @@ getObjectDescription(const ObjectAddress *object)
35423543
caseOCLASS_SUBSCRIPTION:
35433544
{
35443545
appendStringInfo(&buffer,_("subscription %s"),
3545-
get_subscription_name(object->objectId));
3546+
get_subscription_name(object->objectId,
3547+
false));
35463548
break;
35473549
}
35483550

@@ -5042,7 +5044,7 @@ getObjectIdentityParts(const ObjectAddress *object,
50425044
{
50435045
char*pubname;
50445046

5045-
pubname=get_publication_name(object->objectId);
5047+
pubname=get_publication_name(object->objectId, false);
50465048
appendStringInfoString(&buffer,
50475049
quote_identifier(pubname));
50485050
if (objname)
@@ -5063,7 +5065,7 @@ getObjectIdentityParts(const ObjectAddress *object,
50635065
object->objectId);
50645066

50655067
prform= (Form_pg_publication_rel)GETSTRUCT(tup);
5066-
pubname=get_publication_name(prform->prpubid);
5068+
pubname=get_publication_name(prform->prpubid, false);
50675069

50685070
getRelationIdentity(&buffer,prform->prrelid,objname);
50695071
appendStringInfo(&buffer," in publication %s",pubname);
@@ -5079,7 +5081,7 @@ getObjectIdentityParts(const ObjectAddress *object,
50795081
{
50805082
char*subname;
50815083

5082-
subname=get_subscription_name(object->objectId);
5084+
subname=get_subscription_name(object->objectId, false);
50835085
appendStringInfoString(&buffer,
50845086
quote_identifier(subname));
50855087
if (objname)

‎src/backend/catalog/pg_publication.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,12 @@ get_publication_oid(const char *pubname, bool missing_ok)
427427

428428
/*
429429
* get_publication_name - given a publication Oid, look up the name
430+
*
431+
* If missing_ok is false, throw an error if name not found. If true, just
432+
* return NULL.
430433
*/
431434
char*
432-
get_publication_name(Oidpubid)
435+
get_publication_name(Oidpubid,boolmissing_ok)
433436
{
434437
HeapTupletup;
435438
char*pubname;
@@ -438,7 +441,11 @@ get_publication_name(Oid pubid)
438441
tup=SearchSysCache1(PUBLICATIONOID,ObjectIdGetDatum(pubid));
439442

440443
if (!HeapTupleIsValid(tup))
441-
elog(ERROR,"cache lookup failed for publication %u",pubid);
444+
{
445+
if (!missing_ok)
446+
elog(ERROR,"cache lookup failed for publication %u",pubid);
447+
returnNULL;
448+
}
442449

443450
pubform= (Form_pg_publication)GETSTRUCT(tup);
444451
pubname=pstrdup(NameStr(pubform->pubname));

‎src/backend/catalog/pg_subscription.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,12 @@ get_subscription_oid(const char *subname, bool missing_ok)
179179

180180
/*
181181
* get_subscription_name - given a subscription OID, look up the name
182+
*
183+
* If missing_ok is false, throw an error if name not found. If true, just
184+
* return NULL.
182185
*/
183186
char*
184-
get_subscription_name(Oidsubid)
187+
get_subscription_name(Oidsubid,boolmissing_ok)
185188
{
186189
HeapTupletup;
187190
char*subname;
@@ -190,7 +193,11 @@ get_subscription_name(Oid subid)
190193
tup=SearchSysCache1(SUBSCRIPTIONOID,ObjectIdGetDatum(subid));
191194

192195
if (!HeapTupleIsValid(tup))
193-
elog(ERROR,"cache lookup failed for subscription %u",subid);
196+
{
197+
if (!missing_ok)
198+
elog(ERROR,"cache lookup failed for subscription %u",subid);
199+
returnNULL;
200+
}
194201

195202
subform= (Form_pg_subscription)GETSTRUCT(tup);
196203
subname=pstrdup(NameStr(subform->subname));

‎src/include/catalog/pg_publication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extern ObjectAddress publication_add_relation(Oid pubid, Relation targetrel,
8888
boolif_not_exists);
8989

9090
externOidget_publication_oid(constchar*pubname,boolmissing_ok);
91-
externchar*get_publication_name(Oidpubid);
91+
externchar*get_publication_name(Oidpubid,boolmissing_ok);
9292

9393
externDatumpg_get_publication_tables(PG_FUNCTION_ARGS);
9494

‎src/include/catalog/pg_subscription.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct Subscription
8080
externSubscription*GetSubscription(Oidsubid,boolmissing_ok);
8181
externvoidFreeSubscription(Subscription*sub);
8282
externOidget_subscription_oid(constchar*subname,boolmissing_ok);
83-
externchar*get_subscription_name(Oidsubid);
83+
externchar*get_subscription_name(Oidsubid,boolmissing_ok);
8484

8585
externintCountDBSubscriptions(Oiddbid);
8686

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp