aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c19
-rw-r--r--src/backend/commands/sequence.c6
-rw-r--r--src/backend/commands/vacuum.c14
-rw-r--r--src/backend/commands/vacuumlazy.c8
4 files changed, 16 insertions, 31 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index bd82a96b650..d388f521f18 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.70 2004/02/15 21:01:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.71 2004/05/08 19:09:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -388,7 +388,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
/*
* If we are running a standalone ANALYZE, update pages/tuples stats
- * in pg_class. We have the accurate page count from heap_beginscan,
+ * in pg_class. We know the accurate page count from the smgr,
* but only an approximate number of tuples; therefore, if we are part
* of VACUUM ANALYZE do *not* overwrite the accurate count already
* inserted by VACUUM. The same consideration applies to indexes.
@@ -396,7 +396,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
if (!vacstmt->vacuum)
{
vac_update_relstats(RelationGetRelid(onerel),
- onerel->rd_nblocks,
+ RelationGetNumberOfBlocks(onerel),
totalrows,
hasindex);
for (ind = 0; ind < nindexes; ind++)
@@ -657,6 +657,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
{
int numrows = 0;
HeapScanDesc scan;
+ BlockNumber totalblocks;
HeapTuple tuple;
ItemPointer lasttuple;
BlockNumber lastblock,
@@ -673,6 +674,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
* Do a simple linear scan until we reach the target number of rows.
*/
scan = heap_beginscan(onerel, SnapshotNow, 0, NULL);
+ totalblocks = scan->rs_nblocks; /* grab current relation size */
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
rows[numrows++] = heap_copytuple(tuple);
@@ -693,7 +695,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
ereport(elevel,
(errmsg("\"%s\": %u pages, %d rows sampled, %.0f estimated total rows",
RelationGetRelationName(onerel),
- onerel->rd_nblocks, numrows, *totalrows)));
+ totalblocks, numrows, *totalrows)));
return numrows;
}
@@ -772,10 +774,9 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
pageloop:;
/*
- * Have we fallen off the end of the relation? (We rely on
- * heap_beginscan to have updated rd_nblocks.)
+ * Have we fallen off the end of the relation?
*/
- if (targblock >= onerel->rd_nblocks)
+ if (targblock >= totalblocks)
break;
/*
@@ -841,7 +842,7 @@ pageloop:;
/*
* Estimate total number of valid rows in relation.
*/
- *totalrows = floor((double) onerel->rd_nblocks * tuplesperpage + 0.5);
+ *totalrows = floor((double) totalblocks * tuplesperpage + 0.5);
/*
* Emit some interesting relation info
@@ -849,7 +850,7 @@ pageloop:;
ereport(elevel,
(errmsg("\"%s\": %u pages, %d rows sampled, %.0f estimated total rows",
RelationGetRelationName(onerel),
- onerel->rd_nblocks, numrows, *totalrows)));
+ totalblocks, numrows, *totalrows)));
return numrows;
}
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index de4499124d5..0ff1b386b5b 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.109 2004/04/06 16:39:30 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.110 2004/05/08 19:09:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -822,10 +822,6 @@ read_info(SeqTable elm, Relation rel, Buffer *buf)
sequence_magic *sm;
Form_pg_sequence seq;
- if (rel->rd_nblocks > 1)
- elog(ERROR, "invalid number of blocks in sequence \"%s\"",
- RelationGetRelationName(rel));
-
*buf = ReadBuffer(rel, 0);
if (!BufferIsValid(*buf))
elog(ERROR, "ReadBuffer failed");
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 760c10bcc80..342c87db574 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.274 2004/02/12 05:39:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.275 2004/05/08 19:09:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2522,11 +2522,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
/* truncate relation, if needed */
if (blkno < nblocks)
{
- if (onerel->rd_smgr == NULL)
- onerel->rd_smgr = smgropen(onerel->rd_node);
- blkno = smgrtruncate(onerel->rd_smgr, blkno);
- onerel->rd_nblocks = blkno; /* update relcache immediately */
- onerel->rd_targblock = InvalidBlockNumber;
+ RelationTruncate(onerel, blkno);
vacrelstats->rel_pages = blkno; /* set new number of blocks */
}
@@ -2594,11 +2590,7 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
(errmsg("\"%s\": truncated %u to %u pages",
RelationGetRelationName(onerel),
vacrelstats->rel_pages, relblocks)));
- if (onerel->rd_smgr == NULL)
- onerel->rd_smgr = smgropen(onerel->rd_node);
- relblocks = smgrtruncate(onerel->rd_smgr, relblocks);
- onerel->rd_nblocks = relblocks; /* update relcache immediately */
- onerel->rd_targblock = InvalidBlockNumber;
+ RelationTruncate(onerel, relblocks);
vacrelstats->rel_pages = relblocks; /* set new number of
* blocks */
}
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index 46920c0009b..af1b646be46 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.39 2004/04/25 23:50:54 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.40 2004/05/08 19:09:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -738,11 +738,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
/*
* Do the physical truncation.
*/
- if (onerel->rd_smgr == NULL)
- onerel->rd_smgr = smgropen(onerel->rd_node);
- new_rel_pages = smgrtruncate(onerel->rd_smgr, new_rel_pages);
- onerel->rd_nblocks = new_rel_pages; /* update relcache immediately */
- onerel->rd_targblock = InvalidBlockNumber;
+ RelationTruncate(onerel, new_rel_pages);
vacrelstats->rel_pages = new_rel_pages; /* save new number of
* blocks */