aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-06-15 16:29:05 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-06-15 16:29:05 +0000
commit906f27dd73124b7ab91ac2335bf42a95c51b9d7b (patch)
tree07acaca6bc737ccd79874a08508cbb2cbf8defc2 /src
parent71ff461a1832df80d55f02dd8a254c2083a1f479 (diff)
downloadpostgresql-906f27dd73124b7ab91ac2335bf42a95c51b9d7b.tar.gz
postgresql-906f27dd73124b7ab91ac2335bf42a95c51b9d7b.zip
Make DROP INDEX lock the parent table before locking the index. This behavior
is necessary to avoid deadlock against ordinary queries, but we'd broken it with recent changes that made the DROP machinery lock the index before arriving at index_drop. Per intermittent buildfarm failures.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablecmds.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b3d21875b25..639cd7296e2 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.257 2008/06/15 01:25:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.258 2008/06/15 16:29:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -676,6 +676,28 @@ RemoveRelations(DropStmt *drop)
continue;
}
+ /*
+ * In DROP INDEX, attempt to acquire lock on the parent table before
+ * locking the index. index_drop() will need this anyway, and since
+ * regular queries lock tables before their indexes, we risk deadlock
+ * if we do it the other way around. No error if we don't find a
+ * pg_index entry, though --- that most likely means it isn't an
+ * index, and we'll fail below.
+ */
+ if (relkind == RELKIND_INDEX)
+ {
+ tuple = SearchSysCache(INDEXRELID,
+ ObjectIdGetDatum(relOid),
+ 0, 0, 0);
+ if (HeapTupleIsValid(tuple))
+ {
+ Form_pg_index index = (Form_pg_index) GETSTRUCT(tuple);
+
+ LockRelationOid(index->indrelid, AccessExclusiveLock);
+ ReleaseSysCache(tuple);
+ }
+ }
+
/* Get the lock before trying to fetch the syscache entry */
LockRelationOid(relOid, AccessExclusiveLock);