Skip to content

Commit 5aab5f1

Browse files
author
Maksim Milyutin
committed
Add backward compatibility with version 9.5
1 parent 6ce6354 commit 5aab5f1

File tree

6 files changed

+237
-95
lines changed

6 files changed

+237
-95
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
MODULE_big = pg_pathman
44
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o src/runtimeappend.o \
55
src/runtime_merge_append.o src/pg_pathman.o src/dsm_array.o src/rangeset.o src/pl_funcs.o \
6-
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o $(WIN32RES)
6+
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o src/pg_compat.o \
7+
$(WIN32RES)
78

89
EXTENSION = pg_pathman
910
EXTVERSION = 1.0

src/hooks.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11+
#include "pg_compat.h"
12+
1113
#include "hooks.h"
1214
#include "init.h"
1315
#include "partition_filter.h"
@@ -167,12 +169,13 @@ pathman_join_pathlist_hook(PlannerInfo *root,
167169
* Currently we use get_parameterized_joinrel_size() since
168170
* it works just fine, but this might change some day.
169171
*/
170-
nest_path->path.rows = get_parameterized_joinrel_size(root,
171-
joinrel,
172-
outer,
173-
inner,
174-
extra->sjinfo,
175-
filtered_joinclauses);
172+
nest_path->path.rows = get_parameterized_joinrel_size_compat(
173+
root,
174+
joinrel,
175+
outer,
176+
inner,
177+
extra->sjinfo,
178+
filtered_joinclauses);
176179

177180
/* Finally we can add the new NestLoop path */
178181
add_path(joinrel, (Path *) nest_path);
@@ -313,15 +316,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
313316
IndexRange irange = lfirst_irange(lc);
314317

315318
for (i = irange.ir_lower; i <= irange.ir_upper; i++)
316-
append_child_relation(root, rel, rti, rte, i, children[i], wrappers);
319+
append_child_relation(root, rel, rti, rte, i, children[i],
320+
wrappers);
317321
}
318322

319323
/* Clear old path list */
320324
list_free(rel->pathlist);
321325

322326
rel->pathlist = NIL;
323327
set_append_rel_pathlist(root, rel, rti, rte, pathkeyAsc, pathkeyDesc);
324-
set_append_rel_size(root, rel, rti, rte);
328+
set_append_rel_size_compat(root, rel, rti, rte);
325329

326330
/* No need to go further (both nodes are disabled), return */
327331
if (!(pg_pathman_enable_runtimeappend ||

src/pg_compat.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include "pg_compat.h"
2+
3+
#include "optimizer/pathnode.h"
4+
#include "port.h"
5+
#include "utils.h"
6+
7+
#include <math.h>
8+
9+
/*
10+
double
11+
get_parameterized_joinrel_size_compat(PlannerInfo *root, RelOptInfo *rel,
12+
Path *outer_path, Path *inner_path,
13+
SpecialJoinInfo *sjinfo,
14+
List *restrict_clauses)
15+
{
16+
#if PG_VERSION_NUM >= 90600
17+
return get_parameterized_joinrel_size(root, rel, outer_path, inner_path,
18+
sjinfo, restrict_clauses);
19+
#else
20+
return get_parameterized_joinrel_size(root, rel, outer_path->rows,
21+
inner_path->rows, sjinfo,
22+
#endif
23+
restrict_clauses);
24+
}
25+
*/
26+
27+
void
28+
set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel,
29+
Index rti, RangeTblEntry *rte)
30+
{
31+
double parent_rows = 0;
32+
double parent_size = 0;
33+
ListCell *l;
34+
35+
foreach(l, root->append_rel_list)
36+
{
37+
AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
38+
Index childRTindex,
39+
parentRTindex = rti;
40+
RelOptInfo *childrel;
41+
42+
/* append_rel_list contains all append rels; ignore others */
43+
if (appinfo->parent_relid != parentRTindex)
44+
continue;
45+
46+
childRTindex = appinfo->child_relid;
47+
48+
childrel = find_base_rel(root, childRTindex);
49+
Assert(childrel->reloptkind == RELOPT_OTHER_MEMBER_REL);
50+
51+
/*
52+
* Accumulate size information from each live child.
53+
*/
54+
Assert(childrel->rows > 0);
55+
56+
parent_rows += childrel->rows;
57+
#if PG_VERSION_NUM >= 90600
58+
parent_size += childrel->reltarget->width * childrel->rows;
59+
#else
60+
parent_size += childrel->width * childrel->rows;
61+
#endif
62+
}
63+
64+
rel->rows = parent_rows;
65+
#if PG_VERSION_NUM >= 90600
66+
rel->reltarget->width = rint(parent_size / parent_rows);
67+
#else
68+
rel->width = rint(parent_size / parent_rows);
69+
#endif
70+
rel->tuples = parent_rows;
71+
}
72+
73+
extern
74+
void copy_targetlist_compat(RelOptInfo *dest, RelOptInfo *rel)
75+
{
76+
ListCell *lc;
77+
78+
#if PG_VERSION_NUM >= 90600
79+
dest->reltarget->exprs = NIL;
80+
foreach(lc, rel->reltarget->exprs)
81+
#else
82+
dest->reltargetlist = NIL;
83+
foreach(lc, rel->reltargetlist)
84+
#endif
85+
{
86+
Node *new_target;
87+
Node *node;
88+
89+
node = (Node *) lfirst(lc);
90+
new_target = copyObject(node);
91+
change_varnos(new_target, rel->relid, dest->relid);
92+
#if PG_VERSION_NUM >= 90600
93+
dest->reltarget->exprs = lappend(dest->reltarget->exprs, new_target);
94+
#else
95+
dest->reltargetlist = lappend(dest->reltargetlist, new_target);
96+
#endif
97+
}
98+
}
99+
100+
#if PG_VERSION_NUM >= 90600
101+
/*
102+
* make_result
103+
* Build a Result plan node
104+
*/
105+
Result *
106+
make_result(List *tlist,
107+
Node *resconstantqual,
108+
Plan *subplan)
109+
{
110+
Result *node = makeNode(Result);
111+
Plan *plan = &node->plan;
112+
113+
plan->targetlist = tlist;
114+
plan->qual = NIL;
115+
plan->lefttree = subplan;
116+
plan->righttree = NULL;
117+
node->resconstantqual = resconstantqual;
118+
119+
return node;
120+
}
121+
#endif

src/pg_compat.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef PG_COMPAT_H
2+
#define PG_COMPAT_H
3+
4+
#include "postgres.h"
5+
6+
#include "nodes/relation.h"
7+
#include "nodes/pg_list.h"
8+
#include "optimizer/cost.h"
9+
#include "optimizer/paths.h"
10+
11+
/*
12+
extern double get_parameterized_joinrel_size_compat(PlannerInfo *root,
13+
RelOptInfo *rel,
14+
Path *outer_path,
15+
Path *inner_path,
16+
SpecialJoinInfo *sjinfo,
17+
List *restrict_clauses);
18+
*/
19+
extern void set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel,
20+
Index rti, RangeTblEntry *rte);
21+
extern void copy_targetlist_compat(RelOptInfo *dest, RelOptInfo *rel);
22+
23+
#if PG_VERSION_NUM >= 90600
24+
25+
#define get_parameterized_joinrel_size_compat(root, \
26+
rel, \
27+
outer_path, \
28+
inner_path, \
29+
sjinfo, \
30+
restrict_clauses) \
31+
get_parameterized_joinrel_size(root, \
32+
rel, \
33+
outer_path, \
34+
inner_path, \
35+
sjinfo, \
36+
restrict_clauses)
37+
38+
#define check_index_predicates_compat(rool, rel) \
39+
check_index_predicates(root, rel)
40+
41+
#define create_append_path_compat(rel, subpaths, required_outer, \
42+
parallel_workers) \
43+
create_append_path(rel, subpaths, required_outer, parallel_workers)
44+
45+
#define pull_var_clause_compat(node, aggbehavior, phbehavior) \
46+
pull_var_clause(node, aggbehavior | phbehavior)
47+
48+
extern Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan);
49+
#define make_result_compat(root, tlist, resconstantqual, subplan) \
50+
make_result(tlist, resconstantqual, subplan)
51+
52+
#else
53+
54+
#define get_parameterized_joinrel_size_compat(root, \
55+
rel, \
56+
outer_path, \
57+
inner_path, \
58+
sjinfo, \
59+
restrict_clauses) \
60+
get_parameterized_joinrel_size(root, \
61+
rel, \
62+
(outer_path)->rows, \
63+
(inner_path)->rows, \
64+
sjinfo, \
65+
restrict_clauses)
66+
67+
#define check_index_predicates_compat(rool, rel) \
68+
check_partial_indexes(root, rel)
69+
70+
#define create_append_path_compat(rel, subpaths, required_outer, \
71+
parallel_workers) \
72+
create_append_path(rel, subpaths, required_outer)
73+
74+
#define pull_var_clause_compat(node, aggbehavior, phbehavior) \
75+
pull_var_clause(node, aggbehavior, phbehavior)
76+
77+
#define make_result_compat(root, tlist, resconstantqual, subplan) \
78+
make_result(root, tlist, resconstantqual, subplan)
79+
80+
#endif
81+
82+
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy