Hi,

On 2019-07-31 19:25:01 -0400, Tom Lane wrote:
> Andres Freund <and...@anarazel.de> writes:
> > On 2019-07-31 16:55:31 -0400, Tom Lane wrote:
> >> Yeah.  I seem to recall a proposal that nodes.h should contain
> >> 
> >> typedef struct Foo Foo;
> >> 
> >> for every node type Foo, and then the other headers would just
> >> fill in the structs, and we could get rid of a lot of ad-hoc
> >> forward struct declarations and other hackery.
> 
> > That to me just seems objectively worse. Now adding a new struct as a
> > minor implementation detail of some subsystem doesn't just require
> > recompiling the relevant files, but just about all of pg.
> 
> Er, what?  This list of typedefs would change exactly when enum NodeTag
> changes, so AFAICS your objection is bogus.

> It's true that this proposal doesn't help for structs that aren't Nodes,
> but my sense is that > 90% of our ad-hoc struct references are for Nodes.

Ah, well, I somehow assumed you were talking about all nodes. I don't
think I agree with the 90% figure. In headers I feel like most the
references are to things like Relation, Snapshot, HeapTuple, etc.


> > Right now we really have weird dependencies between largely independent
> > subsystem.
> 
> Agreed, but I think fixing that will take some actually serious design
> work.  It's not going to mechanically fall out of changing typedef rules.

No, but without finding a more workable approach than what we're doing
often doing now wrt includes and forward declares, we'll have a lot
harder time to separate subsystems out more.


> > The only reason the explicit forward declaration is needed in the common
> > case of a 'struct foo*' parameter is that C has weird visibility rules
> > about the scope of forward declarations in paramters.
> 
> Yeah, but there's not much we can do about that, nor is getting rid
> of typedefs in favor of "struct" going to make it even a little bit
> better.

It imo pretty fundamentally does. You cannot redefine typedefs, but you
can forward declare structs.


E.g. in the attached series of patches, I'm removing a good portion of
unnecessary dependencies to fmgr.h. But to actually make a difference
that requires referencing two structs without including the header - and
I don't think restructing fmgr.h into two headers is a particularly
attractive alternative (would make it a lot more work and a lot more
invasive).

Think the first three are pretty clearly a good idea, I'm a bit less
sanguine about the fourth:
Headers like utils/timestamp.h are often included just because we need a
TimestampTz type somewhere, or call GetCurrentTimestamp(). Approximately
none of these need the PG_GETARG_* macros, which are the only reason for
including fmgr.h in these headers.  As they're macros that's not
actually needed, although I think normally good style. But I' think here
avoiding exposing fmgr.h to more headers is a bigger win.

Greetings,

Andres Freund
>From 1b45edcb73e4b407cf6449246e57788c5a283b99 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 3 Aug 2019 12:19:41 -0700
Subject: [PATCH v1 1/4] Remove redundant prototypes for SQL callable
 functions.

These aren't needed after 352a24a1f9d6. The ones remaining after this
are not defined on the SQL level.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/catalog/pg_publication.h | 1 -
 src/include/executor/nodeAgg.h       | 2 --
 2 files changed, 3 deletions(-)

diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h
index d4bf5b1e2fa..20a2f0ac1bf 100644
--- a/src/include/catalog/pg_publication.h
+++ b/src/include/catalog/pg_publication.h
@@ -92,6 +92,5 @@ extern ObjectAddress publication_add_relation(Oid pubid, Relation targetrel,
 extern Oid	get_publication_oid(const char *pubname, bool missing_ok);
 extern char *get_publication_name(Oid pubid, bool missing_ok);
 
-extern Datum pg_get_publication_tables(PG_FUNCTION_ARGS);
 
 #endif							/* PG_PUBLICATION_H */
diff --git a/src/include/executor/nodeAgg.h b/src/include/executor/nodeAgg.h
index 1a8ca98a8c3..68c9e5f5400 100644
--- a/src/include/executor/nodeAgg.h
+++ b/src/include/executor/nodeAgg.h
@@ -311,6 +311,4 @@ extern void ExecReScanAgg(AggState *node);
 
 extern Size hash_agg_entry_size(int numAggs);
 
-extern Datum aggregate_dummy(PG_FUNCTION_ARGS);
-
 #endif							/* NODEAGG_H */
-- 
2.22.0.545.g9c9b961d7e

>From d34cb9a51e4c35630012a0a85cc51d2d4c29d367 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 3 Aug 2019 11:51:43 -0700
Subject: [PATCH v1 2/4] Don't include utils/array.h from acl.h.

For most uses of acl.h the details of how "Acl" internally looks like
is irrelevant. In fact, it might make sense to move a lot of the
implementation details into a separate header.

The main motivation of this change is to avoid including fmgr.h (via
array.h, which needs it for exposed structs) in a lot of files that
otherwise don't need it. A future commit will remove fmgr.h from a lot
of files.

Directly include utils/array.h and utils/expandeddatum.h from the
files that need them, but previously included them indirectly, via
acl.h.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 contrib/pageinspect/hashfuncs.c         | 1 +
 src/backend/executor/execExpr.c         | 1 +
 src/backend/executor/execExprInterp.c   | 1 +
 src/backend/executor/execTuples.c       | 1 +
 src/backend/executor/nodeAgg.c          | 1 +
 src/backend/executor/nodeWindowAgg.c    | 1 +
 src/backend/partitioning/partprune.c    | 1 +
 src/backend/statistics/extended_stats.c | 1 +
 src/backend/statistics/mcv.c            | 1 +
 src/backend/utils/adt/acl.c             | 1 +
 src/backend/utils/adt/tsvector_op.c     | 1 +
 src/include/catalog/objectaddress.h     | 2 +-
 src/include/utils/acl.h                 | 3 +--
 src/include/utils/array.h               | 2 +-
 14 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index e69913302ac..9374c4aabc4 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_am.h"
 #include "funcapi.h"
 #include "miscadmin.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
 
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 6d09f2a2181..58e2432aac7 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -42,6 +42,7 @@
 #include "nodes/nodeFuncs.h"
 #include "optimizer/optimizer.h"
 #include "pgstat.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/datum.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index 66a67c72b29..d61f75bc3b6 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -62,6 +62,7 @@
 #include "executor/execExpr.h"
 #include "executor/nodeSubplan.h"
 #include "funcapi.h"
+#include "utils/array.h"
 #include "utils/memutils.h"
 #include "miscadmin.h"
 #include "nodes/nodeFuncs.h"
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 5ee2a464bb4..697f1fed71d 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -65,6 +65,7 @@
 #include "nodes/nodeFuncs.h"
 #include "storage/bufmgr.h"
 #include "utils/builtins.h"
+#include "utils/expandeddatum.h"
 #include "utils/lsyscache.h"
 #include "utils/typcache.h"
 
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index a9a1fd022a5..58c376aeb74 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -231,6 +231,7 @@
 #include "parser/parse_coerce.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
+#include "utils/expandeddatum.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c
index def00cd7c5f..6a71c1295d2 100644
--- a/src/backend/executor/nodeWindowAgg.c
+++ b/src/backend/executor/nodeWindowAgg.c
@@ -46,6 +46,7 @@
 #include "parser/parse_coerce.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
+#include "utils/expandeddatum.h"
 #include "utils/datum.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c
index 6d3751d44a6..0feb8f4a115 100644
--- a/src/backend/partitioning/partprune.c
+++ b/src/backend/partitioning/partprune.c
@@ -53,6 +53,7 @@
 #include "partitioning/partbounds.h"
 #include "partitioning/partprune.h"
 #include "rewrite/rewriteManip.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 
 
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index 23c74f7d90a..48f17ba8d56 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -31,6 +31,7 @@
 #include "postmaster/autovacuum.h"
 #include "statistics/extended_stats_internal.h"
 #include "statistics/statistics.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index cec06f8c444..bae6f219684 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -26,6 +26,7 @@
 #include "optimizer/clauses.h"
 #include "statistics/extended_stats_internal.h"
 #include "statistics/statistics.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/bytea.h"
 #include "utils/fmgroids.h"
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index cfd139e6e92..d7e6100ccbf 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -30,6 +30,7 @@
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "utils/acl.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/catcache.h"
 #include "utils/hashutils.h"
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index 696a7fdf914..28d042273e3 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -25,6 +25,7 @@
 #include "miscadmin.h"
 #include "parser/parse_coerce.h"
 #include "tsearch/ts_utils.h"
+#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/regproc.h"
diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h
index 95cc3158683..7e61569f9fe 100644
--- a/src/include/catalog/objectaddress.h
+++ b/src/include/catalog/objectaddress.h
@@ -77,7 +77,7 @@ extern char *getObjectTypeDescription(const ObjectAddress *object);
 extern char *getObjectIdentity(const ObjectAddress *address);
 extern char *getObjectIdentityParts(const ObjectAddress *address,
 									List **objname, List **objargs);
-extern ArrayType *strlist_to_textarray(List *list);
+extern struct ArrayType *strlist_to_textarray(List *list);
 
 extern ObjectType get_relkind_objtype(char relkind);
 
diff --git a/src/include/utils/acl.h b/src/include/utils/acl.h
index f4c160ee723..b99da737283 100644
--- a/src/include/utils/acl.h
+++ b/src/include/utils/acl.h
@@ -35,7 +35,6 @@
 #include "access/htup.h"
 #include "nodes/parsenodes.h"
 #include "parser/parse_node.h"
-#include "utils/array.h"
 #include "utils/snapshot.h"
 
 
@@ -104,7 +103,7 @@ typedef struct AclItem
 /*
  * Acl			a one-dimensional array of AclItem
  */
-typedef ArrayType Acl;
+typedef struct ArrayType Acl;
 
 #define ACL_NUM(ACL)			(ARR_DIMS(ACL)[0])
 #define ACL_DAT(ACL)			((AclItem *) ARR_DATA_PTR(ACL))
diff --git a/src/include/utils/array.h b/src/include/utils/array.h
index b441eb452b9..5cfafe00457 100644
--- a/src/include/utils/array.h
+++ b/src/include/utils/array.h
@@ -77,7 +77,7 @@ struct ExprContext;
  * CAUTION: if you change the header for ordinary arrays you will also
  * need to change the headers for oidvector and int2vector!
  */
-typedef struct
+typedef struct ArrayType
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
 	int			ndim;			/* # of dimensions */
-- 
2.22.0.545.g9c9b961d7e

>From ffa727a9be04392491cde988eedf72ed47d7643b Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 3 Aug 2019 12:17:19 -0700
Subject: [PATCH v1 3/4] Remove fmgr.h includes from headers that don't really
 need it.

Most of the fmgr.h includes were obsoleted by 352a24a1f9d6f7d4abb1. A
few others can be obsoleted using the underlying struct type in an
implementation detail.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/backend/access/common/printsimple.c     | 1 -
 src/backend/nodes/makefuncs.c               | 1 -
 src/backend/replication/logical/logical.c   | 1 +
 src/backend/replication/pgoutput/pgoutput.c | 2 ++
 src/include/access/brin.h                   | 1 -
 src/include/access/gist_private.h           | 1 -
 src/include/access/hash.h                   | 1 -
 src/include/access/spgist.h                 | 1 -
 src/include/commands/async.h                | 2 --
 src/include/executor/executor.h             | 1 +
 src/include/jit/llvmjit_emit.h              | 1 -
 src/include/nodes/execnodes.h               | 1 +
 src/include/nodes/pathnodes.h               | 3 +--
 src/include/pgstat.h                        | 4 ++--
 src/include/replication/origin.h            | 1 -
 src/include/replication/slot.h              | 1 -
 src/include/replication/walreceiver.h       | 1 -
 src/include/replication/walsender.h         | 2 --
 src/include/utils/bytea.h                   | 1 -
 src/include/utils/formatting.h              | 2 --
 src/include/utils/rel.h                     | 3 +--
 src/include/utils/snapmgr.h                 | 1 -
 src/include/utils/tuplesort.h               | 1 -
 23 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/src/backend/access/common/printsimple.c b/src/backend/access/common/printsimple.c
index 3ea188d701c..651ade14dd2 100644
--- a/src/backend/access/common/printsimple.c
+++ b/src/backend/access/common/printsimple.c
@@ -20,7 +20,6 @@
 
 #include "access/printsimple.h"
 #include "catalog/pg_type.h"
-#include "fmgr.h"
 #include "libpq/pqformat.h"
 #include "utils/builtins.h"
 
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index 5c11b5472e5..18466ac5687 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -17,7 +17,6 @@
 
 #include "catalog/pg_class.h"
 #include "catalog/pg_type.h"
-#include "fmgr.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 9853be6d1c2..f8b9020081e 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -28,6 +28,7 @@
 
 #include "postgres.h"
 
+#include "fmgr.h"
 #include "miscadmin.h"
 
 #include "access/xact.h"
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index d317fd70063..9c08757fcaf 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -14,6 +14,8 @@
 
 #include "catalog/pg_publication.h"
 
+#include "fmgr.h"
+
 #include "replication/logical.h"
 #include "replication/logicalproto.h"
 #include "replication/origin.h"
diff --git a/src/include/access/brin.h b/src/include/access/brin.h
index 612721baf3a..fb351b36e03 100644
--- a/src/include/access/brin.h
+++ b/src/include/access/brin.h
@@ -10,7 +10,6 @@
 #ifndef BRIN_H
 #define BRIN_H
 
-#include "fmgr.h"
 #include "nodes/execnodes.h"
 #include "utils/relcache.h"
 
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index 664f322df3a..fc1a3115565 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -17,7 +17,6 @@
 #include "access/amapi.h"
 #include "access/gist.h"
 #include "access/itup.h"
-#include "fmgr.h"
 #include "lib/pairingheap.h"
 #include "storage/bufmgr.h"
 #include "storage/buffile.h"
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 107c3d01ae4..85982e0e404 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -20,7 +20,6 @@
 #include "access/amapi.h"
 #include "access/itup.h"
 #include "access/sdir.h"
-#include "fmgr.h"
 #include "lib/stringinfo.h"
 #include "storage/bufmgr.h"
 #include "storage/lockdefs.h"
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index 02c87949cee..d787ab213dc 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -16,7 +16,6 @@
 
 #include "access/amapi.h"
 #include "access/xlogreader.h"
-#include "fmgr.h"
 #include "lib/stringinfo.h"
 
 
diff --git a/src/include/commands/async.h b/src/include/commands/async.h
index d132fd59991..c295dc67c64 100644
--- a/src/include/commands/async.h
+++ b/src/include/commands/async.h
@@ -15,8 +15,6 @@
 
 #include <signal.h>
 
-#include "fmgr.h"
-
 /*
  * The number of SLRU page buffers we use for the notification queue.
  */
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 1fb28b4596b..254db49a3ce 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -15,6 +15,7 @@
 #define EXECUTOR_H
 
 #include "executor/execdesc.h"
+#include "fmgr.h"
 #include "nodes/lockoptions.h"
 #include "nodes/parsenodes.h"
 #include "utils/memutils.h"
diff --git a/src/include/jit/llvmjit_emit.h b/src/include/jit/llvmjit_emit.h
index 71a8625efe4..cdfa0dc7214 100644
--- a/src/include/jit/llvmjit_emit.h
+++ b/src/include/jit/llvmjit_emit.h
@@ -17,7 +17,6 @@
 
 #include <llvm-c/Core.h>
 
-#include "fmgr.h"
 #include "jit/llvmjit.h"
 
 
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 4ec78491f6f..c682e86de7d 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -16,6 +16,7 @@
 
 #include "access/tupconvert.h"
 #include "executor/instrument.h"
+#include "fmgr.h"
 #include "lib/pairingheap.h"
 #include "nodes/params.h"
 #include "nodes/plannodes.h"
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index e3c579ee443..510f41a4049 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -15,7 +15,6 @@
 #define PATHNODES_H
 
 #include "access/sdir.h"
-#include "fmgr.h"
 #include "lib/stringinfo.h"
 #include "nodes/params.h"
 #include "nodes/parsenodes.h"
@@ -401,7 +400,7 @@ typedef struct PartitionSchemeData
 	bool	   *parttypbyval;
 
 	/* Cached information about partition comparison functions. */
-	FmgrInfo   *partsupfunc;
+	struct FmgrInfo *partsupfunc;
 }			PartitionSchemeData;
 
 typedef struct PartitionSchemeData *PartitionScheme;
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0a3ad3a1883..fe076d823db 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -12,7 +12,6 @@
 #define PGSTAT_H
 
 #include "datatype/timestamp.h"
-#include "fmgr.h"
 #include "libpq/pqcomm.h"
 #include "port/atomics.h"
 #include "portability/instr_time.h"
@@ -1402,7 +1401,8 @@ extern void pgstat_count_heap_delete(Relation rel);
 extern void pgstat_count_truncate(Relation rel);
 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
 
-extern void pgstat_init_function_usage(FunctionCallInfo fcinfo,
+struct FunctionCallInfoBaseData;
+extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
 									   PgStat_FunctionCallUsage *fcu);
 extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
 									  bool finalize);
diff --git a/src/include/replication/origin.h b/src/include/replication/origin.h
index 7422b26a6d8..dccf48418ff 100644
--- a/src/include/replication/origin.h
+++ b/src/include/replication/origin.h
@@ -10,7 +10,6 @@
 #ifndef PG_ORIGIN_H
 #define PG_ORIGIN_H
 
-#include "fmgr.h"
 #include "access/xlog.h"
 #include "access/xlogdefs.h"
 #include "access/xlogreader.h"
diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h
index 8fbddea78fd..3a5763fb07a 100644
--- a/src/include/replication/slot.h
+++ b/src/include/replication/slot.h
@@ -9,7 +9,6 @@
 #ifndef SLOT_H
 #define SLOT_H
 
-#include "fmgr.h"
 #include "access/xlog.h"
 #include "access/xlogreader.h"
 #include "storage/condition_variable.h"
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index 86a81300517..bc9468b519e 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -14,7 +14,6 @@
 
 #include "access/xlog.h"
 #include "access/xlogdefs.h"
-#include "fmgr.h"
 #include "getaddrinfo.h"		/* for NI_MAXHOST */
 #include "replication/logicalproto.h"
 #include "replication/walsender.h"
diff --git a/src/include/replication/walsender.h b/src/include/replication/walsender.h
index 4a60893a3bc..61223aecbc1 100644
--- a/src/include/replication/walsender.h
+++ b/src/include/replication/walsender.h
@@ -14,8 +14,6 @@
 
 #include <signal.h>
 
-#include "fmgr.h"
-
 /*
  * What to do with a snapshot in create replication slot command.
  */
diff --git a/src/include/utils/bytea.h b/src/include/utils/bytea.h
index c96011fae84..72224ca95f3 100644
--- a/src/include/utils/bytea.h
+++ b/src/include/utils/bytea.h
@@ -14,7 +14,6 @@
 #ifndef BYTEA_H
 #define BYTEA_H
 
-#include "fmgr.h"
 
 
 typedef enum
diff --git a/src/include/utils/formatting.h b/src/include/utils/formatting.h
index 741c5f4809f..0117144779e 100644
--- a/src/include/utils/formatting.h
+++ b/src/include/utils/formatting.h
@@ -17,8 +17,6 @@
 #ifndef _FORMATTING_H_
 #define _FORMATTING_H_
 
-#include "fmgr.h"
-
 
 extern char *str_tolower(const char *buff, size_t nbytes, Oid collid);
 extern char *str_toupper(const char *buff, size_t nbytes, Oid collid);
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index b0fe19ebc54..302dfff1f3d 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -19,7 +19,6 @@
 #include "catalog/pg_class.h"
 #include "catalog/pg_index.h"
 #include "catalog/pg_publication.h"
-#include "fmgr.h"
 #include "nodes/bitmapset.h"
 #include "rewrite/prs2lock.h"
 #include "storage/block.h"
@@ -159,7 +158,7 @@ typedef struct RelationData
 	Oid		   *rd_opfamily;	/* OIDs of op families for each index col */
 	Oid		   *rd_opcintype;	/* OIDs of opclass declared input data types */
 	RegProcedure *rd_support;	/* OIDs of support procedures */
-	FmgrInfo   *rd_supportinfo; /* lookup info for support procedures */
+	struct FmgrInfo *rd_supportinfo; /* lookup info for support procedures */
 	int16	   *rd_indoption;	/* per-column AM-specific flags */
 	List	   *rd_indexprs;	/* index expression trees, if any */
 	List	   *rd_indpred;		/* index predicate tree, if any */
diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h
index 6641ee510a1..8c070d7f412 100644
--- a/src/include/utils/snapmgr.h
+++ b/src/include/utils/snapmgr.h
@@ -14,7 +14,6 @@
 #define SNAPMGR_H
 
 #include "access/transam.h"
-#include "fmgr.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
 #include "utils/snapshot.h"
diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h
index 4521de18e13..d774bc1152f 100644
--- a/src/include/utils/tuplesort.h
+++ b/src/include/utils/tuplesort.h
@@ -23,7 +23,6 @@
 
 #include "access/itup.h"
 #include "executor/tuptable.h"
-#include "fmgr.h"
 #include "storage/dsm.h"
 #include "utils/relcache.h"
 
-- 
2.22.0.545.g9c9b961d7e

>From 18c7d6760aadd033f84e799bb6ac8c94edbf2435 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 3 Aug 2019 12:21:27 -0700
Subject: [PATCH v1 4/4] Remove fmgr.h includes from headers that have macro
 only dependencies.

These headers all just include fmgr.h because they define macros that
in turn use fmgr.h macros, like PG_GETARG_DATUM. Most include sites
for these headers however just want to reference the type defined in
the respective header. Where needed fmgr.h can be included.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 contrib/earthdistance/earthdistance.c | 2 ++
 src/include/utils/cash.h              | 2 --
 src/include/utils/date.h              | 1 -
 src/include/utils/expandedrecord.h    | 1 -
 src/include/utils/geo_decls.h         | 2 --
 src/include/utils/inet.h              | 2 --
 src/include/utils/jsonpath.h          | 1 -
 src/include/utils/numeric.h           | 2 --
 src/include/utils/pg_lsn.h            | 1 -
 src/include/utils/timestamp.h         | 1 -
 src/include/utils/varbit.h            | 2 --
 src/include/utils/xml.h               | 1 -
 12 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c
index e6ebfd11ad4..d6825a83721 100644
--- a/contrib/earthdistance/earthdistance.c
+++ b/contrib/earthdistance/earthdistance.c
@@ -4,6 +4,8 @@
 
 #include <math.h>
 
+#include "fmgr.h"
+
 #include "utils/geo_decls.h"	/* for Point */
 
 #ifndef M_PI
diff --git a/src/include/utils/cash.h b/src/include/utils/cash.h
index 2e332d83b1c..ae158e2dcd0 100644
--- a/src/include/utils/cash.h
+++ b/src/include/utils/cash.h
@@ -12,8 +12,6 @@
 #ifndef CASH_H
 #define CASH_H
 
-#include "fmgr.h"
-
 typedef int64 Cash;
 
 /* Cash is pass-by-reference if and only if int64 is */
diff --git a/src/include/utils/date.h b/src/include/utils/date.h
index bec129aff1c..df6af8dc660 100644
--- a/src/include/utils/date.h
+++ b/src/include/utils/date.h
@@ -16,7 +16,6 @@
 
 #include <math.h>
 
-#include "fmgr.h"
 #include "pgtime.h"
 #include "datatype/timestamp.h"
 
diff --git a/src/include/utils/expandedrecord.h b/src/include/utils/expandedrecord.h
index 84e6aae23fe..ff97effc2f9 100644
--- a/src/include/utils/expandedrecord.h
+++ b/src/include/utils/expandedrecord.h
@@ -15,7 +15,6 @@
 
 #include "access/htup.h"
 #include "access/tupdesc.h"
-#include "fmgr.h"
 #include "utils/expandeddatum.h"
 
 
diff --git a/src/include/utils/geo_decls.h b/src/include/utils/geo_decls.h
index 4b0353cf0f2..cdb350527ba 100644
--- a/src/include/utils/geo_decls.h
+++ b/src/include/utils/geo_decls.h
@@ -18,8 +18,6 @@
 #ifndef GEO_DECLS_H
 #define GEO_DECLS_H
 
-#include "fmgr.h"
-
 /*--------------------------------------------------------------------
  * Useful floating point utilities and constants.
  *-------------------------------------------------------------------
diff --git a/src/include/utils/inet.h b/src/include/utils/inet.h
index 998593e956f..231fb423448 100644
--- a/src/include/utils/inet.h
+++ b/src/include/utils/inet.h
@@ -14,8 +14,6 @@
 #ifndef INET_H
 #define INET_H
 
-#include "fmgr.h"
-
 /*
  *	This is the internal storage format for IP addresses
  *	(both INET and CIDR datatypes):
diff --git a/src/include/utils/jsonpath.h b/src/include/utils/jsonpath.h
index 40ad5fda928..3e7497182e3 100644
--- a/src/include/utils/jsonpath.h
+++ b/src/include/utils/jsonpath.h
@@ -14,7 +14,6 @@
 #ifndef JSONPATH_H
 #define JSONPATH_H
 
-#include "fmgr.h"
 #include "utils/jsonb.h"
 #include "nodes/pg_list.h"
 
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h
index 7cc597d7b09..7bb56f12916 100644
--- a/src/include/utils/numeric.h
+++ b/src/include/utils/numeric.h
@@ -14,8 +14,6 @@
 #ifndef _PG_NUMERIC_H_
 #define _PG_NUMERIC_H_
 
-#include "fmgr.h"
-
 /*
  * Limit on the precision (and hence scale) specifiable in a NUMERIC typmod.
  * Note that the implementation limit on the length of a numeric value is
diff --git a/src/include/utils/pg_lsn.h b/src/include/utils/pg_lsn.h
index 70d8640ef3e..77eff0c15f1 100644
--- a/src/include/utils/pg_lsn.h
+++ b/src/include/utils/pg_lsn.h
@@ -15,7 +15,6 @@
 #ifndef PG_LSN_H
 #define PG_LSN_H
 
-#include "fmgr.h"
 #include "access/xlogdefs.h"
 
 #define DatumGetLSN(X) ((XLogRecPtr) DatumGetInt64(X))
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index ea16190ec3d..e6489180675 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -14,7 +14,6 @@
 #define TIMESTAMP_H
 
 #include "datatype/timestamp.h"
-#include "fmgr.h"
 #include "pgtime.h"
 
 
diff --git a/src/include/utils/varbit.h b/src/include/utils/varbit.h
index 641731c4177..0db45b8f95a 100644
--- a/src/include/utils/varbit.h
+++ b/src/include/utils/varbit.h
@@ -17,8 +17,6 @@
 
 #include <limits.h>
 
-#include "fmgr.h"
-
 /*
  * Modeled on struct varlena from postgres.h, but data type is bits8.
  */
diff --git a/src/include/utils/xml.h b/src/include/utils/xml.h
index 90d08b1fcf2..5f96364bc21 100644
--- a/src/include/utils/xml.h
+++ b/src/include/utils/xml.h
@@ -15,7 +15,6 @@
 #ifndef XML_H
 #define XML_H
 
-#include "fmgr.h"
 #include "nodes/execnodes.h"
 #include "nodes/primnodes.h"
 #include "executor/tablefunc.h"
-- 
2.22.0.545.g9c9b961d7e

Reply via email to