From b9d9c4d951e69d8632147f76a98f58e321dd9e1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@alvh.no-ip.org>
Date: Tue, 19 Nov 2024 23:15:50 +0100
Subject: [PATCH] Avoid including tableam.h and xlogreader.h into nbtree.h

---
 contrib/btree_gist/btree_bool.c               | 1 +
 contrib/btree_gist/btree_cash.c               | 1 +
 contrib/btree_gist/btree_date.c               | 1 +
 contrib/btree_gist/btree_enum.c               | 1 +
 contrib/btree_gist/btree_float4.c             | 1 +
 contrib/btree_gist/btree_float8.c             | 1 +
 contrib/btree_gist/btree_inet.c               | 1 +
 contrib/btree_gist/btree_int2.c               | 1 +
 contrib/btree_gist/btree_int4.c               | 1 +
 contrib/btree_gist/btree_int8.c               | 1 +
 contrib/btree_gist/btree_interval.c           | 1 +
 contrib/btree_gist/btree_macaddr.c            | 1 +
 contrib/btree_gist/btree_macaddr8.c           | 1 +
 contrib/btree_gist/btree_oid.c                | 1 +
 contrib/btree_gist/btree_time.c               | 1 +
 contrib/btree_gist/btree_ts.c                 | 1 +
 contrib/btree_gist/btree_utils_var.c          | 1 +
 contrib/btree_gist/btree_uuid.c               | 1 +
 src/backend/access/nbtree/nbtdedup.c          | 1 +
 src/backend/access/nbtree/nbtinsert.c         | 1 +
 src/backend/access/nbtree/nbtpreprocesskeys.c | 2 ++
 src/backend/access/nbtree/nbtsort.c           | 1 +
 src/backend/access/nbtree/nbtsplitloc.c       | 1 +
 src/backend/access/nbtree/nbtutils.c          | 3 +++
 src/backend/utils/sort/tuplesortvariants.c    | 1 +
 src/include/access/nbtree.h                   | 6 +++---
 26 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/contrib/btree_gist/btree_bool.c b/contrib/btree_gist/btree_bool.c
index 1127597bb60..8282055ebca 100644
--- a/contrib/btree_gist/btree_bool.c
+++ b/contrib/btree_gist/btree_bool.c
@@ -6,6 +6,7 @@
 #include "btree_gist.h"
 #include "btree_utils_num.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct boolkey
 {
diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c
index 01c8d5a5f40..8228d2871e9 100644
--- a/contrib/btree_gist/btree_cash.c
+++ b/contrib/btree_gist/btree_cash.c
@@ -8,6 +8,7 @@
 #include "common/int.h"
 #include "utils/cash.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_date.c b/contrib/btree_gist/btree_date.c
index c008dc61ba5..da248a29aaa 100644
--- a/contrib/btree_gist/btree_date.c
+++ b/contrib/btree_gist/btree_date.c
@@ -8,6 +8,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/date.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_enum.c b/contrib/btree_gist/btree_enum.c
index 83c95c7bb04..23253770ea1 100644
--- a/contrib/btree_gist/btree_enum.c
+++ b/contrib/btree_gist/btree_enum.c
@@ -9,6 +9,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/fmgroids.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 /* enums are really Oids, so we just use the same structure */
 
diff --git a/contrib/btree_gist/btree_float4.c b/contrib/btree_gist/btree_float4.c
index bec026a923a..21eccf1a9ab 100644
--- a/contrib/btree_gist/btree_float4.c
+++ b/contrib/btree_gist/btree_float4.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "utils/float.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct float4key
 {
diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c
index 43e7cde2b69..8e7c78877e7 100644
--- a/contrib/btree_gist/btree_float8.c
+++ b/contrib/btree_gist/btree_float8.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "utils/float.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct float8key
 {
diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c
index 8b23853bafb..460ef6e4a7d 100644
--- a/contrib/btree_gist/btree_inet.c
+++ b/contrib/btree_gist/btree_inet.c
@@ -8,6 +8,7 @@
 #include "catalog/pg_type.h"
 #include "utils/builtins.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct inetkey
 {
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index 33eccdedd70..d9529f760a0 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "common/int.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct int16key
 {
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index a82cee9a58a..9e2e67a0c28 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -6,6 +6,7 @@
 #include "btree_utils_num.h"
 #include "common/int.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct int32key
 {
diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c
index f0c56e01726..ac710f96677 100644
--- a/contrib/btree_gist/btree_int8.c
+++ b/contrib/btree_gist/btree_int8.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "common/int.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct int64key
 {
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c
index b5e365c6e09..61d25b10214 100644
--- a/contrib/btree_gist/btree_interval.c
+++ b/contrib/btree_gist/btree_interval.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "utils/fmgrprotos.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 #include "utils/timestamp.h"
 
 typedef struct
diff --git a/contrib/btree_gist/btree_macaddr.c b/contrib/btree_gist/btree_macaddr.c
index 3b2f26719d5..5fac3b66fda 100644
--- a/contrib/btree_gist/btree_macaddr.c
+++ b/contrib/btree_gist/btree_macaddr.c
@@ -8,6 +8,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/inet.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_macaddr8.c b/contrib/btree_gist/btree_macaddr8.c
index f2b104617e6..dd49f377db5 100644
--- a/contrib/btree_gist/btree_macaddr8.c
+++ b/contrib/btree_gist/btree_macaddr8.c
@@ -8,6 +8,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/inet.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c
index ffe0d7983e4..41fb3872819 100644
--- a/contrib/btree_gist/btree_oid.c
+++ b/contrib/btree_gist/btree_oid.c
@@ -6,6 +6,7 @@
 #include "btree_gist.h"
 #include "btree_utils_num.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index 1dba95057ba..49c2cae522b 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -8,6 +8,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/date.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 #include "utils/timestamp.h"
 
 typedef struct
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index eb899c4d213..7173124d574 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -11,6 +11,7 @@
 #include "utils/timestamp.h"
 #include "utils/float.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 
 typedef struct
 {
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index d9df2356cd1..fb466e5aa32 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -11,6 +11,7 @@
 #include "btree_utils_var.h"
 #include "mb/pg_wchar.h"
 #include "utils/rel.h"
+#include "varatt.h"
 
 /* used for key sorting */
 typedef struct
diff --git a/contrib/btree_gist/btree_uuid.c b/contrib/btree_gist/btree_uuid.c
index 23a307a6a71..873d77dd8f5 100644
--- a/contrib/btree_gist/btree_uuid.c
+++ b/contrib/btree_gist/btree_uuid.c
@@ -7,6 +7,7 @@
 #include "btree_utils_num.h"
 #include "port/pg_bswap.h"
 #include "utils/sortsupport.h"
+#include "utils/rel.h"
 #include "utils/uuid.h"
 
 typedef struct
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index 08884116aec..ab0b6946cb0 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,6 +16,7 @@
 
 #include "access/nbtree.h"
 #include "access/nbtxlog.h"
+#include "access/tableam.h"
 #include "access/xloginsert.h"
 #include "miscadmin.h"
 #include "utils/rel.h"
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index aa82cede30a..be60781fc98 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -17,6 +17,7 @@
 
 #include "access/nbtree.h"
 #include "access/nbtxlog.h"
+#include "access/tableam.h"
 #include "access/transam.h"
 #include "access/xloginsert.h"
 #include "common/int.h"
diff --git a/src/backend/access/nbtree/nbtpreprocesskeys.c b/src/backend/access/nbtree/nbtpreprocesskeys.c
index 21c519cd108..936b93f157a 100644
--- a/src/backend/access/nbtree/nbtpreprocesskeys.c
+++ b/src/backend/access/nbtree/nbtpreprocesskeys.c
@@ -16,11 +16,13 @@
 #include "postgres.h"
 
 #include "access/nbtree.h"
+#include "access/relscan.h"
 #include "common/int.h"
 #include "lib/qunique.h"
 #include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/rel.h"
 
 typedef struct BTScanKeyPreproc
 {
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 9d70e89c1f3..8828a7a8f89 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -44,6 +44,7 @@
 #include "access/parallel.h"
 #include "access/relscan.h"
 #include "access/table.h"
+#include "access/tableam.h"
 #include "access/xact.h"
 #include "catalog/index.h"
 #include "commands/progress.h"
diff --git a/src/backend/access/nbtree/nbtsplitloc.c b/src/backend/access/nbtree/nbtsplitloc.c
index e6c9aaa0454..b88c396195a 100644
--- a/src/backend/access/nbtree/nbtsplitloc.c
+++ b/src/backend/access/nbtree/nbtsplitloc.c
@@ -15,6 +15,7 @@
 #include "postgres.h"
 
 #include "access/nbtree.h"
+#include "access/tableam.h"
 #include "common/int.h"
 
 typedef enum
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 9aed207995f..edfea2acaff 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -19,10 +19,13 @@
 
 #include "access/nbtree.h"
 #include "access/reloptions.h"
+#include "access/relscan.h"
 #include "commands/progress.h"
 #include "miscadmin.h"
 #include "utils/datum.h"
 #include "utils/lsyscache.h"
+#include "utils/rel.h"
+
 
 #define LOOK_AHEAD_REQUIRED_RECHECKS 	3
 #define LOOK_AHEAD_DEFAULT_DISTANCE 	5
diff --git a/src/backend/utils/sort/tuplesortvariants.c b/src/backend/utils/sort/tuplesortvariants.c
index 5f70e8dddac..f5c3ec13f4c 100644
--- a/src/backend/utils/sort/tuplesortvariants.c
+++ b/src/backend/utils/sort/tuplesortvariants.c
@@ -31,6 +31,7 @@
 #include "utils/datum.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
+#include "utils/rel.h"
 #include "utils/tuplesort.h"
 
 
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index e709d2e0afe..9ab467cb8fd 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -17,9 +17,8 @@
 #include "access/amapi.h"
 #include "access/itup.h"
 #include "access/sdir.h"
-#include "access/tableam.h"
-#include "access/xlogreader.h"
 #include "catalog/pg_am_d.h"
+#include "catalog/pg_class.h"
 #include "catalog/pg_index.h"
 #include "lib/stringinfo.h"
 #include "storage/bufmgr.h"
@@ -1285,9 +1284,10 @@ extern void _bt_pageinit(Page page, Size size);
 extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
 								OffsetNumber *deletable, int ndeletable,
 								BTVacuumPosting *updatable, int nupdatable);
+struct TM_IndexDeleteOp;		/* avoid including tableam.h here */
 extern void _bt_delitems_delete_check(Relation rel, Buffer buf,
 									  Relation heapRel,
-									  TM_IndexDeleteOp *delstate);
+									  struct TM_IndexDeleteOp *delstate);
 extern void _bt_pagedel(Relation rel, Buffer leafbuf, BTVacState *vstate);
 extern void _bt_pendingfsm_init(Relation rel, BTVacState *vstate,
 								bool cleanuponly);
-- 
2.39.5

