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

Commit6b24d3f

Browse files
author
Amit Kapila
committed
Move common catalog cache access routines to lsyscache.c
In passing, move pg_relation_is_publishable next to similar functions.Suggested-by: Alvaro HerreraAuthor: Amit KapilaReviewed-by: Hou ZhijieDiscussion:https://postgr.es/m/CAHut+PupQ5UW9A9ut0Yjt21J9tHhx958z5L0k8-9hTYf_NYqxA@mail.gmail.com
1 parentc689baa commit6b24d3f

File tree

6 files changed

+127
-128
lines changed

6 files changed

+127
-128
lines changed

‎src/backend/catalog/pg_publication.c

Lines changed: 22 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ is_publishable_relation(Relation rel)
149149
returnis_publishable_class(RelationGetRelid(rel),rel->rd_rel);
150150
}
151151

152+
/*
153+
* SQL-callable variant of the above
154+
*
155+
* This returns null when the relation does not exist. This is intended to be
156+
* used for example in psql to avoid gratuitous errors when there are
157+
* concurrent catalog changes.
158+
*/
159+
Datum
160+
pg_relation_is_publishable(PG_FUNCTION_ARGS)
161+
{
162+
Oidrelid=PG_GETARG_OID(0);
163+
HeapTupletuple;
164+
boolresult;
165+
166+
tuple=SearchSysCache1(RELOID,ObjectIdGetDatum(relid));
167+
if (!HeapTupleIsValid(tuple))
168+
PG_RETURN_NULL();
169+
result=is_publishable_class(relid, (Form_pg_class)GETSTRUCT(tuple));
170+
ReleaseSysCache(tuple);
171+
PG_RETURN_BOOL(result);
172+
}
173+
152174
/*
153175
* Filter out the partitions whose parent tables were also specified in
154176
* the publication.
@@ -219,28 +241,6 @@ is_schema_publication(Oid pubid)
219241
returnresult;
220242
}
221243

222-
/*
223-
* SQL-callable variant of the above
224-
*
225-
* This returns null when the relation does not exist. This is intended to be
226-
* used for example in psql to avoid gratuitous errors when there are
227-
* concurrent catalog changes.
228-
*/
229-
Datum
230-
pg_relation_is_publishable(PG_FUNCTION_ARGS)
231-
{
232-
Oidrelid=PG_GETARG_OID(0);
233-
HeapTupletuple;
234-
boolresult;
235-
236-
tuple=SearchSysCache1(RELOID,ObjectIdGetDatum(relid));
237-
if (!HeapTupleIsValid(tuple))
238-
PG_RETURN_NULL();
239-
result=is_publishable_class(relid, (Form_pg_class)GETSTRUCT(tuple));
240-
ReleaseSysCache(tuple);
241-
PG_RETURN_BOOL(result);
242-
}
243-
244244
/*
245245
* Gets the relations based on the publication partition option for a specified
246246
* relation.
@@ -1012,7 +1012,6 @@ GetPublication(Oid pubid)
10121012
returnpub;
10131013
}
10141014

1015-
10161015
/*
10171016
* Get Publication using name.
10181017
*/
@@ -1026,56 +1025,6 @@ GetPublicationByName(const char *pubname, bool missing_ok)
10261025
returnOidIsValid(oid) ?GetPublication(oid) :NULL;
10271026
}
10281027

1029-
/*
1030-
* get_publication_oid - given a publication name, look up the OID
1031-
*
1032-
* If missing_ok is false, throw an error if name not found. If true, just
1033-
* return InvalidOid.
1034-
*/
1035-
Oid
1036-
get_publication_oid(constchar*pubname,boolmissing_ok)
1037-
{
1038-
Oidoid;
1039-
1040-
oid=GetSysCacheOid1(PUBLICATIONNAME,Anum_pg_publication_oid,
1041-
CStringGetDatum(pubname));
1042-
if (!OidIsValid(oid)&& !missing_ok)
1043-
ereport(ERROR,
1044-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1045-
errmsg("publication \"%s\" does not exist",pubname)));
1046-
returnoid;
1047-
}
1048-
1049-
/*
1050-
* get_publication_name - given a publication Oid, look up the name
1051-
*
1052-
* If missing_ok is false, throw an error if name not found. If true, just
1053-
* return NULL.
1054-
*/
1055-
char*
1056-
get_publication_name(Oidpubid,boolmissing_ok)
1057-
{
1058-
HeapTupletup;
1059-
char*pubname;
1060-
Form_pg_publicationpubform;
1061-
1062-
tup=SearchSysCache1(PUBLICATIONOID,ObjectIdGetDatum(pubid));
1063-
1064-
if (!HeapTupleIsValid(tup))
1065-
{
1066-
if (!missing_ok)
1067-
elog(ERROR,"cache lookup failed for publication %u",pubid);
1068-
returnNULL;
1069-
}
1070-
1071-
pubform= (Form_pg_publication)GETSTRUCT(tup);
1072-
pubname=pstrdup(NameStr(pubform->pubname));
1073-
1074-
ReleaseSysCache(tup);
1075-
1076-
returnpubname;
1077-
}
1078-
10791028
/*
10801029
* Returns information of tables in a publication.
10811030
*/

‎src/backend/catalog/pg_subscription.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -205,56 +205,6 @@ DisableSubscription(Oid subid)
205205
table_close(rel,NoLock);
206206
}
207207

208-
/*
209-
* get_subscription_oid - given a subscription name, look up the OID
210-
*
211-
* If missing_ok is false, throw an error if name not found. If true, just
212-
* return InvalidOid.
213-
*/
214-
Oid
215-
get_subscription_oid(constchar*subname,boolmissing_ok)
216-
{
217-
Oidoid;
218-
219-
oid=GetSysCacheOid2(SUBSCRIPTIONNAME,Anum_pg_subscription_oid,
220-
MyDatabaseId,CStringGetDatum(subname));
221-
if (!OidIsValid(oid)&& !missing_ok)
222-
ereport(ERROR,
223-
(errcode(ERRCODE_UNDEFINED_OBJECT),
224-
errmsg("subscription \"%s\" does not exist",subname)));
225-
returnoid;
226-
}
227-
228-
/*
229-
* get_subscription_name - given a subscription OID, look up the name
230-
*
231-
* If missing_ok is false, throw an error if name not found. If true, just
232-
* return NULL.
233-
*/
234-
char*
235-
get_subscription_name(Oidsubid,boolmissing_ok)
236-
{
237-
HeapTupletup;
238-
char*subname;
239-
Form_pg_subscriptionsubform;
240-
241-
tup=SearchSysCache1(SUBSCRIPTIONOID,ObjectIdGetDatum(subid));
242-
243-
if (!HeapTupleIsValid(tup))
244-
{
245-
if (!missing_ok)
246-
elog(ERROR,"cache lookup failed for subscription %u",subid);
247-
returnNULL;
248-
}
249-
250-
subform= (Form_pg_subscription)GETSTRUCT(tup);
251-
subname=pstrdup(NameStr(subform->subname));
252-
253-
ReleaseSysCache(tup);
254-
255-
returnsubname;
256-
}
257-
258208
/*
259209
* Convert text array to list of strings.
260210
*

‎src/backend/utils/cache/lsyscache.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"catalog/pg_proc.h"
3434
#include"catalog/pg_range.h"
3535
#include"catalog/pg_statistic.h"
36+
#include"catalog/pg_subscription.h"
3637
#include"catalog/pg_transform.h"
3738
#include"catalog/pg_type.h"
3839
#include"miscadmin.h"
@@ -3578,3 +3579,103 @@ get_index_isclustered(Oid index_oid)
35783579

35793580
returnisclustered;
35803581
}
3582+
3583+
/*
3584+
* get_publication_oid - given a publication name, look up the OID
3585+
*
3586+
* If missing_ok is false, throw an error if name not found. If true, just
3587+
* return InvalidOid.
3588+
*/
3589+
Oid
3590+
get_publication_oid(constchar*pubname,boolmissing_ok)
3591+
{
3592+
Oidoid;
3593+
3594+
oid=GetSysCacheOid1(PUBLICATIONNAME,Anum_pg_publication_oid,
3595+
CStringGetDatum(pubname));
3596+
if (!OidIsValid(oid)&& !missing_ok)
3597+
ereport(ERROR,
3598+
(errcode(ERRCODE_UNDEFINED_OBJECT),
3599+
errmsg("publication \"%s\" does not exist",pubname)));
3600+
returnoid;
3601+
}
3602+
3603+
/*
3604+
* get_publication_name - given a publication Oid, look up the name
3605+
*
3606+
* If missing_ok is false, throw an error if name not found. If true, just
3607+
* return NULL.
3608+
*/
3609+
char*
3610+
get_publication_name(Oidpubid,boolmissing_ok)
3611+
{
3612+
HeapTupletup;
3613+
char*pubname;
3614+
Form_pg_publicationpubform;
3615+
3616+
tup=SearchSysCache1(PUBLICATIONOID,ObjectIdGetDatum(pubid));
3617+
3618+
if (!HeapTupleIsValid(tup))
3619+
{
3620+
if (!missing_ok)
3621+
elog(ERROR,"cache lookup failed for publication %u",pubid);
3622+
returnNULL;
3623+
}
3624+
3625+
pubform= (Form_pg_publication)GETSTRUCT(tup);
3626+
pubname=pstrdup(NameStr(pubform->pubname));
3627+
3628+
ReleaseSysCache(tup);
3629+
3630+
returnpubname;
3631+
}
3632+
3633+
/*
3634+
* get_subscription_oid - given a subscription name, look up the OID
3635+
*
3636+
* If missing_ok is false, throw an error if name not found. If true, just
3637+
* return InvalidOid.
3638+
*/
3639+
Oid
3640+
get_subscription_oid(constchar*subname,boolmissing_ok)
3641+
{
3642+
Oidoid;
3643+
3644+
oid=GetSysCacheOid2(SUBSCRIPTIONNAME,Anum_pg_subscription_oid,
3645+
MyDatabaseId,CStringGetDatum(subname));
3646+
if (!OidIsValid(oid)&& !missing_ok)
3647+
ereport(ERROR,
3648+
(errcode(ERRCODE_UNDEFINED_OBJECT),
3649+
errmsg("subscription \"%s\" does not exist",subname)));
3650+
returnoid;
3651+
}
3652+
3653+
/*
3654+
* get_subscription_name - given a subscription OID, look up the name
3655+
*
3656+
* If missing_ok is false, throw an error if name not found. If true, just
3657+
* return NULL.
3658+
*/
3659+
char*
3660+
get_subscription_name(Oidsubid,boolmissing_ok)
3661+
{
3662+
HeapTupletup;
3663+
char*subname;
3664+
Form_pg_subscriptionsubform;
3665+
3666+
tup=SearchSysCache1(SUBSCRIPTIONOID,ObjectIdGetDatum(subid));
3667+
3668+
if (!HeapTupleIsValid(tup))
3669+
{
3670+
if (!missing_ok)
3671+
elog(ERROR,"cache lookup failed for subscription %u",subid);
3672+
returnNULL;
3673+
}
3674+
3675+
subform= (Form_pg_subscription)GETSTRUCT(tup);
3676+
subname=pstrdup(NameStr(subform->subname));
3677+
3678+
ReleaseSysCache(tup);
3679+
3680+
returnsubname;
3681+
}

‎src/include/catalog/pg_publication.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,4 @@ extern ObjectAddress publication_add_schema(Oid pubid, Oid schemaid,
155155
externBitmapset*pub_collist_to_bitmapset(Bitmapset*columns,Datumpubcols,
156156
MemoryContextmcxt);
157157

158-
externOidget_publication_oid(constchar*pubname,boolmissing_ok);
159-
externchar*get_publication_name(Oidpubid,boolmissing_ok);
160-
161158
#endif/* PG_PUBLICATION_H */

‎src/include/catalog/pg_subscription.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ typedef struct Subscription
140140
externSubscription*GetSubscription(Oidsubid,boolmissing_ok);
141141
externvoidFreeSubscription(Subscription*sub);
142142
externvoidDisableSubscription(Oidsubid);
143-
externOidget_subscription_oid(constchar*subname,boolmissing_ok);
144-
externchar*get_subscription_name(Oidsubid,boolmissing_ok);
145143

146144
externintCountDBSubscriptions(Oiddbid);
147145

‎src/include/utils/lsyscache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ extern Oidget_index_column_opclass(Oid index_oid, int attno);
198198
externboolget_index_isreplident(Oidindex_oid);
199199
externboolget_index_isvalid(Oidindex_oid);
200200
externboolget_index_isclustered(Oidindex_oid);
201+
externOidget_publication_oid(constchar*pubname,boolmissing_ok);
202+
externchar*get_publication_name(Oidpubid,boolmissing_ok);
203+
externOidget_subscription_oid(constchar*subname,boolmissing_ok);
204+
externchar*get_subscription_name(Oidsubid,boolmissing_ok);
201205

202206
#definetype_is_array(typid) (get_element_type(typid) != InvalidOid)
203207
/* type_is_array_domain accepts both plain arrays and domains over arrays */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp