@@ -499,27 +499,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
499
499
else if (GinGetNPosting (itup )> 0 )
500
500
{
501
501
int nitems ;
502
- ItemPointer uncompressed ;
502
+ ItemPointer items_orig ;
503
+ bool free_items_orig ;
504
+ ItemPointer items ;
503
505
504
- /*
505
- * Vacuum posting list with proper function for compressed and
506
- * uncompressed format.
507
- */
506
+ /* Get list of item pointers from the tuple. */
508
507
if (GinItupIsCompressed (itup ))
509
- uncompressed = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
508
+ {
509
+ items_orig = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
510
+ free_items_orig = true;
511
+ }
510
512
else
511
513
{
512
- uncompressed = (ItemPointer )GinGetPosting (itup );
514
+ items_orig = (ItemPointer )GinGetPosting (itup );
513
515
nitems = GinGetNPosting (itup );
516
+ free_items_orig = false;
514
517
}
515
518
516
- uncompressed = ginVacuumItemPointers (gvs ,uncompressed ,nitems ,
517
- & nitems );
518
- if (uncompressed )
519
+ /* Remove any items from the list that need to be vacuumed. */
520
+ items = ginVacuumItemPointers (gvs ,items_orig ,nitems ,& nitems );
521
+
522
+ if (free_items_orig )
523
+ pfree (items_orig );
524
+
525
+ /* If any item pointers were removed, recreate the tuple. */
526
+ if (items )
519
527
{
520
- /*
521
- * Some ItemPointers were deleted, recreate tuple.
522
- */
523
528
OffsetNumber attnum ;
524
529
Datum key ;
525
530
GinNullCategory category ;
@@ -528,7 +533,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
528
533
529
534
if (nitems > 0 )
530
535
{
531
- plist = ginCompressPostingList (uncompressed ,nitems ,GinMaxItemSize ,NULL );
536
+ plist = ginCompressPostingList (items ,nitems ,GinMaxItemSize ,NULL );
532
537
plistsize = SizeOfGinPostingList (plist );
533
538
}
534
539
else
@@ -567,6 +572,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
567
572
RelationGetRelationName (gvs -> index ));
568
573
569
574
pfree (itup );
575
+ pfree (items );
570
576
}
571
577
}
572
578
}