Re: [PATCH] pgstat: Add helper to drop entries from a stats kind's hash

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] pgstat: Add helper to drop entries from a stats kind's hash
Date: 2026-10-29 16:30:45
Message-ID: CAN12+YKQHHWuhQ7W5JSgp9jjAajtgzUS0rA1ESAwmg9Zw7SmAg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > Yeah, I mentioned that earlier, and I did not feel right about it either. So I
> > added back the test that uses pgstat_drop_entry(), and added a separate
> > test function for the new _of_kind API. The TAP test now drops one entry via
> > pgstat_drop_entry() and another via pgstat_drop_matching_entries_of_kind().
> >
> > I also renamed the new static helper to pgstat_drop_matching_entries_in_hash()
> > to match the existing pgstat_reset_matching_entries_in_hash().
>
> My first reaction after reading this patch is why do we need two APIs?
> We could have pgstat_drop_matching_entries() take an additional
> PgStat_Kind, matching with all the hash tables if passing an invalid
> kind?

I initially avoided changing the C API/ABI, which is why the previous
version added a separate helper. Since this is only targeting master, I
agree that changing pgstat_drop_matching_entries() is better. If there
are extensions using pgstat_drop_matching_entries(), it's a simple
change.

> That would mean one routine instead of three as done in this
> patch, as of two exposed and one static in pgstat_shmem.c. That would
> also avoid the filter_kind check in the inner loop of
> pgstat_drop_matching_entries_in_hash(), as done in the patch.

I kept the kind check in the loop because, when kind maps to the shared
hash, scanning that hash also visits entries for other kinds. Without
the check, a kind-specific scan could consider those entries too,
including in the NULL do_drop path.

The added tests cover both cases: the callback path verifies
that entries of another kind are not passed to the callback, and the NULL
do_drop path verifies that dropping all entries of the custom stats kind
does not drop a relation stats entry in the same shared hash.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v3-0001-pgstat-Add-kind-filter-to-pgstat_drop_matching_en.patch application/octet-stream 11.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Burd 2026-10-29 16:42:53 Re: nbtree: opt-in leaf key prefix compression
Previous Message Greg Burd 2026-10-29 16:12:52 Hash index: stop registering pin-only bucket pages in WAL (remove REGBUF_NO_CHANGE)