From c0b1a2fe544226d251c005c9a9ed15d5b4d2b2e7 Mon Sep 17 00:00:00 2001
From: Mario Gonzalez <gonzalemario@gmail.com>
Date: Thu, 6 Nov 2025 17:50:36 -0300
Subject: [PATCH v3 2/4] Remove brin/gin_tuple.h from tuplesort.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Because execnodes.h depends on struct definitions that were in genam.h,
which it no longer gets because of the aforementioned removal.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Co-author: Mario Gonzalez <gonzalemario@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
---
 contrib/pageinspect/gistfuncs.c                | 1 +
 src/backend/access/gin/gininsert.c             | 1 +
 src/backend/catalog/pg_attrdef.c               | 1 +
 src/backend/catalog/pg_largeobject.c           | 1 +
 src/backend/executor/execReplication.c         | 1 +
 src/backend/parser/parse_expr.c                | 1 +
 src/backend/replication/logical/relation.c     | 1 +
 src/backend/replication/logical/sequencesync.c | 1 +
 src/backend/statistics/attribute_stats.c       | 1 +
 src/backend/statistics/stat_utils.c            | 1 +
 src/include/nodes/execnodes.h                  | 1 +
 src/include/utils/tuplesort.h                  | 5 +++--
 12 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.c
index 60a4b240302..e7759488c36 100644
--- a/contrib/pageinspect/gistfuncs.c
+++ b/contrib/pageinspect/gistfuncs.c
@@ -9,6 +9,7 @@
  */
 #include "postgres.h"
 
+#include "access/genam.h"
 #include "access/gist.h"
 #include "access/htup.h"
 #include "access/htup_details.h"
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index c08ea927ac5..d5332920e8f 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -33,6 +33,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/builtins.h"
+#include "utils/typcache.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index b62f19bb803..24815090d3d 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -14,6 +14,7 @@
  */
 #include "postgres.h"
 
+#include "access/genam.h"
 #include "access/htup_details.h"
 #include "access/relation.h"
 #include "access/table.h"
diff --git a/src/backend/catalog/pg_largeobject.c b/src/backend/catalog/pg_largeobject.c
index 0f14ea198de..0e1dd22d908 100644
--- a/src/backend/catalog/pg_largeobject.c
+++ b/src/backend/catalog/pg_largeobject.c
@@ -14,6 +14,7 @@
  */
 #include "postgres.h"
 
+#include "access/genam.h"
 #include "access/htup_details.h"
 #include "access/table.h"
 #include "catalog/catalog.h"
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 173d2fe548d..72f2bff7708 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -14,6 +14,7 @@
 
 #include "postgres.h"
 
+#include "access/amapi.h"
 #include "access/commit_ts.h"
 #include "access/genam.h"
 #include "access/gist.h"
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9cba1272253..56826db4c26 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -38,6 +38,7 @@
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/timestamp.h"
+#include "utils/typcache.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c
index 2df910378dc..0b1d80b5b0f 100644
--- a/src/backend/replication/logical/relation.c
+++ b/src/backend/replication/logical/relation.c
@@ -29,6 +29,7 @@
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
+#include "utils/typcache.h"
 
 
 static MemoryContext LogicalRepRelMapContext = NULL;
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index e51cb51a8ba..c428c95c230 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -52,6 +52,7 @@
 #include "postgres.h"
 
 #include "access/table.h"
+#include "access/genam.h"
 #include "catalog/pg_sequence.h"
 #include "catalog/pg_subscription_rel.h"
 #include "commands/sequence.h"
diff --git a/src/backend/statistics/attribute_stats.c b/src/backend/statistics/attribute_stats.c
index a6b118a8d72..335514827b4 100644
--- a/src/backend/statistics/attribute_stats.c
+++ b/src/backend/statistics/attribute_stats.c
@@ -29,6 +29,7 @@
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
+#include "utils/typcache.h"
 
 /*
  * Positional argument numbers, names, and types for
diff --git a/src/backend/statistics/stat_utils.c b/src/backend/statistics/stat_utils.c
index 44969159ea8..9c680f1cb37 100644
--- a/src/backend/statistics/stat_utils.c
+++ b/src/backend/statistics/stat_utils.c
@@ -35,6 +35,7 @@
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/syscache.h"
+#include "utils/typcache.h"
 
 /* Default values assigned to new pg_statistic tuples. */
 #define DEFAULT_STATATT_NULL_FRAC      Float4GetDatum(0.0)	/* stanullfrac */
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 6fd8b6bfc06..83cd8bcd277 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -29,6 +29,7 @@
 #ifndef EXECNODES_H
 #define EXECNODES_H
 
+#include "access/skey.h"
 #include "access/tupconvert.h"
 #include "executor/instrument.h"
 #include "fmgr.h"
diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h
index a7e867f36b8..38f8493eb95 100644
--- a/src/include/utils/tuplesort.h
+++ b/src/include/utils/tuplesort.h
@@ -21,8 +21,6 @@
 #ifndef TUPLESORT_H
 #define TUPLESORT_H
 
-#include "access/brin_tuple.h"
-#include "access/gin_tuple.h"
 #include "access/itup.h"
 #include "executor/instrument_node.h"
 #include "executor/tuptable.h"
@@ -31,6 +29,9 @@
 #include "utils/relcache.h"
 #include "utils/sortsupport.h"
 
+/* We don't want this file to depend on AM-specific header files */
+typedef struct BrinTuple BrinTuple;
+typedef struct GinTuple GinTuple;
 
 /*
  * Tuplesortstate and Sharedsort are opaque types whose details are not
-- 
2.39.5

