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

Commit95d7714

Browse files
committed
Add macro RelationIsPermanent() to report relation permanence
Previously, to check relation permanence, the Relation's Form_pg_classstructure member relpersistence was compared to the valueRELPERSISTENCE_PERMANENT ("p"). This commit adds the macroRelationIsPermanent() and is used in appropirate places to simplify thecode. This matches other RelationIs* macros.This macro will be used in more places in future cluster file encryptionpatches.Discussion:https://postgr.es/m/20210318153134.GH20766@tamriel.snowman.net
1 parent8e4b332 commit95d7714

File tree

8 files changed

+19
-15
lines changed

8 files changed

+19
-15
lines changed

‎src/backend/access/gist/gistutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ gistGetFakeLSN(Relation rel)
10361036

10371037
returncounter++;
10381038
}
1039-
elseif (rel->rd_rel->relpersistence==RELPERSISTENCE_PERMANENT)
1039+
elseif (RelationIsPermanent(rel))
10401040
{
10411041
/*
10421042
* WAL-logging on this relation will start after commit, so its LSNs

‎src/backend/access/heap/heapam_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ heapam_relation_copy_data(Relation rel, const RelFileNode *newrnode)
662662
* WAL log creation if the relation is persistent, or this is the
663663
* init fork of an unlogged relation.
664664
*/
665-
if (rel->rd_rel->relpersistence==RELPERSISTENCE_PERMANENT||
665+
if (RelationIsPermanent(rel)||
666666
(rel->rd_rel->relpersistence==RELPERSISTENCE_UNLOGGED&&
667667
forkNum==INIT_FORKNUM))
668668
log_smgrcreate(newrnode,forkNum);

‎src/backend/catalog/pg_publication.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel)
6767
errdetail("System tables cannot be added to publications.")));
6868

6969
/* UNLOGGED and TEMP relations cannot be part of publication. */
70-
if (targetrel->rd_rel->relpersistence!=RELPERSISTENCE_PERMANENT)
70+
if (!RelationIsPermanent(targetrel))
7171
ereport(ERROR,
7272
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7373
errmsg("table \"%s\" cannot be replicated",

‎src/backend/commands/tablecmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,13 +8650,13 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
86508650
switch (rel->rd_rel->relpersistence)
86518651
{
86528652
case RELPERSISTENCE_PERMANENT:
8653-
if (pkrel->rd_rel->relpersistence != RELPERSISTENCE_PERMANENT)
8653+
if (!RelationIsPermanent(pkrel))
86548654
ereport(ERROR,
86558655
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
86568656
errmsg("constraints on permanent tables may reference only permanent tables")));
86578657
break;
86588658
case RELPERSISTENCE_UNLOGGED:
8659-
if (pkrel->rd_rel->relpersistence != RELPERSISTENCE_PERMANENT
8659+
if (!RelationIsPermanent(pkrel)
86608660
&& pkrel->rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
86618661
ereport(ERROR,
86628662
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
@@ -13712,7 +13712,7 @@ index_copy_data(Relation rel, RelFileNode newrnode)
1371213712
* WAL log creation if the relation is persistent, or this is the
1371313713
* init fork of an unlogged relation.
1371413714
*/
13715-
if (rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT ||
13715+
if (RelationIsPermanent(rel) ||
1371613716
(rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
1371713717
forkNum == INIT_FORKNUM))
1371813718
log_smgrcreate(&newrnode, forkNum);
@@ -15230,7 +15230,7 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
1523015230

1523115231
if (toLogged)
1523215232
{
15233-
if (foreignrel->rd_rel->relpersistence != RELPERSISTENCE_PERMANENT)
15233+
if (!RelationIsPermanent(foreignrel))
1523415234
ereport(ERROR,
1523515235
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1523615236
errmsg("could not change table \"%s\" to logged because it references unlogged table \"%s\"",
@@ -15240,7 +15240,7 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
1524015240
}
1524115241
else
1524215242
{
15243-
if (foreignrel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
15243+
if (RelationIsPermanent(foreignrel))
1524415244
ereport(ERROR,
1524515245
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1524615246
errmsg("could not change table \"%s\" to unlogged because it references logged table \"%s\"",

‎src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
126126
relation=table_open(relationObjectId,NoLock);
127127

128128
/* Temporary and unlogged relations are inaccessible during recovery. */
129-
if (relation->rd_rel->relpersistence!=RELPERSISTENCE_PERMANENT&&
130-
RecoveryInProgress())
129+
if (!RelationIsPermanent(relation)&&RecoveryInProgress())
131130
ereport(ERROR,
132131
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
133132
errmsg("cannot access temporary or unlogged relations during recovery")));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ static void
29902990
AssertPendingSyncConsistency(Relationrelation)
29912991
{
29922992
boolrelcache_verdict=
2993-
relation->rd_rel->relpersistence==RELPERSISTENCE_PERMANENT&&
2993+
RelationIsPermanent(relation)&&
29942994
((relation->rd_createSubid!=InvalidSubTransactionId&&
29952995
RELKIND_HAS_STORAGE(relation->rd_rel->relkind))||
29962996
relation->rd_firstRelfilenodeSubid!=InvalidSubTransactionId);

‎src/include/utils/rel.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,13 @@ typedef struct PartitionedTableRdOptions
577577
(relation)->rd_smgr->smgr_targblock = (targblock); \
578578
} while (0)
579579

580+
/*
581+
* RelationIsPermanent
582+
*True if relation is permanent.
583+
*/
584+
#defineRelationIsPermanent(relation) \
585+
((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
586+
580587
/*
581588
* RelationNeedsWAL
582589
*True if relation needs WAL.
@@ -586,8 +593,7 @@ typedef struct PartitionedTableRdOptions
586593
* RelFileNode" in src/backend/access/transam/README.
587594
*/
588595
#defineRelationNeedsWAL(relation)\
589-
((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT &&\
590-
(XLogIsNeeded() ||\
596+
(RelationIsPermanent(relation) && (XLogIsNeeded() ||\
591597
(relation->rd_createSubid == InvalidSubTransactionId &&\
592598
relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
593599

‎src/include/utils/snapmgr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
*/
3838
#defineRelationAllowsEarlyPruning(rel) \
3939
( \
40-
(rel)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT\
41-
&& !IsCatalogRelation(rel) \
40+
RelationIsPermanent(rel) && !IsCatalogRelation(rel) \
4241
&& !RelationIsAccessibleInLogicalDecoding(rel) \
4342
)
4443

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp