Re: pgstat include expansion

Andres Freund <andres@anarazel.de>

From: Andres Freund <andres@anarazel.de>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>, Alvaro Herrera <alvherre@kurilemu.de>
Date: 2026-02-16T17:18:41Z
Lists: pgsql-hackers
Hi,

On 2026-02-16 13:36:02 +0900, Michael Paquier wrote:
> On Fri, Feb 13, 2026 at 05:14:01PM -0500, Andres Freund wrote:
> > I think now that we rely on C11, we actually could also forward-declare enum
> > typedefs. That would allow us to avoid including
> > worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
> > for that - IIUC it only allows forward declaring enums when using 'enum
> > class', but I don't think we can rely on that.  I think the best solution
> > would be to move the typedef to a more suitable header, but baring that, I
> > guess just passing an int would do.
> 
> 
> > -extern void pgstat_report_subscription_error(Oid subid,
> > -                                             LogicalRepWorkerType wtype);
> > +extern void pgstat_report_subscription_error(Oid subid, int wtype);
> 
> FWIW, I like some type enforcements when it comes to such report
> routines.  That avoids some careless assignments.

In theory I agree (I after all did suggest moving the typedef to a better
header).  However, the type enforcement argument IMO is somewhat bogus, as C
doesn't really have strong enum types, therefore you can just pass pretty
random stuff.  I do wish C enums could be stronger...


> This is usually a sign of header refactoring to me, where the "light"
> declarations ought to be moved into an independent header that can be fed
> back to other places, like this one.  An enum declaration or a set of
> constants can be usually worth a split if their knowledge gets a lot across
> the tree.  That's just to say that while I agree about reducing the header
> footprint, I don't find the result presented here to be the best thing we
> can do.

I literally wrote that it isn't the best solution in the quoted portion above
and suggested moving the typedef to a different header?  I was hoping the
author of the code would do that...

Greetings,

Andres Freund



Commits

  1. Don't include wait_event.h in pgstat.h

  2. Don't include proc.h in shm_mq.h

  3. Don't include latch.h in libpq/libpq.h

  4. Reduce includes in pgstat.h

  5. Avoid including utils/timestamp.h in conflict.h.

  6. Avoid including worker_internal.h in pgstat.h.

  7. Add seq_sync_error_count to subscription statistics.

  8. Don't include execnodes.h in replication/conflict.h

  9. Collect statistics about conflicts in logical replication.