3838 *
3939 *
4040 * IDENTIFICATION
41- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.103 2008/01/01 19:45:49 momjian Exp $
41+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.104 2008/03/10 02:04:09 tgl Exp $
4242 *
4343 *-------------------------------------------------------------------------
4444 */
@@ -98,7 +98,7 @@ typedef struct LVRelStats
9898bool fs_is_heap ;/* are we using heap organization? */
9999int num_free_pages ;/* current # of entries */
100100int max_free_pages ;/* # slots allocated in array */
101- PageFreeSpaceInfo * free_pages ;/* array or heap of blkno/avail */
101+ FSMPageData * free_pages ;/* array or heap of blkno/avail */
102102BlockNumber tot_free_pages ;/* total pages with >= threshold space */
103103int num_index_scans ;
104104}LVRelStats ;
@@ -813,7 +813,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
813813{
814814BlockNumber old_rel_pages = vacrelstats -> rel_pages ;
815815BlockNumber new_rel_pages ;
816- PageFreeSpaceInfo * pageSpaces ;
816+ FSMPageData * pageSpaces ;
817817int n ;
818818int i ,
819819j ;
@@ -881,7 +881,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
881881j = 0 ;
882882for (i = 0 ;i < n ;i ++ )
883883{
884- if (pageSpaces [i ]. blkno < new_rel_pages )
884+ if (FSMPageGetPageNum ( & pageSpaces [i ]) < new_rel_pages )
885885{
886886pageSpaces [j ]= pageSpaces [i ];
887887j ++ ;
@@ -1028,16 +1028,16 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
10281028palloc (maxtuples * sizeof (ItemPointerData ));
10291029
10301030maxpages = MaxFSMPages ;
1031- maxpages = Min (maxpages ,MaxAllocSize /sizeof (PageFreeSpaceInfo ));
1031+ maxpages = Min (maxpages ,MaxAllocSize /sizeof (FSMPageData ));
10321032/* No need to allocate more pages than the relation has blocks */
10331033if (relblocks < (BlockNumber )maxpages )
10341034maxpages = (int )relblocks ;
10351035
10361036vacrelstats -> fs_is_heap = false;
10371037vacrelstats -> num_free_pages = 0 ;
10381038vacrelstats -> max_free_pages = maxpages ;
1039- vacrelstats -> free_pages = (PageFreeSpaceInfo * )
1040- palloc (maxpages * sizeof (PageFreeSpaceInfo ));
1039+ vacrelstats -> free_pages = (FSMPageData * )
1040+ palloc (maxpages * sizeof (FSMPageData ));
10411041vacrelstats -> tot_free_pages = 0 ;
10421042}
10431043
@@ -1068,7 +1068,7 @@ lazy_record_free_space(LVRelStats *vacrelstats,
10681068BlockNumber page ,
10691069Size avail )
10701070{
1071- PageFreeSpaceInfo * pageSpaces ;
1071+ FSMPageData * pageSpaces ;
10721072int n ;
10731073
10741074/*
@@ -1098,8 +1098,8 @@ lazy_record_free_space(LVRelStats *vacrelstats,
10981098/* If we haven't filled the array yet, just keep adding entries */
10991099if (vacrelstats -> num_free_pages < n )
11001100{
1101- pageSpaces [vacrelstats -> num_free_pages ]. blkno = page ;
1102- pageSpaces [vacrelstats -> num_free_pages ]. avail = avail ;
1101+ FSMPageSetPageNum ( & pageSpaces [vacrelstats -> num_free_pages ], page ) ;
1102+ FSMPageSetSpace ( & pageSpaces [vacrelstats -> num_free_pages ], avail ) ;
11031103vacrelstats -> num_free_pages ++ ;
11041104return ;
11051105}
@@ -1127,8 +1127,8 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11271127
11281128while (-- l >=0 )
11291129{
1130- BlockNumber R = pageSpaces [l ]. blkno ;
1131- Size K = pageSpaces [l ]. avail ;
1130+ BlockNumber R = FSMPageGetPageNum ( & pageSpaces [l ]) ;
1131+ Size K = FSMPageGetSpace ( & pageSpaces [l ]) ;
11321132int i ;/* i is where the "hole" is */
11331133
11341134i = l ;
@@ -1138,22 +1138,22 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11381138
11391139if (j >=n )
11401140break ;
1141- if (j + 1 < n && pageSpaces [j ]. avail > pageSpaces [j + 1 ]. avail )
1141+ if (j + 1 < n && FSMPageGetSpace ( & pageSpaces [j ]) > FSMPageGetSpace ( & pageSpaces [j + 1 ]) )
11421142j ++ ;
1143- if (K <=pageSpaces [j ]. avail )
1143+ if (K <=FSMPageGetSpace ( & pageSpaces [j ]) )
11441144break ;
11451145pageSpaces [i ]= pageSpaces [j ];
11461146i = j ;
11471147}
1148- pageSpaces [i ]. blkno = R ;
1149- pageSpaces [i ]. avail = K ;
1148+ FSMPageSetPageNum ( & pageSpaces [i ], R ) ;
1149+ FSMPageSetSpace ( & pageSpaces [i ], K ) ;
11501150}
11511151
11521152vacrelstats -> fs_is_heap = true;
11531153}
11541154
11551155/* If new page has more than zero'th entry, insert it into heap */
1156- if (avail > pageSpaces [0 ]. avail )
1156+ if (avail > FSMPageGetSpace ( & pageSpaces [0 ]) )
11571157{
11581158/*
11591159 * Notionally, we replace the zero'th entry with the new data, and
@@ -1169,15 +1169,15 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11691169
11701170if (j >=n )
11711171break ;
1172- if (j + 1 < n && pageSpaces [j ]. avail > pageSpaces [j + 1 ]. avail )
1172+ if (j + 1 < n && FSMPageGetSpace ( & pageSpaces [j ]) > FSMPageGetSpace ( & pageSpaces [j + 1 ]) )
11731173j ++ ;
1174- if (avail <=pageSpaces [j ]. avail )
1174+ if (avail <=FSMPageGetSpace ( & pageSpaces [j ]) )
11751175break ;
11761176pageSpaces [i ]= pageSpaces [j ];
11771177i = j ;
11781178}
1179- pageSpaces [i ]. blkno = page ;
1180- pageSpaces [i ]. avail = avail ;
1179+ FSMPageSetPageNum ( & pageSpaces [i ], page ) ;
1180+ FSMPageSetSpace ( & pageSpaces [i ], avail ) ;
11811181}
11821182}
11831183
@@ -1210,14 +1210,14 @@ lazy_tid_reaped(ItemPointer itemptr, void *state)
12101210static void
12111211lazy_update_fsm (Relation onerel ,LVRelStats * vacrelstats )
12121212{
1213- PageFreeSpaceInfo * pageSpaces = vacrelstats -> free_pages ;
1213+ FSMPageData * pageSpaces = vacrelstats -> free_pages ;
12141214int nPages = vacrelstats -> num_free_pages ;
12151215
12161216/*
12171217 * Sort data into order, as required by RecordRelationFreeSpace.
12181218 */
12191219if (nPages > 1 )
1220- qsort (pageSpaces ,nPages ,sizeof (PageFreeSpaceInfo ),
1220+ qsort (pageSpaces ,nPages ,sizeof (FSMPageData ),
12211221vac_cmp_page_spaces );
12221222
12231223RecordRelationFreeSpace (& onerel -> rd_node ,vacrelstats -> tot_free_pages ,
@@ -1257,12 +1257,14 @@ vac_cmp_itemptr(const void *left, const void *right)
12571257static int
12581258vac_cmp_page_spaces (const void * left ,const void * right )
12591259{
1260- PageFreeSpaceInfo * linfo = (PageFreeSpaceInfo * )left ;
1261- PageFreeSpaceInfo * rinfo = (PageFreeSpaceInfo * )right ;
1260+ FSMPageData * linfo = (FSMPageData * )left ;
1261+ FSMPageData * rinfo = (FSMPageData * )right ;
1262+ BlockNumber lblkno = FSMPageGetPageNum (linfo );
1263+ BlockNumber rblkno = FSMPageGetPageNum (rinfo );
12621264
1263- if (linfo -> blkno < rinfo -> blkno )
1265+ if (lblkno < rblkno )
12641266return -1 ;
1265- else if (linfo -> blkno > rinfo -> blkno )
1267+ else if (lblkno > rblkno )
12661268return 1 ;
12671269return 0 ;
12681270}