]> granicus.if.org Git - postgresql/commitdiff
Avoid counting transaction stats for parallel worker cooperating
authorAmit Kapila <akapila@postgresql.org>
Wed, 10 Apr 2019 02:54:15 +0000 (08:24 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 10 Apr 2019 02:54:15 +0000 (08:24 +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 ecc01f741d4f72ab341ca7b5cb5b10a00f419bb3..f9a4960f8aeb132ec70e93b3bf85e15427ed4366 100644 (file)
@@ -1602,7 +1602,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
        LWLockRelease(TwoPhaseStateLock);
 
        /* 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 bd5024ef00aa1c1b13204c9dd46f74e41a850a44..816fd626ece41d1c0a407d913da7a76502773897 100644 (file)
@@ -2241,7 +2241,7 @@ CommitTransaction(void)
        AtEOXact_Files(true);
        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);
@@ -2734,7 +2734,7 @@ AbortTransaction(void)
                AtEOXact_Files(false);
                AtEOXact_ComboCid();
                AtEOXact_HashTables(false);
-               AtEOXact_PgStat(false);
+               AtEOXact_PgStat(false, is_parallel_worker);
                AtEOXact_ApplyLauncher(false);
                pgstat_report_xact_timestamp(0);
        }
index 0355fa65fb899b6cb6823fae5d971042e1db033a..7c0b24a16fa6b15dcae035677ea2e9ec3154f84e 100644 (file)
@@ -2089,18 +2089,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 5888242f757dec70fff74bcde90ed1f5198be42b..a68927b57a28a865a5ff6aae657a8e17c2b87603 100644 (file)
@@ -1378,7 +1378,7 @@ extern void pgstat_init_function_usage(FunctionCallInfo 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);