mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
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
This commit is contained in:
parent
9ee16b49f0
commit
7636c0c821
@ -152,7 +152,7 @@ typedef struct AlteredTableInfo
|
|||||||
bool new_notnull; /* T if we added new NOT NULL constraints */
|
bool new_notnull; /* T if we added new NOT NULL constraints */
|
||||||
bool rewrite; /* T if a rewrite is forced */
|
bool rewrite; /* T if a rewrite is forced */
|
||||||
Oid newTableSpace; /* new tablespace; 0 means no change */
|
Oid newTableSpace; /* new tablespace; 0 means no change */
|
||||||
bool chgLoggedness; /* T if SET LOGGED/UNLOGGED is used */
|
bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
|
||||||
char newrelpersistence; /* if above is true */
|
char newrelpersistence; /* if above is true */
|
||||||
/* Objects to rebuild after completing ALTER TYPE operations */
|
/* Objects to rebuild after completing ALTER TYPE operations */
|
||||||
List *changedConstraintOids; /* OIDs of constraints to rebuild */
|
List *changedConstraintOids; /* OIDs of constraints to rebuild */
|
||||||
@ -388,8 +388,8 @@ static void change_owner_recurse_to_sequences(Oid relationOid,
|
|||||||
static void ATExecClusterOn(Relation rel, const char *indexName,
|
static void ATExecClusterOn(Relation rel, const char *indexName,
|
||||||
LOCKMODE lockmode);
|
LOCKMODE lockmode);
|
||||||
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
|
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
|
||||||
static bool ATPrepChangeLoggedness(Relation rel, bool toLogged);
|
static bool ATPrepChangePersistence(Relation rel, bool toLogged);
|
||||||
static void ATChangeIndexesLoggedness(Oid relid, char relpersistence);
|
static void ATChangeIndexesPersistence(Oid relid, char relpersistence);
|
||||||
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
|
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
|
||||||
char *tablespacename, LOCKMODE lockmode);
|
char *tablespacename, LOCKMODE lockmode);
|
||||||
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
|
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
|
||||||
@ -3174,19 +3174,19 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
|||||||
break;
|
break;
|
||||||
case AT_SetLogged: /* SET LOGGED */
|
case AT_SetLogged: /* SET LOGGED */
|
||||||
ATSimplePermissions(rel, ATT_TABLE);
|
ATSimplePermissions(rel, ATT_TABLE);
|
||||||
tab->chgLoggedness = ATPrepChangeLoggedness(rel, true);
|
tab->chgPersistence = ATPrepChangePersistence(rel, true);
|
||||||
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
|
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
|
||||||
/* force rewrite if necessary */
|
/* force rewrite if necessary */
|
||||||
if (tab->chgLoggedness)
|
if (tab->chgPersistence)
|
||||||
tab->rewrite = true;
|
tab->rewrite = true;
|
||||||
pass = AT_PASS_MISC;
|
pass = AT_PASS_MISC;
|
||||||
break;
|
break;
|
||||||
case AT_SetUnLogged: /* SET UNLOGGED */
|
case AT_SetUnLogged: /* SET UNLOGGED */
|
||||||
ATSimplePermissions(rel, ATT_TABLE);
|
ATSimplePermissions(rel, ATT_TABLE);
|
||||||
tab->chgLoggedness = ATPrepChangeLoggedness(rel, false);
|
tab->chgPersistence = ATPrepChangePersistence(rel, false);
|
||||||
tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
|
tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
|
||||||
/* force rewrite if necessary */
|
/* force rewrite if necessary */
|
||||||
if (tab->chgLoggedness)
|
if (tab->chgPersistence)
|
||||||
tab->rewrite = true;
|
tab->rewrite = true;
|
||||||
pass = AT_PASS_MISC;
|
pass = AT_PASS_MISC;
|
||||||
break;
|
break;
|
||||||
@ -3618,6 +3618,13 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
|
|||||||
* We only need to rewrite the table if at least one column needs to
|
* We only need to rewrite the table if at least one column needs to
|
||||||
* be recomputed, we are adding/removing the OID column, or we are
|
* be recomputed, we are adding/removing the OID column, or we are
|
||||||
* changing its persistence.
|
* changing its persistence.
|
||||||
|
*
|
||||||
|
* There are two reasons for requiring a rewrite when changing
|
||||||
|
* persistence: on one hand, we need to ensure that the buffers
|
||||||
|
* belonging to each of the two relations are marked with or without
|
||||||
|
* BM_PERMANENT properly. On the other hand, since rewriting creates
|
||||||
|
* and assigns a new relfilenode, we automatically create or drop an
|
||||||
|
* init fork for the relation as appropriate.
|
||||||
*/
|
*/
|
||||||
if (tab->rewrite)
|
if (tab->rewrite)
|
||||||
{
|
{
|
||||||
@ -3668,7 +3675,7 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
|
|||||||
* Select persistence of transient table (same as original unless
|
* Select persistence of transient table (same as original unless
|
||||||
* user requested a change)
|
* user requested a change)
|
||||||
*/
|
*/
|
||||||
persistence = tab->chgLoggedness ?
|
persistence = tab->chgPersistence ?
|
||||||
tab->newrelpersistence : OldHeap->rd_rel->relpersistence;
|
tab->newrelpersistence : OldHeap->rd_rel->relpersistence;
|
||||||
|
|
||||||
heap_close(OldHeap, NoLock);
|
heap_close(OldHeap, NoLock);
|
||||||
@ -3705,8 +3712,8 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
|
|||||||
* because the rewrite step might read the indexes, and that would
|
* because the rewrite step might read the indexes, and that would
|
||||||
* cause buffers for them to have the wrong setting.
|
* cause buffers for them to have the wrong setting.
|
||||||
*/
|
*/
|
||||||
if (tab->chgLoggedness)
|
if (tab->chgPersistence)
|
||||||
ATChangeIndexesLoggedness(tab->relid, tab->newrelpersistence);
|
ATChangeIndexesPersistence(tab->relid, tab->newrelpersistence);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Swap the physical files of the old and new heaps, then rebuild
|
* Swap the physical files of the old and new heaps, then rebuild
|
||||||
@ -4119,7 +4126,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
|
|||||||
tab->relkind = rel->rd_rel->relkind;
|
tab->relkind = rel->rd_rel->relkind;
|
||||||
tab->oldDesc = CreateTupleDescCopy(RelationGetDescr(rel));
|
tab->oldDesc = CreateTupleDescCopy(RelationGetDescr(rel));
|
||||||
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
|
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
|
||||||
tab->chgLoggedness = false;
|
tab->chgPersistence = false;
|
||||||
|
|
||||||
*wqueue = lappend(*wqueue, tab);
|
*wqueue = lappend(*wqueue, tab);
|
||||||
|
|
||||||
@ -10678,7 +10685,7 @@ ATExecGenericOptions(Relation rel, List *options)
|
|||||||
* checks are skipped), otherwise true.
|
* checks are skipped), otherwise true.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
ATPrepChangeLoggedness(Relation rel, bool toLogged)
|
ATPrepChangePersistence(Relation rel, bool toLogged)
|
||||||
{
|
{
|
||||||
Relation pg_constraint;
|
Relation pg_constraint;
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
@ -10722,7 +10729,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Scan conrelid if changing to permanent, else confrelid. This also
|
* Scan conrelid if changing to permanent, else confrelid. This also
|
||||||
* determines whether an useful index exists.
|
* determines whether a useful index exists.
|
||||||
*/
|
*/
|
||||||
ScanKeyInit(&skey[0],
|
ScanKeyInit(&skey[0],
|
||||||
toLogged ? Anum_pg_constraint_conrelid :
|
toLogged ? Anum_pg_constraint_conrelid :
|
||||||
@ -10792,7 +10799,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
|
|||||||
* given persistence.
|
* given persistence.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ATChangeIndexesLoggedness(Oid relid, char relpersistence)
|
ATChangeIndexesPersistence(Oid relid, char relpersistence)
|
||||||
{
|
{
|
||||||
Relation rel;
|
Relation rel;
|
||||||
Relation pg_class;
|
Relation pg_class;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user