diff options
Diffstat (limited to 'src/backend/executor/nodeIndexscan.c')
-rw-r--r-- | src/backend/executor/nodeIndexscan.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index 02f83667a45..84ee56beb0f 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.115 2006/07/14 14:52:19 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.116 2006/07/31 20:09:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -415,7 +415,7 @@ ExecEndIndexScan(IndexScanState *node) * close the index relation */ index_endscan(indexScanDesc); - index_close(indexRelationDesc); + index_close(indexRelationDesc, NoLock); /* * close the heap relation. @@ -517,8 +517,14 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags) /* * Open the index relation. + * + * If the parent table is one of the target relations of the query, then + * InitPlan already opened and write-locked the index, so we can avoid + * taking another lock here. Otherwise we need a normal reader's lock. */ - indexstate->iss_RelationDesc = index_open(node->indexid); + relistarget = ExecRelationIsTargetRelation(estate, node->scan.scanrelid); + indexstate->iss_RelationDesc = index_open(node->indexid, + relistarget ? NoLock : AccessShareLock); /* * Initialize index-specific scan state @@ -561,18 +567,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags) /* * Initialize scan descriptor. - * - * Note we acquire no locks here; the index machinery does its own locks - * and unlocks. (We rely on having a lock on the parent table to - * ensure the index won't go away!) Furthermore, if the parent table - * is one of the target relations of the query, then InitPlan already - * opened and write-locked the index, so we can tell the index machinery - * not to bother getting an extra lock. */ - relistarget = ExecRelationIsTargetRelation(estate, node->scan.scanrelid); indexstate->iss_ScanDesc = index_beginscan(currentRelation, indexstate->iss_RelationDesc, - !relistarget, estate->es_snapshot, indexstate->iss_NumScanKeys, indexstate->iss_ScanKeys); |