bool new_notnull; /* T if we added new NOT NULL constraints */
bool rewrite; /* T if a rewrite is forced */
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 */
/* Objects to rebuild after completing ALTER TYPE operations */
List *changedConstraintOids; /* OIDs of constraints to rebuild */
static void ATExecClusterOn(Relation rel, const char *indexName,
LOCKMODE lockmode);
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
-static bool ATPrepChangeLoggedness(Relation rel, bool toLogged);
-static void ATChangeIndexesLoggedness(Oid relid, char relpersistence);
+static bool ATPrepChangePersistence(Relation rel, bool toLogged);
+static void ATChangeIndexesPersistence(Oid relid, char relpersistence);
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
char *tablespacename, LOCKMODE lockmode);
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
break;
case AT_SetLogged: /* SET LOGGED */
ATSimplePermissions(rel, ATT_TABLE);
- tab->chgLoggedness = ATPrepChangeLoggedness(rel, true);
+ tab->chgPersistence = ATPrepChangePersistence(rel, true);
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
/* force rewrite if necessary */
- if (tab->chgLoggedness)
+ if (tab->chgPersistence)
tab->rewrite = true;
pass = AT_PASS_MISC;
break;
case AT_SetUnLogged: /* SET UNLOGGED */
ATSimplePermissions(rel, ATT_TABLE);
- tab->chgLoggedness = ATPrepChangeLoggedness(rel, false);
+ tab->chgPersistence = ATPrepChangePersistence(rel, false);
tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
/* force rewrite if necessary */
- if (tab->chgLoggedness)
+ if (tab->chgPersistence)
tab->rewrite = true;
pass = AT_PASS_MISC;
break;
* 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
* 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)
{
* Select persistence of transient table (same as original unless
* user requested a change)
*/
- persistence = tab->chgLoggedness ?
+ persistence = tab->chgPersistence ?
tab->newrelpersistence : OldHeap->rd_rel->relpersistence;
heap_close(OldHeap, NoLock);
* because the rewrite step might read the indexes, and that would
* cause buffers for them to have the wrong setting.
*/
- if (tab->chgLoggedness)
- ATChangeIndexesLoggedness(tab->relid, tab->newrelpersistence);
+ if (tab->chgPersistence)
+ ATChangeIndexesPersistence(tab->relid, tab->newrelpersistence);
/*
* Swap the physical files of the old and new heaps, then rebuild
tab->relkind = rel->rd_rel->relkind;
tab->oldDesc = CreateTupleDescCopy(RelationGetDescr(rel));
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
- tab->chgLoggedness = false;
+ tab->chgPersistence = false;
*wqueue = lappend(*wqueue, tab);
* checks are skipped), otherwise true.
*/
static bool
-ATPrepChangeLoggedness(Relation rel, bool toLogged)
+ATPrepChangePersistence(Relation rel, bool toLogged)
{
Relation pg_constraint;
HeapTuple tuple;
/*
* 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],
toLogged ? Anum_pg_constraint_conrelid :
* given persistence.
*/
static void
-ATChangeIndexesLoggedness(Oid relid, char relpersistence)
+ATChangeIndexesPersistence(Oid relid, char relpersistence)
{
Relation rel;
Relation pg_class;