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

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
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 22:43:18
Message-ID: auPMBrtN3BM3Bwyz@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 29, 2026 at 11:30:45AM -0500, Sami Imseih wrote:
> 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.

Okay. Looks globally fine.

> 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.

- for (int h = 0; h < pgStatLocal.num_var_hashes; h++)
+ if (filter_by_kind)
{
+ Assert(kind >= PGSTAT_KIND_MIN && kind <= PGSTAT_KIND_MAX);
+ Assert(pgStatLocal.kind_hash[kind] != NULL);
+ }
+
+ for (int h = 0; h < num_hashes; h++)
+ {
+ dshash_table *hash = filter_by_kind ?
+ pgStatLocal.kind_hash[kind] : pgStatLocal.var_hashes[h];

Instead of allocating the dshash_table pointer in the loop, perhaps
use temporary variables to store the number of hashtables and an array
of them. That would matter if somebody would like to extend this API
to a subset of N hashtables, where 1 < N < num_var_hashes?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lukas Fittl 2026-10-29 22:56:23 Re: Assert failure in parallel query due to SubPlan double visit for hash join
Previous Message Hannu Krosing 2026-10-29 22:42:30 Re: ZSTD TOAST compression, and an extensible compression method encoding