3131 *
3232 *
3333 * IDENTIFICATION
34- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.47 2004/10/15 22:39:56 tgl Exp $
34+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.48 2004/10/25 15:42:02 tgl Exp $
3535 *
3636 *-------------------------------------------------------------------------
3737 */
@@ -554,9 +554,12 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
554554vac_init_rusage (& ru0 );
555555
556556/*
557- * If index is unsafe for concurrent access, must lock it.
557+ * Acquire appropriate type of lock on index: must be exclusive if
558+ * index AM isn't concurrent-safe.
558559 */
559- if (!indrel -> rd_am -> amconcurrent )
560+ if (indrel -> rd_am -> amconcurrent )
561+ LockRelation (indrel ,RowExclusiveLock );
562+ else
560563LockRelation (indrel ,AccessExclusiveLock );
561564
562565/*
@@ -576,7 +579,9 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
576579/*
577580 * Release lock acquired above.
578581 */
579- if (!indrel -> rd_am -> amconcurrent )
582+ if (indrel -> rd_am -> amconcurrent )
583+ UnlockRelation (indrel ,RowExclusiveLock );
584+ else
580585UnlockRelation (indrel ,AccessExclusiveLock );
581586
582587if (!stats )
@@ -619,9 +624,12 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats)
619624vac_init_rusage (& ru0 );
620625
621626/*
622- * If index is unsafe for concurrent access, must lock it.
627+ * Acquire appropriate type of lock on index: must be exclusive if
628+ * index AM isn't concurrent-safe.
623629 */
624- if (!indrel -> rd_am -> amconcurrent )
630+ if (indrel -> rd_am -> amconcurrent )
631+ LockRelation (indrel ,RowExclusiveLock );
632+ else
625633LockRelation (indrel ,AccessExclusiveLock );
626634
627635/* Do bulk deletion */
@@ -636,7 +644,9 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats)
636644/*
637645 * Release lock acquired above.
638646 */
639- if (!indrel -> rd_am -> amconcurrent )
647+ if (indrel -> rd_am -> amconcurrent )
648+ UnlockRelation (indrel ,RowExclusiveLock );
649+ else
640650UnlockRelation (indrel ,AccessExclusiveLock );
641651
642652if (!stats )