move_decrement.txt

text/plain

Filename: move_decrement.txt
Type: text/plain
Part: 0
Message: Re: Add support for entry counting in pgstats
index 066027c387c..2482e818e4c 100644
--- a/src/backend/utils/activity/pgstat_shmem.c
+++ b/src/backend/utils/activity/pgstat_shmem.c
@@ -872,6 +872,7 @@ static void
 pgstat_free_entry(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
 {
        dsa_pointer pdsa;
+       PgStat_Kind kind = shent->key.kind;
 
        /*
         * Fetch dsa pointer before deleting entry - that way we can free the
@@ -885,6 +886,11 @@ pgstat_free_entry(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
                dshash_delete_current(hstat);
 
        dsa_free(pgStatLocal.dsa, pdsa);
+
+       /* Entry has been dropped, hence decrement the entry counter */
+       if (pgstat_get_kind_info(kind)->track_entry_counts)
+               pg_atomic_sub_fetch_u64(&pgStatLocal.shmem->entry_counts[kind - 1], 1);
+
 }
 
 /*
@@ -920,17 +926,8 @@ pgstat_drop_entry_internal(PgStatShared_HashEntry *shent,
        /* release refcount marking entry as not dropped */
        if (pg_atomic_sub_fetch_u32(&shent->refcount, 1) == 0)
        {
-               PgStat_Kind kind = shent->key.kind;
-
                pgstat_free_entry(shent, hstat);
 
-               /*
-                * Entry has been dropped with refcount at 0, hence decrement the
-                * entry counter.
-                */
-               if (pgstat_get_kind_info(kind)->track_entry_counts)
-                       pg_atomic_sub_fetch_u64(&pgStatLocal.shmem->entry_counts[kind - 1], 1);
-
                return true;
        }
        else