@@ -499,27 +499,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
499499else if (GinGetNPosting (itup )> 0 )
500500{
501501int nitems ;
502- ItemPointer uncompressed ;
502+ ItemPointer items_orig ;
503+ bool free_items_orig ;
504+ ItemPointer items ;
503505
504- /*
505- * Vacuum posting list with proper function for compressed and
506- * uncompressed format.
507- */
506+ /* Get list of item pointers from the tuple. */
508507if (GinItupIsCompressed (itup ))
509- uncompressed = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
508+ {
509+ items_orig = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
510+ free_items_orig = true;
511+ }
510512else
511513{
512- uncompressed = (ItemPointer )GinGetPosting (itup );
514+ items_orig = (ItemPointer )GinGetPosting (itup );
513515nitems = GinGetNPosting (itup );
516+ free_items_orig = false;
514517}
515518
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 )
519527{
520- /*
521- * Some ItemPointers were deleted, recreate tuple.
522- */
523528OffsetNumber attnum ;
524529Datum key ;
525530GinNullCategory category ;
@@ -528,7 +533,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
528533
529534if (nitems > 0 )
530535{
531- plist = ginCompressPostingList (uncompressed ,nitems ,GinMaxItemSize ,NULL );
536+ plist = ginCompressPostingList (items ,nitems ,GinMaxItemSize ,NULL );
532537plistsize = SizeOfGinPostingList (plist );
533538}
534539else
@@ -567,6 +572,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
567572RelationGetRelationName (gvs -> index ));
568573
569574pfree (itup );
575+ pfree (items );
570576}
571577}
572578}