Skip to content

Commit 71b348d

Browse files
committed
fix runtime clauses for RuntimeAppend (select clause provided that it contains only relevant cols), introduce function get_partitioned_attr_clauses()
1 parent f7e4267 commit 71b348d

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
@@ -41,25 +41,6 @@ static List *get_tableoids_list(List *tlist);
4141
static void lock_rows_visitor(Plan *plan, void *context);
4242

4343

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

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

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)
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