Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71b348d

Browse files
committed
fix runtime clauses for RuntimeAppend (select clause provided that it contains only relevant cols), introduce function get_partitioned_attr_clauses()
1 parentf7e4267 commit71b348d

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+
constPartRelationInfo*prel,
259+
Indexpartitioned_rel)
260+
{
261+
#defineAdjustAttno(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+
intpart_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+
returnresult;
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'stlist 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+
constPartRelationInfo*prel,
65+
Indexpartitioned_rel);
66+
6367
Oid*get_partition_oids(List*ranges,int*n,constPartRelationInfo*prel,
6468
boolinclude_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
staticvoidlock_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(MemoryContextxact_context,
49-
MemoryContextCallbackFunctioncb_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
returntlist;
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,Indexvarno,AttrNumbervarattno)
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
boolclause_contains_params(Node*clause);
5050
boolis_date_type_internal(Oidtypid);
5151
boolis_string_type_internal(Oidtypid);
52-
boolcheck_rinfo_for_partitioned_attr(List*rinfo,
53-
Indexvarno,
54-
AttrNumbervarattno);
5552

5653
/*
5754
* Misc.
@@ -67,9 +64,6 @@ Oid get_binary_operator_oid(char *opname, Oid arg1, Oid arg2);
6764
voidfill_type_cmp_fmgr_info(FmgrInfo*finfo,
6865
Oidtype1,
6966
Oidtype2);
70-
voidexecute_on_xact_mcxt_reset(MemoryContextxact_context,
71-
MemoryContextCallbackFunctioncb_proc,
72-
void*arg);
7367
char*datum_to_cstring(Datumdatum,Oidtypid);
7468

7569

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp