]> granicus.if.org Git - postgresql/commitdiff
Avoid counting transaction stats for parallel worker cooperating
authorAmit Kapila <akapila@postgresql.org>
Wed, 10 Apr 2019 03:17:39 +0000 (08:47 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 10 Apr 2019 03:17:39 +0000 (08:47 +0530)
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

src/backend/access/transam/twophase.c
src/backend/access/transam/xact.c
src/backend/postmaster/pgstat.c
src/include/pgstat.h

index 29ae6b4ba948b7f0d3c3a72048a4174040ae7d0a..74e75a853de32a037fb39df5716c6a6a30467ff5 100644 (file)
@@ -1506,7 +1506,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
        PredicateLockTwoPhaseFinish(xid, isCommit);
 
        /* Count the prepared xact as committed or aborted */
-       AtEOXact_PgStat(isCommit);
+       AtEOXact_PgStat(isCommit, false);
 
        /*
         * And now we can clean up any files we may have left.
index 30e1539fcec690f7cdd3f28cd8a656ec0553f7de..3bfa64d02f1177723226aaccfb01ec00d3daa601 100644 (file)
@@ -2165,7 +2165,7 @@ CommitTransaction(void)
        AtEOXact_Files();
        AtEOXact_ComboCid();
        AtEOXact_HashTables(true);
-       AtEOXact_PgStat(true);
+       AtEOXact_PgStat(true, is_parallel_worker);
        AtEOXact_Snapshot(true, false);
        AtEOXact_ApplyLauncher(true);
        pgstat_report_xact_timestamp(0);
@@ -2657,7 +2657,7 @@ AbortTransaction(void)
                AtEOXact_Files();
                AtEOXact_ComboCid();
                AtEOXact_HashTables(false);
-               AtEOXact_PgStat(false);
+               AtEOXact_PgStat(false, is_parallel_worker);
                AtEOXact_ApplyLauncher(false);
                pgstat_report_xact_timestamp(0);
        }
index ac658dcb24184bc99939a59385afb455134e6f67..98348d8aad4edda2c0a0e259a7a445e1e81dec7a 100644 (file)
@@ -2050,18 +2050,22 @@ pgstat_update_heap_dead_tuples(Relation rel, int delta)
  * ----------
  */
 void
-AtEOXact_PgStat(bool isCommit)
+AtEOXact_PgStat(bool isCommit, bool parallel)
 {
        PgStat_SubXactStatus *xact_state;
 
-       /*
-        * 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++;
+       /* 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
index cb05d9b81e518264eed89db3a11aa661e8ce0c48..06e6d670c5799525f1d2c40550d3662c7a865fae 100644 (file)
@@ -1299,7 +1299,7 @@ extern void pgstat_init_function_usage(FunctionCallInfoData *fcinfo,
 extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
                                                  bool finalize);
 
-extern void AtEOXact_PgStat(bool isCommit);
+extern void AtEOXact_PgStat(bool isCommit, bool parallel);
 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
 
 extern void AtPrepare_PgStat(void);