@ -2374,43 +2374,19 @@ pgstat_update_heap_dead_tuples(Relation rel, int delta)
pgstat_info - > t_counts . t_delta_dead_tuples - = delta ;
}
/* ----------
* AtEOXact_PgStat
*
* Called from access / transam / xact . c at top - level transaction commit / abort .
* - - - - - - - - - -
*/
void
AtEOXact_PgStat ( bool isCommit , bool parallel )
{
PgStat_SubXactStatus * xact_state ;
/* Don't count parallel worker transaction stats */
if ( ! parallel )
{
/*
* Count transaction commit or abort . ( We use counters , not just
* bools , in case the reporting message isn ' t sent right away . )
*/
if ( isCommit )
pgStatXactCommit + + ;
else
pgStatXactRollback + + ;
}
/*
* Transfer transactional insert / update counts into the base tabstat
* entries . We don ' t bother to free any of the transactional state , since
* it ' s all in TopTransactionContext and will go away anyway .
* Perform relation stats specific end - of - transaction work . Helper for
* AtEOXact_PgStat .
*
* Transfer transactional insert / update counts into the base tabstat entries .
* We don ' t bother to free any of the transactional state , since it ' s all in
* TopTransactionContext and will go away anyway .
*/
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL )
static void
AtEOXact_PgStat_Relations ( PgStat_SubXactStatus * xact_state , bool isCommit )
{
PgStat_TableXactStatus * trans ;
Assert ( xact_state - > nest_level = = 1 ) ;
Assert ( xact_state - > prev = = NULL ) ;
for ( trans = xact_state - > first ; trans ! = NULL ; trans = trans - > next )
{
PgStat_TableStatus * tabstat ;
@ -2456,37 +2432,65 @@ AtEOXact_PgStat(bool isCommit, bool parallel)
tabstat - > trans = NULL ;
}
}
pgStatXactStack = NULL ;
/* Make sure any stats snapshot is thrown away */
pgstat_clear_snapshot ( ) ;
static void
AtEOXact_PgStat_Database ( bool isCommit , bool parallel )
{
/* Don't count parallel worker transaction stats */
if ( ! parallel )
{
/*
* Count transaction commit or abort . ( We use counters , not just
* bools , in case the reporting message isn ' t sent right away . )
*/
if ( isCommit )
pgStatXactCommit + + ;
else
pgStatXactRollback + + ;
}
}
/* ----------
* AtEOSubXact_PgStat
* AtEOXact_PgStat
*
* Called from access / transam / xact . c at subtransaction commit / abort .
* Called from access / transam / xact . c at top - level transaction commit / abort .
* - - - - - - - - - -
*/
void
AtEOSubXact_PgStat ( bool isCommit , int nestDepth )
AtEOXact_PgStat ( bool isCommit , bool parallel )
{
PgStat_SubXactStatus * xact_state ;
AtEOXact_PgStat_Database ( isCommit , parallel ) ;
/* handle transactional stats information */
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL )
{
Assert ( xact_state - > nest_level = = 1 ) ;
Assert ( xact_state - > prev = = NULL ) ;
AtEOXact_PgStat_Relations ( xact_state , isCommit ) ;
}
pgStatXactStack = NULL ;
/* Make sure any stats snapshot is thrown away */
pgstat_clear_snapshot ( ) ;
}
/*
* Perform relation stats specific end - of - sub - transaction work . Helper for
* AtEOSubXact_PgStat .
*
* Transfer transactional insert / update counts into the next higher
* subtransaction state .
*/
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL & &
xact_state - > nest_level > = nestDepth )
static void
AtEOSubXact_PgStat_Relations ( PgStat_SubXactStatus * xact_state , bool isCommit , int nestDepth )
{
PgStat_TableXactStatus * trans ;
PgStat_TableXactStatus * next_trans ;
/* delink xact_state from stack immediately to simplify reuse case */
pgStatXactStack = xact_state - > prev ;
for ( trans = xact_state - > first ; trans ! = NULL ; trans = next_trans )
{
PgStat_TableStatus * tabstat ;
@ -2495,6 +2499,7 @@ AtEOSubXact_PgStat(bool isCommit, int nestDepth)
Assert ( trans - > nest_level = = nestDepth ) ;
tabstat = trans - > parent ;
Assert ( tabstat - > trans = = trans ) ;
if ( isCommit )
{
if ( trans - > upper & & trans - > upper - > nest_level = = nestDepth - 1 )
@ -2555,30 +2560,42 @@ AtEOSubXact_PgStat(bool isCommit, int nestDepth)
pfree ( trans ) ;
}
}
pfree ( xact_state ) ;
}
}
/*
* AtPrepare_PgStat
* Save the transactional stats state at 2 PC transaction prepare .
/* ----------
* AtEOSubXact_PgStat
*
* In this phase we just generate 2 PC records for all the pending
* transaction - dependent stats work .
* Called from access / transam / xact . c at subtransaction commit / abort .
* - - - - - - - - - -
*/
void
AtPrepare_PgStat ( void )
AtEOSubXact_PgStat ( bool isCommit , int nestDepth )
{
PgStat_SubXactStatus * xact_state ;
/* merge the sub-transaction's transactional stats into the parent */
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL )
if ( xact_state ! = NULL & &
xact_state - > nest_level > = nestDepth )
{
/* delink xact_state from stack immediately to simplify reuse case */
pgStatXactStack = xact_state - > prev ;
AtEOSubXact_PgStat_Relations ( xact_state , isCommit , nestDepth ) ;
pfree ( xact_state ) ;
}
}
/*
* Generate 2 PC records for all the pending transaction - dependent relation
* stats .
*/
static void
AtPrepare_PgStat_Relations ( PgStat_SubXactStatus * xact_state )
{
PgStat_TableXactStatus * trans ;
Assert ( xact_state - > nest_level = = 1 ) ;
Assert ( xact_state - > prev = = NULL ) ;
for ( trans = xact_state - > first ; trans ! = NULL ; trans = trans - > next )
{
PgStat_TableStatus * tabstat ;
@ -2603,16 +2620,51 @@ AtPrepare_PgStat(void)
& record , sizeof ( TwoPhasePgStatRecord ) ) ;
}
}
/*
* AtPrepare_PgStat
* Save the transactional stats state at 2 PC transaction prepare .
*/
void
AtPrepare_PgStat ( void )
{
PgStat_SubXactStatus * xact_state ;
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL )
{
Assert ( xact_state - > nest_level = = 1 ) ;
Assert ( xact_state - > prev = = NULL ) ;
AtPrepare_PgStat_Relations ( xact_state ) ;
}
}
/*
* PostPrepare_PgStat
* Clean up after successful PREPARE .
*
* All we need do here is unlink the transaction stats state from the
* nontransactional state . The nontransactional action counts will be
* reported to the stats collector immediately , while the effects on live
* and dead tuple counts are preserved in the 2 PC state file .
* reported to the stats collector immediately , while the effects on
* live and dead tuple counts are preserved in the 2 PC state file .
*
* Note : AtEOXact_PgStat_Relations is not called during PREPARE .
*/
static void
PostPrepare_PgStat_Relations ( PgStat_SubXactStatus * xact_state )
{
PgStat_TableXactStatus * trans ;
for ( trans = xact_state - > first ; trans ! = NULL ; trans = trans - > next )
{
PgStat_TableStatus * tabstat ;
tabstat = trans - > parent ;
tabstat - > trans = NULL ;
}
}
/*
* PostPrepare_PgStat
* Clean up after successful PREPARE .
*
* Note : AtEOXact_PgStat is not called during PREPARE .
*/
@ -2628,15 +2680,10 @@ PostPrepare_PgStat(void)
xact_state = pgStatXactStack ;
if ( xact_state ! = NULL )
{
PgStat_TableXactStatus * trans ;
for ( trans = xact_state - > first ; trans ! = NULL ; trans = trans - > next )
{
PgStat_TableStatus * tabstat ;
Assert ( xact_state - > nest_level = = 1 ) ;
Assert ( xact_state - > prev = = NULL ) ;
tabstat = trans - > parent ;
tabstat - > trans = NULL ;
}
PostPrepare_PgStat_Relations ( xact_state ) ;
}
pgStatXactStack = NULL ;