Skip to content

Commit ae81df2

Browse files
committed
Merge branch 'master' into rework_query_walkers
2 parents 86f6f8b + 71b348d commit ae81df2

File tree

5 files changed

+50
-69
lines changed

5 files changed

+50
-69
lines changed

src/hooks.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
101101

102102
/* Check that innerrel's RestrictInfo contains partitioned column */
103103
innerrel_rinfo_contains_part_attr =
104-
check_rinfo_for_partitioned_attr(innerrel->baserestrictinfo,
105-
innerrel->relid,
106-
inner_prel->attnum);
104+
get_partitioned_attr_clauses(innerrel->baserestrictinfo,
105+
inner_prel, innerrel->relid) != NULL;
107106

108107
foreach (lc, innerrel->pathlist)
109108
{
@@ -132,9 +131,9 @@ pathman_join_pathlist_hook(PlannerInfo *root,
132131
* ppi->ppi_clauses reference partition attribute
133132
*/
134133
if (!(innerrel_rinfo_contains_part_attr ||
135-
(ppi && check_rinfo_for_partitioned_attr(ppi->ppi_clauses,
136-
innerrel->relid,
137-
inner_prel->attnum))))
134+
(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
135+
inner_prel,
136+
innerrel->relid))))
138137
continue;
139138

140139
inner = create_runtimeappend_path(root, cur_inner_path,
@@ -310,10 +309,10 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
310309
if (!clause_contains_params((Node *) get_actual_clauses(rel->baserestrictinfo)))
311310
return;
312311

312+
/* Check that rel's RestrictInfo contains partitioned column */
313313
rel_rinfo_contains_part_attr =
314-
check_rinfo_for_partitioned_attr(rel->baserestrictinfo,
315-
rel->relid,
316-
prel->attnum);
314+
get_partitioned_attr_clauses(rel->baserestrictinfo,
315+
prel, rel->relid) != NULL;
317316

318317
foreach (lc, rel->pathlist)
319318
{
@@ -334,9 +333,8 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
334333
* ppi->ppi_clauses reference partition attribute
335334
*/
336335
if (!(rel_rinfo_contains_part_attr ||
337-
(ppi && check_rinfo_for_partitioned_attr(ppi->ppi_clauses,
338-
rel->relid,
339-
prel->attnum))))
336+
(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
337+
prel, rel->relid))))
340338
continue;
341339

342340
if (IsA(cur_path, AppendPath) && pg_pathman_enable_runtimeappend)

src/nodes_common.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "runtimeappend.h"
1313
#include "utils.h"
1414

15+
#include "access/sysattr.h"
1516
#include "optimizer/restrictinfo.h"
17+
#include "optimizer/var.h"
1618
#include "utils/memutils.h"
1719

1820

@@ -248,6 +250,38 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
248250
scan_state->enable_parent = (bool) linitial_int(lthird(runtimeappend_private));
249251
}
250252

253+
/*
254+
* Filter all available clauses and extract relevant ones.
255+
*/
256+
List *
257+
get_partitioned_attr_clauses(List *restrictinfo_list,
258+
const PartRelationInfo *prel,
259+
Index partitioned_rel)
260+
{
261+
#define AdjustAttno(attno) \
262+
( (AttrNumber) (part_attno + FirstLowInvalidHeapAttributeNumber) )
263+
264+
List *result = NIL;
265+
ListCell *l;
266+
267+
foreach(l, restrictinfo_list)
268+
{
269+
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
270+
Bitmapset *varattnos = NULL;
271+
int part_attno;
272+
273+
Assert(IsA(rinfo, RestrictInfo));
274+
pull_varattnos((Node *) rinfo->clause, partitioned_rel, &varattnos);
275+
276+
if (bms_get_singleton_member(varattnos, &part_attno) &&
277+
AdjustAttno(part_attno) == prel->attnum)
278+
{
279+
result = lappend(result, rinfo->clause);
280+
}
281+
}
282+
return result;
283+
}
284+
251285

252286
/* Transform partition ranges into plain array of partition Oids */
253287
Oid *
@@ -385,7 +419,7 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
385419
Plan *child_plan = (Plan *) lfirst(lc2);
386420
RelOptInfo *child_rel = ((Path *) lfirst(lc1))->parent;
387421

388-
/* Replace rel's tlist with a matching one */
422+
/* Replace rel's tlist with a matching one */
389423
if (!cscan->scan.plan.targetlist)
390424
tlist = replace_tlist_varnos(child_plan->targetlist, rel);
391425

@@ -407,7 +441,7 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
407441
/* Since we're not scanning any real table directly */
408442
cscan->scan.scanrelid = 0;
409443

410-
cscan->custom_exprs = get_actual_clauses(clauses);
444+
cscan->custom_exprs = get_partitioned_attr_clauses(clauses, prel, rel->relid);
411445
cscan->custom_plans = custom_plans;
412446
cscan->methods = scan_methods;
413447

src/nodes_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ clear_plan_states(CustomScanState *scan_state)
6060
}
6161
}
6262

63+
List * get_partitioned_attr_clauses(List *restrictinfo_list,
64+
const PartRelationInfo *prel,
65+
Index partitioned_rel);
66+
6367
Oid * get_partition_oids(List *ranges, int *n, const PartRelationInfo *prel,
6468
bool include_parent);
6569

src/utils.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,6 @@ static void lock_rows_visitor(Plan *plan, void *context);
4242
static bool rowmark_add_tableoids_walker(Node *node, void *context);
4343

4444

45-
/*
46-
* Execute 'cb_proc' on 'xact_context' reset.
47-
*/
48-
void
49-
execute_on_xact_mcxt_reset(MemoryContext xact_context,
50-
MemoryContextCallbackFunction cb_proc,
51-
void *arg)
52-
{
53-
MemoryContextCallback *mcxt_cb = MemoryContextAlloc(xact_context,
54-
sizeof(MemoryContextCallback));
55-
56-
/* Initialize MemoryContextCallback */
57-
mcxt_cb->arg = arg;
58-
mcxt_cb->func = cb_proc;
59-
mcxt_cb->next = NULL;
60-
61-
MemoryContextRegisterResetCallback(xact_context, mcxt_cb);
62-
}
63-
6445
/*
6546
* Check whether clause contains PARAMs or not
6647
*/
@@ -251,36 +232,6 @@ build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
251232
return tlist;
252233
}
253234

254-
/*
255-
* We should ensure that 'rel->baserestrictinfo' or 'ppi->ppi_clauses' contain
256-
* Var which corresponds to partition attribute before creating RuntimeXXX
257-
* paths since they are used by create_scan_plan() to form 'scan_clauses'
258-
* that are passed to create_customscan_plan().
259-
*/
260-
bool
261-
check_rinfo_for_partitioned_attr(List *rinfo, Index varno, AttrNumber varattno)
262-
{
263-
List *vars;
264-
List *clauses;
265-
ListCell *lc;
266-
267-
clauses = get_actual_clauses(rinfo);
268-
269-
vars = pull_var_clause((Node *) clauses,
270-
PVC_REJECT_AGGREGATES,
271-
PVC_REJECT_PLACEHOLDERS);
272-
273-
foreach (lc, vars)
274-
{
275-
Var *var = (Var *) lfirst(lc);
276-
277-
if (var->varno == varno && var->varoattno == varattno)
278-
return true;
279-
}
280-
281-
return false;
282-
}
283-
284235
/*
285236
* Get BTORDER_PROC for two types described by Oids
286237
*/

src/utils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ void postprocess_lock_rows(List *rtable, Plan *plan);
4949
bool clause_contains_params(Node *clause);
5050
bool is_date_type_internal(Oid typid);
5151
bool is_string_type_internal(Oid typid);
52-
bool check_rinfo_for_partitioned_attr(List *rinfo,
53-
Index varno,
54-
AttrNumber varattno);
5552

5653
/*
5754
* Misc.
@@ -67,9 +64,6 @@ Oid get_binary_operator_oid(char *opname, Oid arg1, Oid arg2);
6764
void fill_type_cmp_fmgr_info(FmgrInfo *finfo,
6865
Oid type1,
6966
Oid type2);
70-
void execute_on_xact_mcxt_reset(MemoryContext xact_context,
71-
MemoryContextCallbackFunction cb_proc,
72-
void *arg);
7367
char * datum_to_cstring(Datum datum, Oid typid);
7468

7569

0 commit comments

Comments
 (0)