Skip to content

Commit fbfd149

Browse files
committed
resolve conflicts caused by a merge of PostgreSQL 9.6 compatibility fixes
2 parents e8a47aa + e999b86 commit fbfd149

File tree

11 files changed

+265
-79
lines changed

11 files changed

+265
-79
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ before_install:
1414
- sudo sh ./travis/apt.postgresql.org.sh
1515

1616
env:
17+
- PGVERSION=9.6 CHECK_CODE=true
18+
- PGVERSION=9.6 CHECK_CODE=false
1719
- PGVERSION=9.5 CHECK_CODE=true
1820
- PGVERSION=9.5 CHECK_CODE=false
1921

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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 \
66
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o \
7-
$(WIN32RES)
7+
src/pg_compat.o $(WIN32RES)
88

99
EXTENSION = pg_pathman
1010
EXTVERSION = 1.0

range.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ DECLARE
9191
v_rows_count INTEGER;
9292
v_max p_start_value%TYPE;
9393
v_cur_value p_start_value%TYPE := p_start_value;
94+
p_end_value p_start_value%TYPE;
9495
i INTEGER;
9596

9697
BEGIN
@@ -132,12 +133,19 @@ BEGIN
132133
* and specifies partition count as 0 then do not check boundaries
133134
*/
134135
IF p_count != 0 THEN
136+
/* compute right bound of partitioning through additions */
137+
p_end_value := p_start_value;
138+
FOR i IN 1..p_count
139+
LOOP
140+
p_end_value := p_end_value + p_interval;
141+
END LOOP;
142+
135143
/* Check boundaries */
136144
EXECUTE format('SELECT @extschema@.check_boundaries(''%s'', ''%s'', ''%s'', ''%s''::%s)',
137145
parent_relid,
138146
p_attribute,
139147
p_start_value,
140-
p_start_value + p_interval * p_count,
148+
p_end_value,
141149
@extschema@.get_base_type(pg_typeof(p_start_value))::TEXT);
142150
END IF;
143151

@@ -195,6 +203,7 @@ DECLARE
195203
v_rows_count INTEGER;
196204
v_max p_start_value%TYPE;
197205
v_cur_value p_start_value%TYPE := p_start_value;
206+
p_end_value p_start_value%TYPE;
198207
i INTEGER;
199208

200209
BEGIN
@@ -240,11 +249,18 @@ BEGIN
240249
* and specifies partition count as 0 then do not check boundaries
241250
*/
242251
IF p_count != 0 THEN
252+
/* compute right bound of partitioning through additions */
253+
p_end_value := p_start_value;
254+
FOR i IN 1..p_count
255+
LOOP
256+
p_end_value := p_end_value + p_interval;
257+
END LOOP;
258+
243259
/* check boundaries */
244260
PERFORM @extschema@.check_boundaries(parent_relid,
245261
p_attribute,
246262
p_start_value,
247-
p_start_value + p_interval * p_count);
263+
p_end_value);
248264
END IF;
249265

250266
/* Create sequence for child partitions names */

src/hooks.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hooks.h"
1313
#include "init.h"
1414
#include "partition_filter.h"
15+
#include "pg_compat.h"
1516
#include "runtimeappend.h"
1617
#include "runtime_merge_append.h"
1718
#include "utils.h"
@@ -169,12 +170,12 @@ pathman_join_pathlist_hook(PlannerInfo *root,
169170
* Currently we use get_parameterized_joinrel_size() since
170171
* it works just fine, but this might change some day.
171172
*/
172-
nest_path->path.rows = get_parameterized_joinrel_size(root,
173-
joinrel,
174-
outer->rows,
175-
inner->rows,
176-
extra->sjinfo,
177-
filtered_joinclauses);
173+
nest_path->path.rows = get_parameterized_joinrel_size_compat(root,
174+
joinrel,
175+
outer,
176+
inner,
177+
extra->sjinfo,
178+
filtered_joinclauses);
178179

179180
/* Finally we can add the new NestLoop path */
180181
add_path(joinrel, (Path *) nest_path);
@@ -183,7 +184,10 @@ pathman_join_pathlist_hook(PlannerInfo *root,
183184

184185
/* Cope with simple relations */
185186
void
186-
pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
187+
pathman_rel_pathlist_hook(PlannerInfo *root,
188+
RelOptInfo *rel,
189+
Index rti,
190+
RangeTblEntry *rte)
187191
{
188192
const PartRelationInfo *prel;
189193
RangeTblEntry **new_rte_array;
@@ -315,15 +319,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
315319
IndexRange irange = lfirst_irange(lc);
316320

317321
for (i = irange.ir_lower; i <= irange.ir_upper; i++)
318-
append_child_relation(root, rel, rti, rte, i, children[i], wrappers);
322+
append_child_relation(root, rel, rti, rte, i, children[i],
323+
wrappers);
319324
}
320325

321326
/* Clear old path list */
322327
list_free(rel->pathlist);
323328

324329
rel->pathlist = NIL;
325330
set_append_rel_pathlist(root, rel, rti, rte, pathkeyAsc, pathkeyDesc);
326-
set_append_rel_size(root, rel, rti, rte);
331+
set_append_rel_size_compat(root, rel, rti, rte);
327332

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

src/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "utils/syscache.h"
3939
#include "utils/typcache.h"
4040

41+
#if PG_VERSION_NUM >= 90600
42+
#include "catalog/pg_constraint_fn.h"
43+
#endif
44+
4145

4246
/* Help user in case of emergency */
4347
#define INIT_ERROR_HINT "pg_pathman will be disabled to allow you to resolve this issue"

src/nodes_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "commands/explain.h"
1818
#include "optimizer/planner.h"
1919

20+
#if PG_VERSION_NUM >= 90600
21+
#include "nodes/extensible.h"
22+
#endif
23+
2024

2125
/*
2226
* Common structure for storing selected

src/partition_filter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include "commands/explain.h"
1919
#include "optimizer/planner.h"
2020

21+
#if PG_VERSION_NUM >= 90600
22+
#include "nodes/extensible.h"
23+
#endif
24+
2125

2226
#define ERR_PART_ATTR_NULL "partitioned column's value should not be NULL"
2327
#define ERR_PART_ATTR_NO_PART "no suitable partition for key '%s'"

src/pg_compat.c

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

src/pg_compat.h

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

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