@@ -432,27 +432,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
432432else if (GinGetNPosting (itup )> 0 )
433433{
434434int nitems ;
435- ItemPointer uncompressed ;
435+ ItemPointer items_orig ;
436+ bool free_items_orig ;
437+ ItemPointer items ;
436438
437- /*
438- * Vacuum posting list with proper function for compressed and
439- * uncompressed format.
440- */
439+ /* Get list of item pointers from the tuple. */
441440if (GinItupIsCompressed (itup ))
442- uncompressed = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
441+ {
442+ items_orig = ginPostingListDecode ((GinPostingList * )GinGetPosting (itup ),& nitems );
443+ free_items_orig = true;
444+ }
443445else
444446{
445- uncompressed = (ItemPointer )GinGetPosting (itup );
447+ items_orig = (ItemPointer )GinGetPosting (itup );
446448nitems = GinGetNPosting (itup );
449+ free_items_orig = false;
447450}
448451
449- uncompressed = ginVacuumItemPointers (gvs ,uncompressed ,nitems ,
450- & nitems );
451- if (uncompressed )
452+ /* Remove any items from the list that need to be vacuumed. */
453+ items = ginVacuumItemPointers (gvs ,items_orig ,nitems ,& nitems );
454+
455+ if (free_items_orig )
456+ pfree (items_orig );
457+
458+ /* If any item pointers were removed, recreate the tuple. */
459+ if (items )
452460{
453- /*
454- * Some ItemPointers were deleted, recreate tuple.
455- */
456461OffsetNumber attnum ;
457462Datum key ;
458463GinNullCategory category ;
@@ -461,7 +466,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
461466
462467if (nitems > 0 )
463468{
464- plist = ginCompressPostingList (uncompressed ,nitems ,GinMaxItemSize ,NULL );
469+ plist = ginCompressPostingList (items ,nitems ,GinMaxItemSize ,NULL );
465470plistsize = SizeOfGinPostingList (plist );
466471}
467472else
@@ -500,6 +505,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
500505RelationGetRelationName (gvs -> index ));
501506
502507pfree (itup );
508+ pfree (items );
503509}
504510}
505511}