Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9727c58

Browse files
committed
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.
1 parent fdac8cf commit 9727c58

File tree

6 files changed

+328
-212
lines changed

6 files changed

+328
-212
lines changed

src/backend/access/heap/tuptoaster.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.96 2010/01/02 16:57:35 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.97 2010/02/04 00:09:13 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1185,10 +1185,25 @@ toast_save_datum(Relation rel, Datum value, int options)
11851185
toast_pointer.va_extsize = data_todo;
11861186
}
11871187

1188+
/*
1189+
* Insert the correct table OID into the result TOAST pointer.
1190+
*
1191+
* Normally this is the actual OID of the target toast table, but during
1192+
* table-rewriting operations such as CLUSTER, we have to insert the OID
1193+
* of the table's real permanent toast table instead. rd_toastoid is
1194+
* set if we have to substitute such an OID.
1195+
*/
1196+
if (OidIsValid(rel->rd_toastoid))
1197+
toast_pointer.va_toastrelid = rel->rd_toastoid;
1198+
else
1199+
toast_pointer.va_toastrelid = RelationGetRelid(toastrel);
1200+
1201+
/*
1202+
* Choose an unused OID within the toast table for this toast value.
1203+
*/
11881204
toast_pointer.va_valueid = GetNewOidWithIndex(toastrel,
11891205
RelationGetRelid(toastidx),
11901206
(AttrNumber) 1);
1191-
toast_pointer.va_toastrelid = rel->rd_rel->reltoastrelid;
11921207

11931208
/*
11941209
* Initialize constant parts of the tuple data

0 commit comments

Comments
 (0)