@@ -432,27 +432,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
432432 else if (GinGetNPosting (itup ) > 0 )
433433 {
434434 int 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. */
441440 if (GinItupIsCompressed (itup ))
442- uncompressed = ginPostingListDecode ((GinPostingList * ) GinGetPosting (itup ), & nitems );
441+ {
442+ items_orig = ginPostingListDecode ((GinPostingList * ) GinGetPosting (itup ), & nitems );
443+ free_items_orig = true;
444+ }
443445 else
444446 {
445- uncompressed = (ItemPointer ) GinGetPosting (itup );
447+ items_orig = (ItemPointer ) GinGetPosting (itup );
446448 nitems = 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- */
456461 OffsetNumber attnum ;
457462 Datum key ;
458463 GinNullCategory category ;
@@ -461,7 +466,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
461466
462467 if (nitems > 0 )
463468 {
464- plist = ginCompressPostingList (uncompressed , nitems , GinMaxItemSize , NULL );
469+ plist = ginCompressPostingList (items , nitems , GinMaxItemSize , NULL );
465470 plistsize = SizeOfGinPostingList (plist );
466471 }
467472 else
@@ -500,6 +505,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
500505 RelationGetRelationName (gvs -> index ));
501506
502507 pfree (itup );
508+ pfree (items );
503509 }
504510 }
505511 }
0 commit comments