aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-02-10 03:42:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-02-10 03:42:45 +0000
commit58f337a3435cd6ac46dfca4ce1a44b837080745e (patch)
tree03e4a309f7ada6914474c02fd9b53df7ab1da975 /src/backend/commands
parent87bd95638552b8fc1f5f787ce5b862bb6fc2eb80 (diff)
downloadpostgresql-58f337a3435cd6ac46dfca4ce1a44b837080745e.tar.gz
postgresql-58f337a3435cd6ac46dfca4ce1a44b837080745e.zip
Centralize implementation of delay code by creating a pg_usleep()
subroutine in src/port/pgsleep.c. Remove platform dependencies from miscadmin.h and put them in port.h where they belong. Extend recent vacuum cost-based-delay patch to apply to VACUUM FULL, ANALYZE, and non-btree index vacuuming. By the way, where is the documentation for the cost-based-delay patch?
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c10
-rw-r--r--src/backend/commands/vacuum.c53
-rw-r--r--src/backend/commands/vacuumlazy.c72
3 files changed, 56 insertions, 79 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 09269d9187c..0c713b3ca67 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.66 2004/01/06 18:07:31 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.67 2004/02/10 03:42:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -529,7 +529,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
rows[numrows++] = heap_copytuple(tuple);
if (numrows >= targrows)
break;
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
}
heap_endscan(scan);
@@ -604,7 +604,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
OffsetNumber targoffset,
maxoffset;
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
t = select_next_random_record(t, targrows, &rstate);
/* Try to read the t'th record in the table */
@@ -912,7 +912,7 @@ compute_minimal_stats(VacAttrStats *stats,
int firstcount1,
j;
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
value = heap_getattr(tuple, stats->attnum, tupDesc, &isnull);
@@ -1214,7 +1214,7 @@ compute_scalar_stats(VacAttrStats *stats,
Datum value;
bool isnull;
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
value = heap_getattr(tuple, stats->attnum, tupDesc, &isnull);
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 29a2df1ef1d..a0dd09df215 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.272 2004/02/10 01:55:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.273 2004/02/10 03:42:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -181,6 +181,10 @@ vacuum(VacuumStmt *vacstmt)
if (vacstmt->vacuum)
PreventTransactionChain((void *) vacstmt, stmttype);
+ /* Turn vacuum cost accounting on or off */
+ VacuumCostActive = (VacuumCostNaptime > 0);
+ VacuumCostBalance = 0;
+
/*
* Send info about dead objects to the statistics collector
*/
@@ -374,6 +378,9 @@ vacuum(VacuumStmt *vacstmt)
if (anl_context)
MemoryContextDelete(anl_context);
+
+ /* Turn off vacuum cost accounting */
+ VacuumCostActive = false;
}
/*
@@ -1082,7 +1089,7 @@ scan_heap(VRelStats *vacrelstats, Relation onerel,
bool do_reap,
do_frag;
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
buf = ReadBuffer(onerel, blkno);
page = BufferGetPage(buf);
@@ -1528,7 +1535,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
blkno > last_move_dest_block;
blkno--)
{
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
/*
* Forget fraged_pages pages at or after this one; they're no
@@ -2311,7 +2318,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
i < vacuumed_pages;
i++, curpage++)
{
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
+
Assert((*curpage)->blkno < blkno);
if ((*curpage)->offsets_used == 0)
{
@@ -2342,7 +2350,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
i < num_fraged_pages;
i++, curpage++)
{
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
+
Assert((*curpage)->blkno < blkno);
if ((*curpage)->blkno > last_move_dest_block)
break; /* no need to scan any further */
@@ -2553,7 +2562,8 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
for (i = 0, vacpage = vacuum_pages->pagedesc; i < nblocks; i++, vacpage++)
{
- CHECK_FOR_INTERRUPTS();
+ vacuum_delay_point();
+
if ((*vacpage)->offsets_free > 0)
{
buf = ReadBuffer(onerel, (*vacpage)->blkno);
@@ -3164,3 +3174,34 @@ vac_show_rusage(VacRUsage *ru0)
return result;
}
+
+/*
+ * vacuum_delay_point --- check for interrupts and cost-based delay.
+ *
+ * This should be called in each major loop of VACUUM processing,
+ * typically once per page processed.
+ */
+void
+vacuum_delay_point(void)
+{
+ /* Always check for interrupts */
+ CHECK_FOR_INTERRUPTS();
+
+ /* Nap if appropriate */
+ if (VacuumCostActive && !InterruptPending &&
+ VacuumCostBalance >= VacuumCostLimit)
+ {
+ int msec;
+
+ msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
+ if (msec > VacuumCostNaptime * 4)
+ msec = VacuumCostNaptime * 4;
+
+ pg_usleep(msec * 1000L);
+
+ VacuumCostBalance = 0;
+
+ /* Might have gotten an interrupt while sleeping */
+ CHECK_FOR_INTERRUPTS();
+ }
+}
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index 17f91efef70..2d85b652937 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -31,7 +31,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.36 2004/02/10 01:55:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.37 2004/02/10 03:42:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -148,10 +148,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
vac_open_indexes(onerel, &nindexes, &Irel);
hasindex = (nindexes > 0);
- /* Turn vacuum cost accounting on or off */
- VacuumCostActive = (VacuumCostNaptime > 0);
- VacuumCostBalance = 0;
-
/* Do the vacuuming */
lazy_scan_heap(onerel, vacrelstats, Irel, nindexes);
@@ -172,9 +168,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
/* Update shared free space map with final free space info */
lazy_update_fsm(onerel, vacrelstats);
- /* Turn off vacuum cost accounting */
- VacuumCostActive = false;
-
/* Update statistics in pg_class */
vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages,
vacrelstats->rel_tuples, hasindex);
@@ -233,26 +226,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
hastup;
int prev_dead_count;
- CHECK_FOR_INTERRUPTS();
-
- /*
- * Do the napping in a cost based vacuum.
- */
- if (VacuumCostActive && !InterruptPending &&
- VacuumCostBalance >= VacuumCostLimit)
- {
- int msec;
-
- msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
- if (msec < VacuumCostNaptime * 4)
- PG_MSLEEP(msec);
- else
- PG_MSLEEP(VacuumCostNaptime * 4);
-
- VacuumCostBalance = 0;
-
- CHECK_FOR_INTERRUPTS();
- }
+ vacuum_delay_point();
/*
* If we are close to overrunning the available space for
@@ -493,26 +467,7 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats)
Buffer buf;
Page page;
- CHECK_FOR_INTERRUPTS();
-
- /*
- * Do the napping in a cost based vacuum.
- */
- if (VacuumCostActive && !InterruptPending &&
- VacuumCostBalance >= VacuumCostLimit)
- {
- int msec;
-
- msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
- if (msec < VacuumCostNaptime * 4)
- PG_MSLEEP(msec);
- else
- PG_MSLEEP(VacuumCostNaptime * 4);
-
- VacuumCostBalance = 0;
-
- CHECK_FOR_INTERRUPTS();
- }
+ vacuum_delay_point();
tblk = ItemPointerGetBlockNumber(&vacrelstats->dead_tuples[tupindex]);
buf = ReadBuffer(onerel, tblk);
@@ -845,26 +800,7 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
tupgone,
hastup;
- CHECK_FOR_INTERRUPTS();
-
- /*
- * Do the napping in a cost based vacuum.
- */
- if (VacuumCostActive && !InterruptPending &&
- VacuumCostBalance >= VacuumCostLimit)
- {
- int msec;
-
- msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
- if (msec < VacuumCostNaptime * 4)
- PG_MSLEEP(msec);
- else
- PG_MSLEEP(VacuumCostNaptime * 4);
-
- VacuumCostBalance = 0;
-
- CHECK_FOR_INTERRUPTS();
- }
+ vacuum_delay_point();
blkno--;