summaryrefslogtreecommitdiff
path: root/src/backend/catalog/toasting.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-07-25 22:16:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-07-25 22:16:18 +0000
commit82eed4dba254b8fda71d429b29d222ffb4e93fca (patch)
treeeb84bdb8b70e931a08c23c07bc5c83d305bf19b3 /src/backend/catalog/toasting.c
parentfdb5b69e9c8f7186fe43c21580ac2ba45db1740f (diff)
downloadpostgresql-82eed4dba254b8fda71d429b29d222ffb4e93fca.tar.gz
Arrange to put TOAST tables belonging to temporary tables into special schemas
named pg_toast_temp_nnn, alongside the pg_temp_nnn schemas used for the temp tables themselves. This allows low-level code such as the relcache to recognize that these tables are indeed temporary, which enables various optimizations such as not WAL-logging changes and using local rather than shared buffers for access. Aside from obvious performance benefits, this provides a solution to bug #3483, in which other backends unexpectedly held open file references to temporary tables. The scheme preserves the property that TOAST tables are not in any schema that's normally in the search path, so they don't conflict with user table names. initdb forced because of changes in system view definitions.
Diffstat (limited to 'src/backend/catalog/toasting.c')
-rw-r--r--src/backend/catalog/toasting.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index 463f038c0f..2fe44f59f8 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.6 2007/04/06 04:21:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.7 2007/07/25 22:16:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,6 +21,7 @@
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/indexing.h"
+#include "catalog/namespace.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_type.h"
@@ -108,6 +109,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid)
Relation class_rel;
Oid toast_relid;
Oid toast_idxid;
+ Oid namespaceid;
char toast_relname[NAMEDATALEN];
char toast_idxname[NAMEDATALEN];
IndexInfo *indexInfo;
@@ -173,16 +175,20 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid)
tupdesc->attrs[2]->attstorage = 'p';
/*
- * Note: the toast relation is placed in the regular pg_toast namespace
- * even if its master relation is a temp table. There cannot be any
- * naming collision, and the toast rel will be destroyed when its master
- * is, so there's no need to handle the toast rel as temp.
- *
+ * Toast tables for regular relations go in pg_toast; those for temp
+ * relations go into the per-backend temp-toast-table namespace.
+ */
+ if (rel->rd_istemp)
+ namespaceid = GetTempToastNamespace();
+ else
+ namespaceid = PG_TOAST_NAMESPACE;
+
+ /*
* XXX would it make sense to apply the master's reloptions to the toast
- * table?
+ * table? Or maybe some toast-specific reloptions?
*/
toast_relid = heap_create_with_catalog(toast_relname,
- PG_TOAST_NAMESPACE,
+ namespaceid,
rel->rd_rel->reltablespace,
toastOid,
rel->rd_rel->relowner,