7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.56 1999/10/11 06:28:27 inoue Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.57 1999/10/30 23:10:21 tgl Exp $
11
11
*
12
12
*
13
13
* INTERFACE ROUTINES
@@ -102,7 +102,16 @@ initscan(HeapScanDesc scan,
102
102
unsigned nkeys,
103
103
ScanKey key)
104
104
{
105
- if (!RelationGetNumberOfBlocks(relation))
105
+ /* ----------------
106
+ *Make sure we have up-to-date idea of number of blocks in relation.
107
+ *It is sufficient to do this once at scan start, since any tuples
108
+ *added while the scan is in progress will be invisible to my
109
+ *transaction anyway...
110
+ * ----------------
111
+ */
112
+ relation->rd_nblocks = RelationGetNumberOfBlocks(relation);
113
+
114
+ if (relation->rd_nblocks == 0)
106
115
{
107
116
/* ----------------
108
117
*relation is empty
@@ -652,11 +661,12 @@ heap_beginscan(Relation relation,
652
661
*/
653
662
scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
654
663
655
- relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation);
656
664
scan->rs_rd = relation;
665
+ scan->rs_atend = atend;
666
+ scan->rs_snapshot = snapshot;
667
+ scan->rs_nkeys = (short) nkeys;
657
668
658
669
if (nkeys)
659
-
660
670
/*
661
671
* we do this here instead of in initscan() because heap_rescan
662
672
* also calls initscan() and we don't want to allocate memory
@@ -668,10 +678,6 @@ heap_beginscan(Relation relation,
668
678
669
679
initscan(scan, relation, atend, nkeys, key);
670
680
671
- scan->rs_atend = atend;
672
- scan->rs_snapshot = snapshot;
673
- scan->rs_nkeys = (short) nkeys;
674
-
675
681
return scan;
676
682
}
677
683
@@ -703,8 +709,8 @@ heap_rescan(HeapScanDesc scan,
703
709
*reinitialize scan descriptor
704
710
* ----------------
705
711
*/
706
- initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
707
712
scan->rs_atend = (bool) scanFromEnd;
713
+ initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
708
714
}
709
715
710
716
/* ----------------
@@ -1096,7 +1102,7 @@ heap_get_latest_tid(Relation relation,
1096
1102
Snapshot snapshot,
1097
1103
ItemPointer tid)
1098
1104
{
1099
- ItemIdlp;
1105
+ ItemIdlp = NULL ;
1100
1106
Bufferbuffer;
1101
1107
PageHeaderdp;
1102
1108
OffsetNumberoffnum;