@ -50,7 +50,7 @@ static bool _bt_mark_page_halfdead(Relation rel, Buffer leafbuf,
static bool _bt_unlink_halfdead_page ( Relation rel , Buffer leafbuf ,
BlockNumber scanblkno ,
bool * rightsib_empty ,
uint32 * ndeleted ) ;
BTVacState * vstate ) ;
static bool _bt_lock_subtree_parent ( Relation rel , BlockNumber child ,
BTStack stack ,
Buffer * subtreeparent ,
@ -1760,20 +1760,22 @@ _bt_rightsib_halfdeadflag(Relation rel, BlockNumber leafrightsib)
* should never pass a buffer containing an existing deleted page here . The
* lock and pin on caller ' s buffer will be dropped before we return .
*
* Returns the number of pages successfully deleted ( zero if page cannot
* be deleted now ; could be more than one if parent or right sibling pages
* were deleted too ) . Note that this does not include pages that we delete
* that the btvacuumscan scan has yet to reach ; they ' ll get counted later
* instead .
* Maintains bulk delete stats for caller , which are taken from vstate . We
* need to cooperate closely with caller here so that whole VACUUM operation
* reliably avoids any double counting of subsidiary - to - leafbuf pages that we
* delete in passing . If such pages happen to be from a block number that is
* ahead of the current scanblkno position , then caller is expected to count
* them directly later on . It ' s simpler for us to understand caller ' s
* requirements than it would be for caller to understand when or how a
* deleted page became deleted after the fact .
*
* NOTE : this leaks memory . Rather than trying to clean up everything
* carefully , it ' s better to run it in a temp context that can be reset
* frequently .
*/
uint32
_bt_pagedel ( Relation rel , Buffer leafbuf )
void
_bt_pagedel ( Relation rel , Buffer leafbuf , BTVacState * vstate )
{
uint32 ndeleted = 0 ;
BlockNumber rightsib ;
bool rightsib_empty ;
Page page ;
@ -1781,7 +1783,8 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
/*
* Save original leafbuf block number from caller . Only deleted blocks
* that are < = scanblkno get counted in ndeleted return value .
* that are < = scanblkno are added to bulk delete stat ' s pages_deleted
* count .
*/
BlockNumber scanblkno = BufferGetBlockNumber ( leafbuf ) ;
@ -1843,7 +1846,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
RelationGetRelationName ( rel ) ) ) ) ;
_bt_relbuf ( rel , leafbuf ) ;
return ndeleted ;
return ;
}
/*
@ -1873,7 +1876,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
Assert ( ! P_ISHALFDEAD ( opaque ) ) ;
_bt_relbuf ( rel , leafbuf ) ;
return ndeleted ;
return ;
}
/*
@ -1922,8 +1925,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
if ( _bt_leftsib_splitflag ( rel , leftsib , leafblkno ) )
{
ReleaseBuffer ( leafbuf ) ;
Assert ( ndeleted = = 0 ) ;
return ndeleted ;
return ;
}
/* we need an insertion scan key for the search, so build one */
@ -1964,7 +1966,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
if ( ! _bt_mark_page_halfdead ( rel , leafbuf , stack ) )
{
_bt_relbuf ( rel , leafbuf ) ;
return ndeleted ;
return ;
}
}
@ -1979,7 +1981,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
{
/* Check for interrupts in _bt_unlink_halfdead_page */
if ( ! _bt_unlink_halfdead_page ( rel , leafbuf , scanblkno ,
& rightsib_empty , & ndeleted ) )
& rightsib_empty , vstate ) )
{
/*
* _bt_unlink_halfdead_page should never fail , since we
@ -1990,7 +1992,7 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
* lock and pin on leafbuf for us .
*/
Assert ( false ) ;
return ndeleted ;
return ;
}
}
@ -2026,8 +2028,6 @@ _bt_pagedel(Relation rel, Buffer leafbuf)
leafbuf = _bt_getbuf ( rel , rightsib , BT_WRITE ) ;
}
return ndeleted ;
}
/*
@ -2262,9 +2262,10 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
*/
static bool
_bt_unlink_halfdead_page ( Relation rel , Buffer leafbuf , BlockNumber scanblkno ,
bool * rightsib_empty , uint32 * ndeleted )
bool * rightsib_empty , BTVacState * vstate )
{
BlockNumber leafblkno = BufferGetBlockNumber ( leafbuf ) ;
IndexBulkDeleteResult * stats = vstate - > stats ;
BlockNumber leafleftsib ;
BlockNumber leafrightsib ;
BlockNumber target ;
@ -2674,12 +2675,17 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
_bt_relbuf ( rel , buf ) ;
/*
* If btvacuumscan won ' t revisit this page in a future btvacuumpage call
* and count it as deleted then , we count it as deleted by current
* btvacuumpage call
* Maintain pages_newly_deleted , which is simply the number of pages
* deleted by the ongoing VACUUM operation .
*
* Maintain pages_deleted in a way that takes into account how
* btvacuumpage ( ) will count deleted pages that have yet to become
* scanblkno - - only count page when it ' s not going to get that treatment
* later on .
*/
stats - > pages_newly_deleted + + ;
if ( target < = scanblkno )
( * ndeleted ) + + ;
stats - > pages_deleted + + ;
return true ;
}