Skip to content

Commit b84a0a5

Browse files
committed
Merge branch 'master' into callbacks
2 parents 86d609a + fbbbf4b commit b84a0a5

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/hooks.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,21 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9999
paramsel *= wrap->paramsel;
100100
}
101101

102-
/* Check that innerrel's RestrictInfo contains partitioned column */
102+
/* Check that innerrel's RestrictInfos contain partitioned column */
103103
innerrel_rinfo_contains_part_attr =
104104
get_partitioned_attr_clauses(innerrel->baserestrictinfo,
105105
inner_prel, innerrel->relid) != NULL;
106106

107107
foreach (lc, innerrel->pathlist)
108108
{
109+
AppendPath *cur_inner_path = (AppendPath *) lfirst(lc);
109110
Path *outer,
110111
*inner;
111112
NestPath *nest_path; /* NestLoop we're creating */
112113
ParamPathInfo *ppi; /* parameterization info */
113114
Relids inner_required; /* required paremeterization relids */
114-
AppendPath *cur_inner_path = (AppendPath *) lfirst(lc);
115+
List *filtered_joinclauses = NIL;
116+
ListCell *rinfo_lc;
115117

116118
if (!IsA(cur_inner_path, AppendPath))
117119
continue;
@@ -136,8 +138,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
136138
innerrel->relid))))
137139
continue;
138140

139-
inner = create_runtimeappend_path(root, cur_inner_path,
140-
ppi, paramsel);
141+
inner = create_runtimeappend_path(root, cur_inner_path, ppi, paramsel);
141142

142143
initial_cost_nestloop(root, &workspace, jointype,
143144
outer, inner, /* built paths */
@@ -151,7 +152,29 @@ pathman_join_pathlist_hook(PlannerInfo *root,
151152
pathkeys,
152153
calc_nestloop_required_outer(outer, inner));
153154

154-
/* Finally we can add new NestLoop path */
155+
/* Discard all clauses that are to be evaluated by 'inner' */
156+
foreach (rinfo_lc, extra->restrictlist)
157+
{
158+
RestrictInfo *rinfo = (RestrictInfo *) lfirst(rinfo_lc);
159+
160+
Assert(IsA(rinfo, RestrictInfo));
161+
if (!join_clause_is_movable_to(rinfo, inner->parent))
162+
filtered_joinclauses = lappend(filtered_joinclauses, rinfo);
163+
}
164+
165+
/*
166+
* Override 'rows' value produced by standard estimator.
167+
* Currently we use get_parameterized_joinrel_size() since
168+
* it works just fine, but this might change some day.
169+
*/
170+
nest_path->path.rows = get_parameterized_joinrel_size(root,
171+
joinrel,
172+
outer->rows,
173+
inner->rows,
174+
extra->sjinfo,
175+
filtered_joinclauses);
176+
177+
/* Finally we can add the new NestLoop path */
155178
add_path(joinrel, (Path *) nest_path);
156179
}
157180
}
@@ -342,8 +365,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
342365
ppi, paramsel);
343366
else if (IsA(cur_path, MergeAppendPath) &&
344367
pg_pathman_enable_runtime_merge_append)
368+
{
369+
/* Check struct layout compatibility */
370+
if (offsetof(AppendPath, subpaths) !=
371+
offsetof(MergeAppendPath, subpaths))
372+
elog(FATAL, "Struct layouts of AppendPath and "
373+
"MergeAppendPath differ");
374+
345375
inner_path = create_runtimemergeappend_path(root, cur_path,
346376
ppi, paramsel);
377+
}
347378

348379
if (inner_path)
349380
add_path(rel, inner_path);

src/nodes_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ get_partitioned_attr_clauses(List *restrictinfo_list,
259259
Index partitioned_rel)
260260
{
261261
#define AdjustAttno(attno) \
262-
( (AttrNumber) (part_attno + FirstLowInvalidHeapAttributeNumber) )
262+
( (AttrNumber) (attno + FirstLowInvalidHeapAttributeNumber) )
263263

264264
List *result = NIL;
265265
ListCell *l;

src/pg_pathman.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
544544
/* Recalc parent relation tuples count */
545545
rel->tuples += childrel->tuples;
546546

547+
/* Close child relations, but keep locks */
547548
heap_close(newrelation, NoLock);
548549

549550

@@ -1510,7 +1511,6 @@ handle_boolexpr(const BoolExpr *expr, WalkerContext *context)
15101511
switch (expr->boolop)
15111512
{
15121513
case OR_EXPR:
1513-
// finish_least_greatest(arg, context);
15141514
result->rangeset = irange_list_union(result->rangeset, arg->rangeset);
15151515
break;
15161516
case AND_EXPR:
@@ -1671,7 +1671,6 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
16711671
path = create_seqscan_path(root, rel, required_outer);
16721672
#endif
16731673
add_path(rel, path);
1674-
// set_pathkeys(root, rel, path);
16751674

16761675
/* Consider index scans */
16771676
create_index_paths(root, rel);

0 commit comments

Comments
 (0)