diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-11-15 01:19:49 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-11-15 01:19:49 -0300 |
commit | 85b506bbfc2937c9abdfcce4e01a8feca8e64ee8 (patch) | |
tree | 6525cd42c9bd3dec7e2eadcedc0594e8c113c403 /src/backend/commands | |
parent | e4d1e264918f4019c86c807e7c349658f7a10397 (diff) | |
download | postgresql-85b506bbfc2937c9abdfcce4e01a8feca8e64ee8.tar.gz postgresql-85b506bbfc2937c9abdfcce4e01a8feca8e64ee8.zip |
Get rid of SET LOGGED indexes persistence kludge
This removes ATChangeIndexesPersistence() introduced by f41872d0c1239d36
which was too ugly to live for long. Instead, the correct persistence
marking is passed all the way down to reindex_index, so that the
transient relation built to contain the index relfilenode can
get marked correctly right from the start.
Author: Fabrízio de Royes Mello
Review and editorialization by Michael Paquier
and Álvaro Herrera
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/cluster.c | 16 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/matview.c | 8 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 56 |
4 files changed, 21 insertions, 61 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 6a578ec58f5..bc5f33fb785 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -589,7 +589,8 @@ rebuild_relation(Relation OldHeap, Oid indexOid, bool verbose) */ finish_heap_swap(tableOid, OIDNewHeap, is_system_catalog, swap_toast_by_content, false, true, - frozenXid, cutoffMulti); + frozenXid, cutoffMulti, + OldHeap->rd_rel->relpersistence); } @@ -1475,7 +1476,8 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool check_constraints, bool is_internal, TransactionId frozenXid, - MultiXactId cutoffMulti) + MultiXactId cutoffMulti, + char newrelpersistence) { ObjectAddress object; Oid mapped_tables[4]; @@ -1519,6 +1521,16 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, reindex_flags = REINDEX_REL_SUPPRESS_INDEX_USE; if (check_constraints) reindex_flags |= REINDEX_REL_CHECK_CONSTRAINTS; + + /* + * Ensure that the indexes have the same persistence as the parent + * relation. + */ + if (newrelpersistence == RELPERSISTENCE_UNLOGGED) + reindex_flags |= REINDEX_REL_FORCE_INDEXES_UNLOGGED; + else if (newrelpersistence == RELPERSISTENCE_PERMANENT) + reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; + reindex_relation(OIDOldHeap, reindex_flags); /* diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 02055950b58..12b4ac7b3ce 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1689,7 +1689,7 @@ ReindexIndex(RangeVar *indexRelation) RangeVarCallbackForReindexIndex, (void *) &heapOid); - reindex_index(indOid, false); + reindex_index(indOid, false, indexRelation->relpersistence); return indOid; } diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index 523ba35ba24..b19da4ac63c 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -67,7 +67,7 @@ static void mv_GenerateOper(StringInfo buf, Oid opoid); static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context); -static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap); +static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence); static void OpenMatViewIncrementalMaintenance(void); static void CloseMatViewIncrementalMaintenance(void); @@ -303,7 +303,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, Assert(matview_maintenance_depth == old_depth); } else - refresh_by_heap_swap(matviewOid, OIDNewHeap); + refresh_by_heap_swap(matviewOid, OIDNewHeap, relpersistence); /* Roll back any GUC changes */ AtEOXact_GUC(false, save_nestlevel); @@ -759,10 +759,10 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, * swapping is handled by the called function, so it is not needed here. */ static void -refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap) +refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence) { finish_heap_swap(matviewOid, OIDNewHeap, false, false, true, true, - RecentXmin, ReadNextMultiXactId()); + RecentXmin, ReadNextMultiXactId(), relpersistence); } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 714a9f1ee78..093224f4e64 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -393,7 +393,6 @@ static void ATExecClusterOn(Relation rel, const char *indexName, LOCKMODE lockmode); static void ATExecDropCluster(Relation rel, LOCKMODE lockmode); 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); @@ -3735,16 +3734,6 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode) ATRewriteTable(tab, OIDNewHeap, lockmode); /* - * Change the persistence marking of indexes, if necessary. This - * is so that the new copies are built with the right persistence - * in the reindex step below. Note we cannot do this earlier, - * because the rewrite step might read the indexes, and that would - * cause buffers for them to have the wrong setting. - */ - if (tab->chgPersistence) - ATChangeIndexesPersistence(tab->relid, tab->newrelpersistence); - - /* * Swap the physical files of the old and new heaps, then rebuild * indexes and discard the old heap. We can use RecentXmin for * the table's new relfrozenxid because we rewrote all the tuples @@ -3756,7 +3745,8 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode) false, false, true, !OidIsValid(tab->newTableSpace), RecentXmin, - ReadNextMultiXactId()); + ReadNextMultiXactId(), + persistence); } else { @@ -10880,48 +10870,6 @@ ATPrepChangePersistence(Relation rel, bool toLogged) } /* - * Update the pg_class entry of each index for the given relation to the - * given persistence. - */ -static void -ATChangeIndexesPersistence(Oid relid, char relpersistence) -{ - Relation rel; - Relation pg_class; - List *indexes; - ListCell *cell; - - pg_class = heap_open(RelationRelationId, RowExclusiveLock); - - /* We already have a lock on the table */ - rel = relation_open(relid, NoLock); - indexes = RelationGetIndexList(rel); - foreach(cell, indexes) - { - Oid indexid = lfirst_oid(cell); - HeapTuple tuple; - Form_pg_class pg_class_form; - - tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(indexid)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for relation %u", - indexid); - - pg_class_form = (Form_pg_class) GETSTRUCT(tuple); - pg_class_form->relpersistence = relpersistence; - simple_heap_update(pg_class, &tuple->t_self, tuple); - - /* keep catalog indexes current */ - CatalogUpdateIndexes(pg_class, tuple); - - heap_freetuple(tuple); - } - - heap_close(pg_class, RowExclusiveLock); - heap_close(rel, NoLock); -} - -/* * Execute ALTER TABLE SET SCHEMA */ Oid |