Skip to content

Commit 0fb9f6b

Browse files
committed
Merge master, resolve conflicts
1 parent 7e53a83 commit 0fb9f6b

File tree

7 files changed

+193
-50
lines changed

7 files changed

+193
-50
lines changed

expected/pg_pathman.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2 OR value = 1;
190190
Filter: (value = 2)
191191
(5 rows)
192192

193+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value BETWEEN 1 AND 2;
194+
QUERY PLAN
195+
-------------------------------------------------
196+
Append
197+
-> Seq Scan on hash_rel_1
198+
Filter: ((value >= 1) AND (value <= 2))
199+
-> Seq Scan on hash_rel_2
200+
Filter: ((value >= 1) AND (value <= 2))
201+
(5 rows)
202+
193203
EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE id > 2500;
194204
QUERY PLAN
195205
-----------------------------------

hooks.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4242
*otherclauses;
4343
ListCell *lc;
4444
double paramsel;
45+
WalkerContext context;
4546

4647
if (set_join_pathlist_next)
4748
set_join_pathlist_next(root, joinrel, outerrel,
@@ -81,7 +82,12 @@ pathman_join_pathlist_hook(PlannerInfo *root,
8182
{
8283
WrapperNode *wrap;
8384

84-
wrap = walk_expr_tree(NULL, (Expr *) lfirst(lc), inner_prel);
85+
context.prel = inner_prel;
86+
context.econtext = NULL;
87+
context.hasLeast = false;
88+
context.hasGreatest = false;
89+
90+
wrap = walk_expr_tree((Expr *) lfirst(lc), &context);
8591
paramsel *= wrap->paramsel;
8692
}
8793

@@ -146,14 +152,15 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
146152

147153
if (prel != NULL && found)
148154
{
149-
ListCell *lc;
150-
int i;
151-
Oid *dsm_arr;
152-
List *ranges,
153-
*wrappers;
154-
PathKey *pathkeyAsc = NULL,
155-
*pathkeyDesc = NULL;
156-
double paramsel = 1.0;
155+
ListCell *lc;
156+
int i;
157+
Oid *dsm_arr;
158+
List *ranges,
159+
*wrappers;
160+
PathKey *pathkeyAsc = NULL,
161+
*pathkeyDesc = NULL;
162+
double paramsel = 1.0;
163+
WalkerContext context;
157164

158165
if (prel->parttype == PT_RANGE)
159166
{
@@ -192,15 +199,22 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
192199
dsm_arr = (Oid *) dsm_array_get_pointer(&prel->children);
193200
ranges = list_make1_int(make_irange(0, prel->children_count - 1, false));
194201

202+
context.prel = prel;
203+
context.econtext = NULL;
204+
context.hasLeast = false;
205+
context.hasGreatest = false;
206+
195207
/* Make wrappers over restrictions and collect final rangeset */
196208
wrappers = NIL;
197209
foreach(lc, rel->baserestrictinfo)
198210
{
199-
WrapperNode *wrap;
211+
WrapperNode *wrap;
212+
RestrictInfo *rinfo = (RestrictInfo*) lfirst(lc);
200213

201-
RestrictInfo *rinfo = (RestrictInfo*) lfirst(lc);
214+
wrap = walk_expr_tree(rinfo->clause, &context);
215+
if (!lc->next)
216+
finish_least_greatest(wrap, &context);
202217

203-
wrap = walk_expr_tree(NULL, rinfo->clause, prel);
204218
paramsel *= wrap->paramsel;
205219
wrappers = lappend(wrappers, wrap);
206220
ranges = irange_list_intersect(ranges, wrap->rangeset);

init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
284284
Datum vals[1];
285285
Oid oids[1] = {INT4OID};
286286
bool nulls[1] = {false};
287-
287+
288288
vals[0] = Int32GetDatum(parent_oid);
289289
prel = get_pathman_relation_info(parent_oid, NULL);
290290

@@ -351,7 +351,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
351351
HeapTupleGetOid(tuple));
352352
conbin = TextDatumGetCString(val);
353353
expr = (Expr *) stringToNode(conbin);
354-
354+
355355
switch(prel->parttype)
356356
{
357357
case PT_RANGE:
@@ -378,7 +378,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
378378
re.child_oid = con->conrelid;
379379
ranges[i] = re;
380380
break;
381-
381+
382382
case PT_HASH:
383383
if (!validate_hash_constraint(expr, prel, &hash))
384384
{

nodes_common.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,20 @@ rescan_append_common(CustomScanState *node)
350350
ListCell *lc;
351351
Oid *parts;
352352
int nparts;
353+
WalkerContext wcxt;
353354

354355
ranges = list_make1_int(make_irange(0, prel->children_count - 1, false));
355356

357+
wcxt.prel = prel;
358+
wcxt.econtext = econtext;
359+
wcxt.hasLeast = false;
360+
wcxt.hasGreatest = false;
361+
356362
foreach (lc, scan_state->custom_exprs)
357363
{
358364
WrapperNode *wn;
359-
WalkerContext wcxt;
360365

361-
wcxt.econtext = econtext;
362-
wn = walk_expr_tree(&wcxt, (Expr *) lfirst(lc), prel);
366+
wn = walk_expr_tree((Expr *) lfirst(lc), &wcxt);
363367

364368
ranges = irange_list_intersect(ranges, wn->rangeset);
365369
}

pathman.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,17 @@ typedef struct
217217

218218
typedef struct
219219
{
220-
PlanState *pstate;
221-
ExprContext *econtext;
220+
const PartRelationInfo *prel;
221+
bool hasLeast,
222+
hasGreatest;
223+
Datum least,
224+
greatest;
225+
226+
PlanState *pstate;
227+
ExprContext *econtext;
222228
} WalkerContext;
223229

224-
WrapperNode *walk_expr_tree(WalkerContext *wcxt, Expr *expr, const PartRelationInfo *prel);
230+
WrapperNode *walk_expr_tree(Expr *expr, WalkerContext *context);
231+
void finish_least_greatest(WrapperNode *wrap, WalkerContext *context);
225232

226233
#endif /* PATHMAN_H */

0 commit comments

Comments
 (0)