88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.70 2004/02/15 21:01:39 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.71 2004/05/08 19:09:24 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -388,15 +388,15 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
388388
389389 /*
390390 * If we are running a standalone ANALYZE, update pages/tuples stats
391- * in pg_class. We have the accurate page count from heap_beginscan ,
391+ * in pg_class. We know the accurate page count from the smgr ,
392392 * but only an approximate number of tuples; therefore, if we are part
393393 * of VACUUM ANALYZE do *not* overwrite the accurate count already
394394 * inserted by VACUUM. The same consideration applies to indexes.
395395 */
396396 if (!vacstmt -> vacuum )
397397 {
398398 vac_update_relstats (RelationGetRelid (onerel ),
399- onerel -> rd_nblocks ,
399+ RelationGetNumberOfBlocks ( onerel ) ,
400400 totalrows ,
401401 hasindex );
402402 for (ind = 0 ; ind < nindexes ; ind ++ )
@@ -657,6 +657,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
657657{
658658 int numrows = 0 ;
659659 HeapScanDesc scan ;
660+ BlockNumber totalblocks ;
660661 HeapTuple tuple ;
661662 ItemPointer lasttuple ;
662663 BlockNumber lastblock ,
@@ -673,6 +674,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
673674 * Do a simple linear scan until we reach the target number of rows.
674675 */
675676 scan = heap_beginscan (onerel , SnapshotNow , 0 , NULL );
677+ totalblocks = scan -> rs_nblocks ; /* grab current relation size */
676678 while ((tuple = heap_getnext (scan , ForwardScanDirection )) != NULL )
677679 {
678680 rows [numrows ++ ] = heap_copytuple (tuple );
@@ -693,7 +695,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
693695 ereport (elevel ,
694696 (errmsg ("\"%s\": %u pages, %d rows sampled, %.0f estimated total rows" ,
695697 RelationGetRelationName (onerel ),
696- onerel -> rd_nblocks , numrows , * totalrows )));
698+ totalblocks , numrows , * totalrows )));
697699
698700 return numrows ;
699701 }
@@ -772,10 +774,9 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
772774pageloop :;
773775
774776 /*
775- * Have we fallen off the end of the relation? (We rely on
776- * heap_beginscan to have updated rd_nblocks.)
777+ * Have we fallen off the end of the relation?
777778 */
778- if (targblock >= onerel -> rd_nblocks )
779+ if (targblock >= totalblocks )
779780 break ;
780781
781782 /*
@@ -841,15 +842,15 @@ pageloop:;
841842 /*
842843 * Estimate total number of valid rows in relation.
843844 */
844- * totalrows = floor ((double ) onerel -> rd_nblocks * tuplesperpage + 0.5 );
845+ * totalrows = floor ((double ) totalblocks * tuplesperpage + 0.5 );
845846
846847 /*
847848 * Emit some interesting relation info
848849 */
849850 ereport (elevel ,
850851 (errmsg ("\"%s\": %u pages, %d rows sampled, %.0f estimated total rows" ,
851852 RelationGetRelationName (onerel ),
852- onerel -> rd_nblocks , numrows , * totalrows )));
853+ totalblocks , numrows , * totalrows )));
853854
854855 return numrows ;
855856}
0 commit comments