| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
| Cc: | Andres Freund <andres(at)anarazel(dot)de>, Daniel Gustafsson <daniel(at)yesql(dot)se>, "Gregory Stark (as CFM)" <stark(dot)cfm(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Split index and table statistics into different types of stats |
| Date: | 2026-08-12 22:34:37 |
| Message-ID: | anz0_bHBEd-_7Vzb@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, Aug 12, 2026 at 11:52:16AM +0000, Bertrand Drouvot wrote:
> I've a few comments:
Thanks for the review.
> I agree that keeping a single Relation.pgstat_info pointer makes sense.
> That said, IIUC, it does not require both kinds to use the same allocation
> size.
>
> I wonder if we could keep the single pointer design while using a small common
> header in separate table and index pending structures? That would allow
> Relation.pgstat_info to point to the common header while using a different
> pending_size for each kind.
TBH, I find this a bit unattractive because it reduces code clarity.
There is a bit of memory wasted for pending index data for indexes due
to the fact that the union's size is calculated based on its largest
number. It's nothing new, the split just makes cleaner the handling
of the fields, in terms of which stats kind can touch each part.
> The table and index specific functions and macros assume that the relation
> has the expected kind. That assumption existed before this patch, but both
> kinds previously used PgStat_TableStatus, so those accesses still referred to
> fields that existed in the pending object.
>
> With the new union, a wrong call can modify an unrelated member. For example,
> pgstat_count_index_tuples() on a table updates idx.tuples_returned, which
> overlaps the tab.trans pointer.
>
> The current callers look correct, but worth adding assertions for the expected
> kind in those functions and macros?
Hmm. That sounds like a good idea at the end, based on the stats
kind, before touching any relevant field. That enforces the union
policy on a caller basis.
> -typedef struct PgStat_TableXactStatus
> +typedef struct PgStat_RelXactStatus
> {
>
> PgStat_RelationStatus is common to tables and indexes, but PgStat_RelXactStatus
> tracks transactional tuple changes for tables only.
>
> Would keeping PgStat_TableXactStatus be less ambiguous here? It would also
> match add_tabstat_xact_level() and ensure_tabstat_xact_level().
Works for me. Perhaps I was just too much enthusiastic with this part
of the rename. :p
Updated patch attached.
--
Michael
| Attachment | Content-Type | Size |
|---|---|---|
| v17-0001-Refactor-PgStat_TableStatus-to-new-PgStat_Relati.patch | text/plain | 42.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sami Imseih | 2026-08-12 22:53:38 | Re: Disallow outer-level and WHERE-clause aggregates in GRAPH_TABLE |
| Previous Message | Andrew Dunstan | 2026-08-12 22:32:41 | Fire create_upper_paths_hook for UPPERREL_PARTIAL_GROUP_AGG |