Skip to content

Commit 7636c0c

Browse files
committed
Editorial review of SET UNLOGGED
Add a succint comment explaining why it's correct to change the persistence in this way. Also s/loggedness/persistence/ because native speakers didn't like the latter term. Fabrízio and Álvaro
1 parent 9ee16b4 commit 7636c0c

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/backend/commands/tablecmds.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef struct AlteredTableInfo
152152
bool new_notnull; /* T if we added new NOT NULL constraints */
153153
bool rewrite; /* T if a rewrite is forced */
154154
Oid newTableSpace; /* new tablespace; 0 means no change */
155-
bool chgLoggedness; /* T if SET LOGGED/UNLOGGED is used */
155+
bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
156156
char newrelpersistence; /* if above is true */
157157
/* Objects to rebuild after completing ALTER TYPE operations */
158158
List *changedConstraintOids; /* OIDs of constraints to rebuild */
@@ -388,8 +388,8 @@ static void change_owner_recurse_to_sequences(Oid relationOid,
388388
static void ATExecClusterOn(Relation rel, const char *indexName,
389389
LOCKMODE lockmode);
390390
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
391-
static bool ATPrepChangeLoggedness(Relation rel, bool toLogged);
392-
static void ATChangeIndexesLoggedness(Oid relid, char relpersistence);
391+
static bool ATPrepChangePersistence(Relation rel, bool toLogged);
392+
static void ATChangeIndexesPersistence(Oid relid, char relpersistence);
393393
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
394394
char *tablespacename, LOCKMODE lockmode);
395395
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
@@ -3174,19 +3174,19 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
31743174
break;
31753175
case AT_SetLogged: /* SET LOGGED */
31763176
ATSimplePermissions(rel, ATT_TABLE);
3177-
tab->chgLoggedness = ATPrepChangeLoggedness(rel, true);
3177+
tab->chgPersistence = ATPrepChangePersistence(rel, true);
31783178
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
31793179
/* force rewrite if necessary */
3180-
if (tab->chgLoggedness)
3180+
if (tab->chgPersistence)
31813181
tab->rewrite = true;
31823182
pass = AT_PASS_MISC;
31833183
break;
31843184
case AT_SetUnLogged: /* SET UNLOGGED */
31853185
ATSimplePermissions(rel, ATT_TABLE);
3186-
tab->chgLoggedness = ATPrepChangeLoggedness(rel, false);
3186+
tab->chgPersistence = ATPrepChangePersistence(rel, false);
31873187
tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
31883188
/* force rewrite if necessary */
3189-
if (tab->chgLoggedness)
3189+
if (tab->chgPersistence)
31903190
tab->rewrite = true;
31913191
pass = AT_PASS_MISC;
31923192
break;
@@ -3618,6 +3618,13 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
36183618
* We only need to rewrite the table if at least one column needs to
36193619
* be recomputed, we are adding/removing the OID column, or we are
36203620
* changing its persistence.
3621+
*
3622+
* There are two reasons for requiring a rewrite when changing
3623+
* persistence: on one hand, we need to ensure that the buffers
3624+
* belonging to each of the two relations are marked with or without
3625+
* BM_PERMANENT properly. On the other hand, since rewriting creates
3626+
* and assigns a new relfilenode, we automatically create or drop an
3627+
* init fork for the relation as appropriate.
36213628
*/
36223629
if (tab->rewrite)
36233630
{
@@ -3668,7 +3675,7 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
36683675
* Select persistence of transient table (same as original unless
36693676
* user requested a change)
36703677
*/
3671-
persistence = tab->chgLoggedness ?
3678+
persistence = tab->chgPersistence ?
36723679
tab->newrelpersistence : OldHeap->rd_rel->relpersistence;
36733680

36743681
heap_close(OldHeap, NoLock);
@@ -3705,8 +3712,8 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
37053712
* because the rewrite step might read the indexes, and that would
37063713
* cause buffers for them to have the wrong setting.
37073714
*/
3708-
if (tab->chgLoggedness)
3709-
ATChangeIndexesLoggedness(tab->relid, tab->newrelpersistence);
3715+
if (tab->chgPersistence)
3716+
ATChangeIndexesPersistence(tab->relid, tab->newrelpersistence);
37103717

37113718
/*
37123719
* Swap the physical files of the old and new heaps, then rebuild
@@ -4119,7 +4126,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
41194126
tab->relkind = rel->rd_rel->relkind;
41204127
tab->oldDesc = CreateTupleDescCopy(RelationGetDescr(rel));
41214128
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
4122-
tab->chgLoggedness = false;
4129+
tab->chgPersistence = false;
41234130

41244131
*wqueue = lappend(*wqueue, tab);
41254132

@@ -10678,7 +10685,7 @@ ATExecGenericOptions(Relation rel, List *options)
1067810685
* checks are skipped), otherwise true.
1067910686
*/
1068010687
static bool
10681-
ATPrepChangeLoggedness(Relation rel, bool toLogged)
10688+
ATPrepChangePersistence(Relation rel, bool toLogged)
1068210689
{
1068310690
Relation pg_constraint;
1068410691
HeapTuple tuple;
@@ -10722,7 +10729,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
1072210729

1072310730
/*
1072410731
* Scan conrelid if changing to permanent, else confrelid. This also
10725-
* determines whether an useful index exists.
10732+
* determines whether a useful index exists.
1072610733
*/
1072710734
ScanKeyInit(&skey[0],
1072810735
toLogged ? Anum_pg_constraint_conrelid :
@@ -10792,7 +10799,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
1079210799
* given persistence.
1079310800
*/
1079410801
static void
10795-
ATChangeIndexesLoggedness(Oid relid, char relpersistence)
10802+
ATChangeIndexesPersistence(Oid relid, char relpersistence)
1079610803
{
1079710804
Relation rel;
1079810805
Relation pg_class;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy