From 63c32c0d81083b3f527c780656602f333658e8e0 Mon Sep 17 00:00:00 2001 From: Mehmet Yilmaz Date: Tue, 13 May 2025 15:19:36 +0000 Subject: [PATCH] Refactor compatibility handling for PostgreSQL versions in various files --- src/backend/columnar/columnar_metadata.c | 2 - .../distributed/deparser/ruleutils_18.c | 3 +- .../distributed/planner/multi_explain.c | 2 +- src/backend/distributed/test/fake_fdw.c | 22 ++--- src/include/pg_version_compat.h | 88 ++++++------------- 5 files changed, 36 insertions(+), 81 deletions(-) diff --git a/src/backend/columnar/columnar_metadata.c b/src/backend/columnar/columnar_metadata.c index 6d95f000a..301596b26 100644 --- a/src/backend/columnar/columnar_metadata.c +++ b/src/backend/columnar/columnar_metadata.c @@ -1743,8 +1743,6 @@ create_estate_for_relation(Relation rel) #if PG_VERSION_NUM >= PG_VERSION_16 List *perminfos = NIL; addRTEPermissionInfo(&perminfos, rte); -#else - List *perminfos = NIL; /* not used on PG 15 */ #endif /* Initialize the range table, with the right signature for each PG version */ diff --git a/src/backend/distributed/deparser/ruleutils_18.c b/src/backend/distributed/deparser/ruleutils_18.c index d254aa0a4..c597ef793 100644 --- a/src/backend/distributed/deparser/ruleutils_18.c +++ b/src/backend/distributed/deparser/ruleutils_18.c @@ -1211,7 +1211,7 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte, if (rte->rtekind == RTE_FUNCTION && rte->functions != NIL) { /* Since we're not creating Vars, rtindex etc. don't matter */ - expandRTE(rte, 1, 0, -1, true /* include dropped */ , + expandRTE(rte, 1, 0, VAR_RETURNING_DEFAULT, -1, true /* include dropped */ , &colnames, NULL); } else @@ -4611,6 +4611,7 @@ get_name_for_var_field(Var *var, int fieldno, case RTE_VALUES: case RTE_NAMEDTUPLESTORE: case RTE_RESULT: + case RTE_GROUP: /* * This case should not occur: a column of a table or values list diff --git a/src/backend/distributed/planner/multi_explain.c b/src/backend/distributed/planner/multi_explain.c index 295221b03..9972adfee 100644 --- a/src/backend/distributed/planner/multi_explain.c +++ b/src/backend/distributed/planner/multi_explain.c @@ -2315,7 +2315,7 @@ ExplainWorkerPlan(PlannedStmt *plannedstmt, DestReceiver *dest, ExplainState *es if (es->costs) ExplainPrintJITSummary(es, queryDesc); -#if PG_VERSION_NUM >= PG_VERSION_17 && PG_VERSION_NUM < PG_VERSION_1 +#if PG_VERSION_NUM >= PG_VERSION_17 && PG_VERSION_NUM < PG_VERSION_18 if (es->serialize != EXPLAIN_SERIALIZE_NONE) { /* the SERIALIZE option requires its own tuple receiver */ diff --git a/src/backend/distributed/test/fake_fdw.c b/src/backend/distributed/test/fake_fdw.c index fdf673154..90b205b1e 100644 --- a/src/backend/distributed/test/fake_fdw.c +++ b/src/backend/distributed/test/fake_fdw.c @@ -91,23 +91,11 @@ FakeGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) Cost startup_cost = 0; Cost total_cost = startup_cost + baserel->rows; - add_path(baserel, - (Path *) create_foreignscan_path_compat( - root, - baserel, - baserel->reltarget, /* ← PathTarget* is the rel’s reltarget */ - baserel->rows, - 0, /* ← disabled_nodes (only used in PG18+) */ - startup_cost, - total_cost, - NIL, /* pathkeys */ - NULL, /* required_outer */ - NULL, /* fdw_outerpath */ - NIL, /* fdw_restrictinfo (PG18+) */ - NIL, /* fdw_private */ - NIL /* fdw_scan_tlist (PG15–17) */ - ) - ); + add_path(baserel, (Path *) create_foreignscan_path_compat(root, baserel, NULL, + baserel->rows, + startup_cost, total_cost, + NIL, + NULL, NULL, NIL, NIL)); } diff --git a/src/include/pg_version_compat.h b/src/include/pg_version_compat.h index 2a04fd3bb..8727b0768 100644 --- a/src/include/pg_version_compat.h +++ b/src/include/pg_version_compat.h @@ -384,70 +384,34 @@ getStxstattarget_compat(HeapTuple tup) #define matched_compat(a) (a->matchKind == MERGE_WHEN_MATCHED) -#include "nodes/pg_list.h" /* for List */ -#include "nodes/plannodes.h" /* for ForeignScan */ -#include "optimizer/pathnode.h" /* for create_foreignscan_path, ForeignPath */ +#include "nodes/bitmapset.h" /* for Relids */ +#include "nodes/pg_list.h" /* for List */ +#include "optimizer/pathnode.h" /* for create_foreignscan_path() */ -/* - * A single entry point for Citus code to build ForeignPath - * using the *full* superset of parameters: - * - * root, rel, target, rows, - * disabled_nodes, startup_cost, total_cost, - * pathkeys, required_outer, - * fdw_outerpath, fdw_restrictinfo, - * fdw_private, fdw_scan_tlist - */ -static inline ForeignPath * -create_foreignscan_path_compat(PlannerInfo *root, - RelOptInfo *rel, - PathTarget *target, - double rows, - int disabled_nodes, - Cost startup_cost, - Cost total_cost, - List *pathkeys, - Relids required_outer, - Path *fdw_outerpath, - List *fdw_restrictinfo, - List *fdw_private, - List *fdw_scan_tlist) -{ #if PG_VERSION_NUM >= PG_VERSION_18 - - /* PG 18+ signature: 12 args */ - return create_foreignscan_path( - root, - rel, - target, - rows, - disabled_nodes, - startup_cost, - total_cost, - pathkeys, - required_outer, - fdw_outerpath, - fdw_restrictinfo, - fdw_private - ); +#define create_foreignscan_path_compat(a, b, c, d, e, f, g, h, i, j, k) \ + create_foreignscan_path( \ + (a), /* root */ \ + (b), /* rel */ \ + (c), /* target */ \ + (d), /* rows */ \ + 0, /* disabled_nodes */ \ + (e), /* startup_cost */ \ + (f), /* total_cost */ \ + (g), /* pathkeys */ \ + (h), /* required_outer */ \ + (i), /* fdw_outerpath */ \ + (j), /* fdw_restrictinfo*/ \ + (k) /* fdw_private */ \ + ) #else - - /* PG 17- signature: 11 args */ - return create_foreignscan_path( - root, - rel, - target, - rows, - startup_cost, - total_cost, - pathkeys, - required_outer, - fdw_outerpath, - fdw_private, - fdw_scan_tlist - ); +#define create_foreignscan_path_compat(a, b, c, d, e, f, g, h, i, j, k) \ + create_foreignscan_path( \ + (a), (b), (c), (d), \ + (e), (f), \ + (g), (h), (i), (j), (k) \ + ) #endif -} #define getProcNo_compat(a) (a->vxid.procNumber) @@ -483,6 +447,10 @@ getStxstattarget_compat(HeapTuple tup) #define matched_compat(a) (a->matched) +#define create_foreignscan_path_compat(a, b, c, d, e, f, g, h, i, j, \ + k) create_foreignscan_path(a, b, c, d, e, f, g, h, \ + i, k) + #define getProcNo_compat(a) (a->pgprocno) #define getLxid_compat(a) (a->lxid)