Skip to content

Commit 4c62e4a

Browse files
committed
Make compat version of pg_analyze_and_rewrite
1 parent 72e3c00 commit 4c62e4a

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/include/compat/pg_compat.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ extern void create_plain_partial_paths(PlannerInfo *root,
197197
#endif
198198

199199

200+
/*
201+
* get_rel_persistence()
202+
*/
203+
#if PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90600
204+
char get_rel_persistence(Oid relid);
205+
#endif
206+
207+
200208
/*
201209
* InitResultRelInfo
202210
*
@@ -241,6 +249,24 @@ void McxtStatsInternal(MemoryContext context, int level,
241249
#endif
242250

243251

252+
/*
253+
* pg_analyze_and_rewrite
254+
*
255+
* for v10 cast first arg to RawStmt type
256+
*/
257+
#if PG_VERSION_NUM >= 100000
258+
#define pg_analyze_and_rewrite_compat(parsetree, query_string, paramTypes, \
259+
numParams, queryEnv) \
260+
pg_analyze_and_rewrite((RawStmt *) (parsetree), (query_string), \
261+
(paramTypes), (numParams), (queryEnv))
262+
#elif PG_VERSION_NUM >= 90500
263+
#define pg_analyze_and_rewrite_compat(parsetree, query_string, paramTypes, \
264+
numParams, queryEnv) \
265+
pg_analyze_and_rewrite((Node *) (parsetree), (query_string), \
266+
(paramTypes), (numParams))
267+
#endif
268+
269+
244270
/*
245271
* ProcessUtility
246272
*
@@ -299,14 +325,6 @@ extern void set_rel_consider_parallel(PlannerInfo *root,
299325
#endif
300326

301327

302-
/*
303-
* get_rel_persistence()
304-
*/
305-
#if PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90600
306-
char get_rel_persistence(Oid relid);
307-
#endif
308-
309-
310328
/*
311329
* -------------
312330
* Common code

src/relation_info.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,7 @@ parse_partitioning_expression(const Oid relid,
589589
*query_string_out = query_string;
590590

591591
if (parsetree_out)
592-
#if PG_VERSION_NUM >= 100000
593592
*parsetree_out = (Node *) linitial(parsetree_list);
594-
#else
595-
*parsetree_out = (Node *) select_stmt;
596-
#endif
597593

598594
return ((ResTarget *) linitial(select_stmt->targetList))->val;
599595
}
@@ -669,11 +665,9 @@ cook_partitioning_expression(const Oid relid,
669665
old_mcxt = MemoryContextSwitchTo(parse_mcxt);
670666

671667
/* This will fail with elog in case of wrong expression */
672-
#if PG_VERSION_NUM >= 100000
673-
querytree_list = pg_analyze_and_rewrite((RawStmt *) parsetree/* stub value */, query_string, NULL, 0, NULL);
674-
#else
675-
querytree_list = pg_analyze_and_rewrite(parsetree, query_string, NULL, 0);
676-
#endif
668+
querytree_list = pg_analyze_and_rewrite_compat(parsetree, query_string,
669+
NULL, 0, NULL);
670+
677671
if (list_length(querytree_list) != 1)
678672
elog(ERROR, "partitioning expression produced more than 1 query");
679673

0 commit comments

Comments
 (0)