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

Commit7636c0c

Browse files
committed
Editorial review of SET UNLOGGED
Add a succint comment explaining why it's correct to change thepersistence in this way. Also s/loggedness/persistence/ because nativespeakers didn't like the latter term.Fabrízio and Álvaro
1 parent9ee16b4 commit7636c0c

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
boolnew_notnull;/* T if we added new NOT NULL constraints */
153153
boolrewrite;/* T if a rewrite is forced */
154154
OidnewTableSpace;/* new tablespace; 0 means no change */
155-
boolchgLoggedness;/* T if SET LOGGED/UNLOGGED is used */
155+
boolchgPersistence;/* T if SET LOGGED/UNLOGGED is used */
156156
charnewrelpersistence;/* 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
staticvoidATExecClusterOn(Relationrel,constchar*indexName,
389389
LOCKMODElockmode);
390390
staticvoidATExecDropCluster(Relationrel,LOCKMODElockmode);
391-
staticboolATPrepChangeLoggedness(Relationrel,booltoLogged);
392-
staticvoidATChangeIndexesLoggedness(Oidrelid,charrelpersistence);
391+
staticboolATPrepChangePersistence(Relationrel,booltoLogged);
392+
staticvoidATChangeIndexesPersistence(Oidrelid,charrelpersistence);
393393
staticvoidATPrepSetTableSpace(AlteredTableInfo*tab,Relationrel,
394394
char*tablespacename,LOCKMODElockmode);
395395
staticvoidATExecSetTableSpace(OidtableOid,OidnewTableSpace,LOCKMODElockmode);
@@ -3174,19 +3174,19 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
31743174
break;
31753175
caseAT_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
caseAT_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
staticbool
10681-
ATPrepChangeLoggedness(Relationrel,booltoLogged)
10688+
ATPrepChangePersistence(Relationrel,booltoLogged)
1068210689
{
1068310690
Relationpg_constraint;
1068410691
HeapTupletuple;
@@ -10722,7 +10729,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
1072210729

1072310730
/*
1072410731
* Scan conrelid if changing to permanent, else confrelid. This also
10725-
* determines whetheran useful index exists.
10732+
* determines whethera 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
staticvoid
10795-
ATChangeIndexesLoggedness(Oidrelid,charrelpersistence)
10802+
ATChangeIndexesPersistence(Oidrelid,charrelpersistence)
1079610803
{
1079710804
Relationrel;
1079810805
Relationpg_class;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp