Skip to content

Commit 17dce6f

Browse files
author
Maksim Milyutin
committed
Add fixes to build pathman with pg10
1 parent f7d62b5 commit 17dce6f

14 files changed

+521
-17
lines changed

src/compat/pg_compat.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
107107

108108
if (proparallel != PROPARALLEL_SAFE)
109109
return;
110+
#if PG_VERSION_NUM >= 100000
111+
if (!is_parallel_safe(root, (Node *) rte->tablesample->args))
112+
#else
110113
if (has_parallel_hazard((Node *) rte->tablesample->args,
111114
false))
115+
#endif
112116
return;
113117
}
114118

@@ -161,13 +165,21 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
161165

162166
case RTE_FUNCTION:
163167
/* Check for parallel-restricted functions. */
168+
#if PG_VERSION_NUM >= 100000
169+
if (!is_parallel_safe(root, (Node *) rte->functions))
170+
#else
164171
if (has_parallel_hazard((Node *) rte->functions, false))
172+
#endif
165173
return;
166174
break;
167175

168176
case RTE_VALUES:
169177
/* Check for parallel-restricted functions. */
178+
#if PG_VERSION_NUM >= 100000
179+
if (!is_parallel_safe(root, (Node *) rte->values_lists))
180+
#else
170181
if (has_parallel_hazard((Node *) rte->values_lists, false))
182+
#endif
171183
return;
172184
break;
173185

@@ -181,6 +193,9 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
181193
* executed only once.
182194
*/
183195
return;
196+
197+
default:
198+
;
184199
}
185200

186201
/*
@@ -192,14 +207,22 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
192207
* outer join clauses work correctly. It would likely break equivalence
193208
* classes, too.
194209
*/
210+
#if PG_VERSION_NUM >= 100000
211+
if (!is_parallel_safe(root, (Node *) rel->baserestrictinfo))
212+
#else
195213
if (has_parallel_hazard((Node *) rel->baserestrictinfo, false))
214+
#endif
196215
return;
197216

198217
/*
199218
* Likewise, if the relation's outputs are not parallel-safe, give up.
200219
* (Usually, they're just Vars, but sometimes they're not.)
201220
*/
221+
#if PG_VERSION_NUM >= 100000
222+
if (!is_parallel_safe(root, (Node *) rel->reltarget->exprs))
223+
#else
202224
if (has_parallel_hazard((Node *) rel->reltarget->exprs, false))
225+
#endif
203226
return;
204227

205228
/* We have a winner. */
@@ -211,6 +234,22 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
211234
* create_plain_partial_paths
212235
* Build partial access paths for parallel scan of a plain relation
213236
*/
237+
#if PG_VERSION_NUM >= 100000
238+
void
239+
create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
240+
{
241+
int parallel_workers;
242+
243+
parallel_workers = compute_parallel_worker(rel, rel->pages, -1);
244+
245+
/* If any limit was set to zero, the user doesn't want a parallel scan. */
246+
if (parallel_workers <= 0)
247+
return;
248+
249+
/* Add an unordered partial path based on a parallel sequential scan. */
250+
add_partial_path(rel, create_seqscan_path(root, rel, NULL, parallel_workers));
251+
}
252+
#else
214253
void
215254
create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
216255
{
@@ -267,6 +306,7 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
267306
/* Add an unordered partial path based on a parallel sequential scan. */
268307
add_partial_path(rel, create_seqscan_path(root, rel, NULL, parallel_workers));
269308
}
309+
#endif
270310

271311
/*
272312
* Examine contents of MemoryContext.

src/hooks.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ pathman_join_pathlist_hook(PlannerInfo *root,
210210
return;
211211

212212

213+
#if PG_VERSION_NUM >= 100000
214+
initial_cost_nestloop(root, &workspace, jointype,
215+
outer, inner, /* built paths */
216+
extra);
217+
218+
nest_path = create_nestloop_path(root, joinrel, jointype, &workspace,
219+
extra, outer, inner,
220+
extra->restrictlist,
221+
build_join_pathkeys(root, joinrel,
222+
jointype,
223+
outer->pathkeys),
224+
required_nestloop);
225+
#else
213226
initial_cost_nestloop(root, &workspace, jointype,
214227
outer, inner, /* built paths */
215228
extra->sjinfo, &extra->semifactors);
@@ -221,6 +234,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
221234
jointype,
222235
outer->pathkeys),
223236
required_nestloop);
237+
#endif
224238

225239
/* Discard all clauses that are to be evaluated by 'inner' */
226240
foreach (rinfo_lc, extra->restrictlist)
@@ -752,6 +766,71 @@ pathman_relcache_hook(Datum arg, Oid relid)
752766
/*
753767
* Utility function invoker hook.
754768
*/
769+
#if PG_VERSION_NUM >= 100000
770+
void
771+
pathman_process_utility_hook(PlannedStmt *pstmt,
772+
const char *queryString,
773+
ProcessUtilityContext context,
774+
ParamListInfo params,
775+
QueryEnvironment *queryEnv,
776+
DestReceiver *dest, char *completionTag)
777+
{
778+
Node *parsetree = pstmt->utilityStmt;
779+
780+
if (IsPathmanReady())
781+
{
782+
Oid relation_oid;
783+
PartType part_type;
784+
AttrNumber attr_number;
785+
786+
/* Override standard COPY statement if needed */
787+
if (is_pathman_related_copy(parsetree))
788+
{
789+
uint64 processed;
790+
791+
/* Handle our COPY case (and show a special cmd name) */
792+
PathmanDoCopy((CopyStmt *) parsetree, queryString, &processed);
793+
if (completionTag)
794+
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
795+
"PATHMAN COPY " UINT64_FORMAT, processed);
796+
797+
return; /* don't call standard_ProcessUtility() or hooks */
798+
}
799+
800+
/* Override standard RENAME statement if needed */
801+
else if (is_pathman_related_table_rename(parsetree,
802+
&relation_oid,
803+
&attr_number))
804+
PathmanRenameConstraint(relation_oid,
805+
attr_number,
806+
(const RenameStmt *) parsetree);
807+
808+
/* Override standard ALTER COLUMN TYPE statement if needed */
809+
else if (is_pathman_related_alter_column_type(parsetree,
810+
&relation_oid,
811+
&attr_number,
812+
&part_type) &&
813+
part_type == PT_HASH)
814+
ereport(ERROR,
815+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
816+
errmsg("cannot change type of column \"%s\""
817+
" of table \"%s\" partitioned by HASH",
818+
get_attname(relation_oid, attr_number),
819+
get_rel_name(relation_oid))));
820+
}
821+
822+
/* Call hooks set by other extensions if needed */
823+
if (process_utility_hook_next)
824+
process_utility_hook_next(pstmt, queryString,
825+
context, params, queryEnv,
826+
dest, completionTag);
827+
/* Else call internal implementation */
828+
else
829+
standard_ProcessUtility(pstmt, queryString,
830+
context, params, queryEnv,
831+
dest, completionTag);
832+
}
833+
#else
755834
void
756835
pathman_process_utility_hook(Node *parsetree,
757836
const char *queryString,
@@ -813,3 +892,4 @@ pathman_process_utility_hook(Node *parsetree,
813892
context, params,
814893
dest, completionTag);
815894
}
895+
#endif

src/include/compat/pg_compat.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,15 @@
3434
* ----------
3535
*/
3636

37-
#if PG_VERSION_NUM >= 90600
3837

39-
/* adjust_appendrel_attrs() */
40-
#define adjust_rel_targetlist_compat(root, dst_rel, src_rel, appinfo) \
41-
do { \
42-
(dst_rel)->reltarget->exprs = (List *) \
43-
adjust_appendrel_attrs((root), \
44-
(Node *) (src_rel)->reltarget->exprs, \
45-
(appinfo)); \
46-
} while (0)
38+
/* create_append_path() */
39+
#if PG_VERSION_NUM >= 100000
4740

41+
#define create_append_path_compat(rel, subpaths, required_outer, parallel_workers) \
42+
create_append_path((rel), (subpaths), (required_outer), (parallel_workers), NULL)
43+
44+
#elif PG_VERSION_NUM >= 90600
4845

49-
/* create_append_path() */
5046
#ifndef PGPRO_VERSION
5147
#define create_append_path_compat(rel, subpaths, required_outer, parallel_workers) \
5248
create_append_path((rel), (subpaths), (required_outer), (parallel_workers))
@@ -56,6 +52,25 @@
5652
false, NIL, (parallel_workers))
5753
#endif
5854

55+
#else /* for v9.5 */
56+
57+
#define create_append_path_compat(rel, subpaths, required_outer, parallel_workers) \
58+
create_append_path((rel), (subpaths), (required_outer))
59+
60+
#endif
61+
62+
63+
#if PG_VERSION_NUM >= 90600
64+
65+
/* adjust_appendrel_attrs() */
66+
#define adjust_rel_targetlist_compat(root, dst_rel, src_rel, appinfo) \
67+
do { \
68+
(dst_rel)->reltarget->exprs = (List *) \
69+
adjust_appendrel_attrs((root), \
70+
(Node *) (src_rel)->reltarget->exprs, \
71+
(appinfo)); \
72+
} while (0)
73+
5974

6075
/* check_index_predicates() */
6176
#define check_index_predicates_compat(rool, rel) \
@@ -120,11 +135,6 @@ extern void set_rel_consider_parallel(PlannerInfo *root,
120135
} while (0)
121136

122137

123-
/* create_append_path() */
124-
#define create_append_path_compat(rel, subpaths, required_outer, parallel_workers) \
125-
create_append_path((rel), (subpaths), (required_outer))
126-
127-
128138
/* check_partial_indexes() */
129139
#define check_index_predicates_compat(rool, rel) \
130140
check_partial_indexes((root), (rel))

src/include/hooks.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,22 @@ void pathman_shmem_startup_hook(void);
5353

5454
void pathman_relcache_hook(Datum arg, Oid relid);
5555

56+
#if PG_VERSION_NUM >= 100000
57+
void pathman_process_utility_hook(PlannedStmt *pstmt,
58+
const char *queryString,
59+
ProcessUtilityContext context,
60+
ParamListInfo params,
61+
QueryEnvironment *queryEnv,
62+
DestReceiver *dest,
63+
char *completionTag);
64+
#else
5665
void pathman_process_utility_hook(Node *parsetree,
5766
const char *queryString,
5867
ProcessUtilityContext context,
5968
ParamListInfo params,
6069
DestReceiver *dest,
6170
char *completionTag);
71+
#endif
6272

6373

6474
#endif /* PATHMAN_HOOKS_H */

src/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ static bool read_opexpr_const(const OpExpr *opexpr,
8686
const AttrNumber part_attno,
8787
Datum *value);
8888

89+
#if PG_VERSION_NUM < 100000
8990
static int oid_cmp(const void *p1, const void *p2);
91+
#endif
9092

9193

9294
/* Validate SQL facade */
@@ -1128,6 +1130,7 @@ validate_hash_constraint(const Expr *expr,
11281130
return false;
11291131
}
11301132

1133+
#if PG_VERSION_NUM < 100000
11311134
/* needed for find_inheritance_children_array() function */
11321135
static int
11331136
oid_cmp(const void *p1, const void *p2)
@@ -1141,6 +1144,7 @@ oid_cmp(const void *p1, const void *p2)
11411144
return 1;
11421145
return 0;
11431146
}
1147+
#endif
11441148

11451149

11461150
/* Parse cstring and build uint32 representing the version */

src/nodes_common.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ tlist_is_var_subset(List *a, List *b)
175175
if (!IsA(te->expr, Var) && !IsA(te->expr, RelabelType))
176176
continue;
177177

178+
#if PG_VERSION_NUM >= 100000
179+
if (!tlist_member_ignore_relabel(te->expr, a))
180+
return true;
181+
#else
178182
if (!tlist_member_ignore_relabel((Node *) te->expr, a))
179183
return true;
184+
#endif
180185
}
181186

182187
return false;
@@ -583,7 +588,9 @@ create_append_scan_state_common(CustomScan *node,
583588
void
584589
begin_append_common(CustomScanState *node, EState *estate, int eflags)
585590
{
591+
#if PG_VERSION_NUM < 100000
586592
node->ss.ps.ps_TupFromTlist = false;
593+
#endif
587594
}
588595

589596
TupleTableSlot *
@@ -599,13 +606,15 @@ exec_append_common(CustomScanState *node,
599606
for (;;)
600607
{
601608
/* Fetch next tuple if we're done with Projections */
609+
#if PG_VERSION_NUM < 100000
602610
if (!node->ss.ps.ps_TupFromTlist)
603611
{
604612
fetch_next_tuple(node); /* use specific callback */
605613

606614
if (TupIsNull(scan_state->slot))
607615
return NULL;
608616
}
617+
#endif
609618

610619
if (node->ss.ps.ps_ProjInfo)
611620
{
@@ -615,8 +624,13 @@ exec_append_common(CustomScanState *node,
615624
ResetExprContext(node->ss.ps.ps_ExprContext);
616625

617626
node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = scan_state->slot;
627+
#if PG_VERSION_NUM >= 100000
628+
result = ExecProject(node->ss.ps.ps_ProjInfo);
629+
#else
618630
result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone);
631+
#endif
619632

633+
#if PG_VERSION_NUM < 100000
620634
if (isDone != ExprEndResult)
621635
{
622636
node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult);
@@ -625,6 +639,10 @@ exec_append_common(CustomScanState *node,
625639
}
626640
else
627641
node->ss.ps.ps_TupFromTlist = false;
642+
#else
643+
if (isDone != ExprEndResult)
644+
return result;
645+
#endif
628646
}
629647
else
630648
return scan_state->slot;

0 commit comments

Comments
 (0)