aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/heap/tuptoaster.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-08-12 01:36:05 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-08-12 01:36:05 +0000
commit721e53785d837d48dc33dd68aa77c42ece7c9afb (patch)
tree59c7bf34cada497f50c61072826d6fa0de080b57 /src/backend/access/heap/tuptoaster.c
parent9e4a2de8448997924e74ace8dfd9ccd05acb2d08 (diff)
downloadpostgresql-721e53785d837d48dc33dd68aa77c42ece7c9afb.tar.gz
postgresql-721e53785d837d48dc33dd68aa77c42ece7c9afb.zip
Solve the problem of OID collisions by probing for duplicate OIDs
whenever we generate a new OID. This prevents occasional duplicate-OID errors that can otherwise occur once the OID counter has wrapped around. Duplicate relfilenode values are also checked for when creating new physical files. Per my recent proposal.
Diffstat (limited to 'src/backend/access/heap/tuptoaster.c')
-rw-r--r--src/backend/access/heap/tuptoaster.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c
index 5359f24fce2..02da8446cd0 100644
--- a/src/backend/access/heap/tuptoaster.c
+++ b/src/backend/access/heap/tuptoaster.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.51 2005/08/02 16:11:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.52 2005/08/12 01:35:54 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -1007,6 +1007,15 @@ toast_save_datum(Relation rel, Datum value)
int32 data_todo;
/*
+ * Open the toast relation and its index. We can use the index to
+ * check uniqueness of the OID we assign to the toasted item, even
+ * though it has additional columns besides OID.
+ */
+ toastrel = heap_open(rel->rd_rel->reltoastrelid, RowExclusiveLock);
+ toasttupDesc = toastrel->rd_att;
+ toastidx = index_open(toastrel->rd_rel->reltoastidxid);
+
+ /*
* Create the varattrib reference
*/
result = (varattrib *) palloc(sizeof(varattrib));
@@ -1023,7 +1032,8 @@ toast_save_datum(Relation rel, Datum value)
result->va_content.va_external.va_extsize =
VARATT_SIZE(value) - VARHDRSZ;
- result->va_content.va_external.va_valueid = newoid();
+ result->va_content.va_external.va_valueid =
+ GetNewOidWithIndex(toastrel, toastidx);
result->va_content.va_external.va_toastrelid =
rel->rd_rel->reltoastrelid;
@@ -1043,12 +1053,9 @@ toast_save_datum(Relation rel, Datum value)
data_todo = VARATT_SIZE(value) - VARHDRSZ;
/*
- * Open the toast relation. We must explicitly lock the toast index
- * because we aren't using an index scan here.
+ * We must explicitly lock the toast index because we aren't using an
+ * index scan here.
*/
- toastrel = heap_open(rel->rd_rel->reltoastrelid, RowExclusiveLock);
- toasttupDesc = toastrel->rd_att;
- toastidx = index_open(toastrel->rd_rel->reltoastidxid);
LockRelation(toastidx, RowExclusiveLock);
/*