Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bdf3574

Browse files
author
Amit Kapila
committed
Avoid counting transaction stats for parallel worker cooperating
transaction. The transaction that is initiated by the parallel worker to cooperate with the actual transaction started by the main backend to complete the query execution should not be counted as a separate transaction. The other internal transactions started and committed by the parallel worker are still counted as separate transactions as we that is what we do in other places like autovacuum. This will partially fix the bloat in transaction stats due to additional transactions performed by parallel workers. For a complete fix, we need to decide how we want to show all the transactions that are started internally for various operations and that is a matter of separate patch. Reported-by: Haribabu Kommi Author: Haribabu Kommi Reviewed-by: Amit Kapila, Jamison Kirk and Rahila Syed Backpatch-through: 9.6 Discussion: https://postgr.es/m/CAJrrPGc9=jKXuScvNyQ+VNhO0FZk7LLAShAJRyZjnedd2D61EQ@mail.gmail.com
1 parent d614aae commit bdf3574

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/backend/access/transam/twophase.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
16021602
LWLockRelease(TwoPhaseStateLock);
16031603

16041604
/* Count the prepared xact as committed or aborted */
1605-
AtEOXact_PgStat(isCommit);
1605+
AtEOXact_PgStat(isCommit, false);
16061606

16071607
/*
16081608
* And now we can clean up any files we may have left.

src/backend/access/transam/xact.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,7 @@ CommitTransaction(void)
22412241
AtEOXact_Files(true);
22422242
AtEOXact_ComboCid();
22432243
AtEOXact_HashTables(true);
2244-
AtEOXact_PgStat(true);
2244+
AtEOXact_PgStat(true, is_parallel_worker);
22452245
AtEOXact_Snapshot(true, false);
22462246
AtEOXact_ApplyLauncher(true);
22472247
pgstat_report_xact_timestamp(0);
@@ -2734,7 +2734,7 @@ AbortTransaction(void)
27342734
AtEOXact_Files(false);
27352735
AtEOXact_ComboCid();
27362736
AtEOXact_HashTables(false);
2737-
AtEOXact_PgStat(false);
2737+
AtEOXact_PgStat(false, is_parallel_worker);
27382738
AtEOXact_ApplyLauncher(false);
27392739
pgstat_report_xact_timestamp(0);
27402740
}

src/backend/postmaster/pgstat.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -2089,18 +2089,22 @@ pgstat_update_heap_dead_tuples(Relation rel, int delta)
20892089
* ----------
20902090
*/
20912091
void
2092-
AtEOXact_PgStat(bool isCommit)
2092+
AtEOXact_PgStat(bool isCommit, bool parallel)
20932093
{
20942094
PgStat_SubXactStatus *xact_state;
20952095

2096-
/*
2097-
* Count transaction commit or abort. (We use counters, not just bools,
2098-
* in case the reporting message isn't sent right away.)
2099-
*/
2100-
if (isCommit)
2101-
pgStatXactCommit++;
2102-
else
2103-
pgStatXactRollback++;
2096+
/* Don't count parallel worker transaction stats */
2097+
if (!parallel)
2098+
{
2099+
/*
2100+
* Count transaction commit or abort. (We use counters, not just
2101+
* bools, in case the reporting message isn't sent right away.)
2102+
*/
2103+
if (isCommit)
2104+
pgStatXactCommit++;
2105+
else
2106+
pgStatXactRollback++;
2107+
}
21042108

21052109
/*
21062110
* Transfer transactional insert/update counts into the base tabstat

src/include/pgstat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ extern void pgstat_init_function_usage(FunctionCallInfo fcinfo,
13781378
extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
13791379
bool finalize);
13801380

1381-
extern void AtEOXact_PgStat(bool isCommit);
1381+
extern void AtEOXact_PgStat(bool isCommit, bool parallel);
13821382
extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
13831383

13841384
extern void AtPrepare_PgStat(void);

0 commit comments

Comments
 (0)