aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-30 23:21:26 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-30 23:21:26 +0000
commitd2af5f8a3e89f02dd54949fa42e2dcd31ddcd5c7 (patch)
tree122463e70e53c0fd7ae418dc8eb9057ffedae130 /src/backend/access
parentd6748843069f7dd4205cd85b60977b5414647635 (diff)
downloadpostgresql-d2af5f8a3e89f02dd54949fa42e2dcd31ddcd5c7.tar.gz
postgresql-d2af5f8a3e89f02dd54949fa42e2dcd31ddcd5c7.zip
Adjust index locking rules as per my proposal of earlier today. You
now are supposed to take some kind of lock on an index whenever you are going to access the index contents, rather than relying only on a lock on the parent table.
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/heap/tuptoaster.c7
-rw-r--r--src/backend/access/index/indexam.c15
2 files changed, 15 insertions, 7 deletions
diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c
index fe389991415..0aa590a99ea 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.45 2004/08/29 05:06:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.46 2004/09/30 23:21:06 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -1007,11 +1007,13 @@ toast_save_datum(Relation rel, Datum value)
data_todo = VARATT_SIZE(value) - VARHDRSZ;
/*
- * Open the toast relation
+ * Open the toast relation. 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);
/*
* Split up the item into chunks
@@ -1065,6 +1067,7 @@ toast_save_datum(Relation rel, Datum value)
/*
* Done - close toast relation and return the reference
*/
+ UnlockRelation(toastidx, RowExclusiveLock);
index_close(toastidx);
heap_close(toastrel, RowExclusiveLock);
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 949deb27a28..7c698fb48a2 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.74 2004/08/29 04:12:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.75 2004/09/30 23:21:14 tgl Exp $
*
* INTERFACE ROUTINES
* index_open - open an index relation by relation OID
@@ -112,10 +112,15 @@
/* ----------------
* index_open - open an index relation by relation OID
*
- * Note: we acquire no lock on the index. An AccessShareLock is
- * acquired by index_beginscan (and released by index_endscan).
- * Generally, the caller should already hold some type of lock on
- * the parent relation to ensure that the index doesn't disappear.
+ * Note: we acquire no lock on the index. A lock is not needed when
+ * simply examining the index reldesc; the index's schema information
+ * is considered to be protected by the lock that the caller had better
+ * be holding on the parent relation. Some type of lock should be
+ * obtained on the index before physically accessing it, however.
+ * This is handled automatically for most uses by index_beginscan
+ * and index_endscan for scan cases, or by ExecOpenIndices and
+ * ExecCloseIndices for update cases. Other callers will need to
+ * obtain their own locks.
*
* This is a convenience routine adapted for indexscan use.
* Some callers may prefer to use relation_open directly.