diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-04 00:09:14 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-02-04 00:09:14 +0000 |
commit | 9727c583fe863252338dc4c5a925d78c59128c93 (patch) | |
tree | a5cc318744cccb7cb60565b2e0b11f7997cfde15 /src/backend/commands/tablecmds.c | |
parent | fdac8cf998b9a41fa2b64cb3a80bc02548189082 (diff) |
Restructure CLUSTER/newstyle VACUUM FULL/ALTER TABLE support so that swapping
of old and new toast tables can be done either at the logical level (by
swapping the heaps' reltoastrelid links) or at the physical level (by swapping
the relfilenodes of the toast tables and their indexes). This is necessary
infrastructure for upcoming changes to support CLUSTER/VAC FULL on shared
system catalogs, where we cannot change reltoastrelid. The physical swap
saves a few catalog updates too.
We unfortunately have to keep the logical-level swap logic because in some
cases we will be adding or deleting a toast table, so there's no possibility
of a physical swap. However, that only happens as a consequence of schema
changes in the table, which we do not need to support for system catalogs,
so such cases aren't an obstacle for that.
In passing, refactor the cluster support functions a little bit to eliminate
unnecessarily-duplicated code; and fix the problem that while CLUSTER had
been taught to rename the final toast table at need, ALTER TABLE had not.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 48 |
1 files changed, 10 insertions, 38 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index a729adb0550..dba5f29d661 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.323 2010/02/03 10:01:29 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.324 2010/02/04 00:09:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2866,11 +2866,9 @@ ATRewriteTables(List **wqueue) if (tab->newvals != NIL || tab->new_changeoids) { /* Build a temporary relation and copy data */ + Relation OldHeap; Oid OIDNewHeap; - char NewHeapName[NAMEDATALEN]; Oid NewTableSpace; - Relation OldHeap; - ObjectAddress object; OldHeap = heap_open(tab->relid, NoLock); @@ -2905,18 +2903,8 @@ ATRewriteTables(List **wqueue) heap_close(OldHeap, NoLock); - /* - * Create the new heap, using a temporary name in the same - * namespace as the existing table. NOTE: there is some risk of - * collision with user relnames. Working around this seems more - * trouble than it's worth; in particular, we can't create the new - * heap in a different namespace from the old, or we will have - * problems with the TEMP status of temp tables. - */ - snprintf(NewHeapName, sizeof(NewHeapName), - "pg_temp_%u", tab->relid); - - OIDNewHeap = make_new_heap(tab->relid, NewHeapName, NewTableSpace); + /* Create transient table that will receive the modified data */ + OIDNewHeap = make_new_heap(tab->relid, NewTableSpace); /* * Copy the heap data into the new table with the desired @@ -2929,30 +2917,14 @@ ATRewriteTables(List **wqueue) * Swap the physical files of the old and new heaps. Since we are * generating a new heap, we can use RecentXmin for the table's * new relfrozenxid because we rewrote all the tuples on - * ATRewriteTable, so no older Xid remains on the table. - */ - swap_relation_files(tab->relid, OIDNewHeap, RecentXmin); - - CommandCounterIncrement(); - - /* Destroy new heap with old filenode */ - object.classId = RelationRelationId; - object.objectId = OIDNewHeap; - object.objectSubId = 0; - - /* - * The new relation is local to our transaction and we know - * nothing depends on it, so DROP_RESTRICT should be OK. + * ATRewriteTable, so no older Xid remains in the table. Also, + * we never try to swap toast tables by content, since we have + * no interest in letting this code work on system catalogs. */ - performDeletion(&object, DROP_RESTRICT); - /* performDeletion does CommandCounterIncrement at end */ + swap_relation_files(tab->relid, OIDNewHeap, false, RecentXmin); - /* - * Rebuild each index on the relation (but not the toast table, - * which is all-new anyway). We do not need - * CommandCounterIncrement() because reindex_relation does it. - */ - reindex_relation(tab->relid, false); + /* Destroy the new heap, removing the old data along with it. */ + cleanup_heap_swap(tab->relid, OIDNewHeap, false); } else { |