Skip to content

Commit 8690132

Browse files
committed
Merge branch 'master' into hash
2 parents abd5781 + 5bab8f8 commit 8690132

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/hooks.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4444
ListCell *lc;
4545
double paramsel;
4646
WalkerContext context;
47+
bool innerrel_rinfo_contains_part_attr;
4748

4849
if (set_join_pathlist_next)
4950
set_join_pathlist_next(root, joinrel, outerrel,
@@ -92,6 +93,11 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9293
paramsel *= wrap->paramsel;
9394
}
9495

96+
innerrel_rinfo_contains_part_attr =
97+
check_rinfo_for_partitioned_attr(innerrel->baserestrictinfo,
98+
innerrel->relid,
99+
inner_prel->attnum);
100+
95101
foreach (lc, innerrel->pathlist)
96102
{
97103
AppendPath *cur_inner_path = (AppendPath *) lfirst(lc);
@@ -107,6 +113,16 @@ pathman_join_pathlist_hook(PlannerInfo *root,
107113

108114
ppi = get_baserel_parampathinfo(root, innerrel, inner_required);
109115

116+
/*
117+
* Skip if neither rel->baserestrictinfo nor
118+
* ppi->ppi_clauses reference partition attribute
119+
*/
120+
if (!(innerrel_rinfo_contains_part_attr ||
121+
(ppi && check_rinfo_for_partitioned_attr(ppi->ppi_clauses,
122+
innerrel->relid,
123+
inner_prel->attnum))))
124+
continue;
125+
110126
inner = create_runtimeappend_path(root, cur_inner_path,
111127
ppi,
112128
paramsel);
@@ -162,6 +178,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
162178
double paramsel = 1.0;
163179
WalkerContext context;
164180
int i;
181+
bool rel_rinfo_contains_part_attr = false;
165182

166183
if (prel->parttype == PT_RANGE)
167184
{
@@ -280,6 +297,11 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
280297
if (!clause_contains_params((Node *) get_actual_clauses(rel->baserestrictinfo)))
281298
return;
282299

300+
rel_rinfo_contains_part_attr =
301+
check_rinfo_for_partitioned_attr(rel->baserestrictinfo,
302+
rel->relid,
303+
prel->attnum);
304+
283305
foreach (lc, rel->pathlist)
284306
{
285307
AppendPath *cur_path = (AppendPath *) lfirst(lc);
@@ -295,6 +317,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
295317
continue;
296318
}
297319

320+
/*
321+
* Skip if neither rel->baserestrictinfo nor
322+
* ppi->ppi_clauses reference partition attribute
323+
*/
324+
if (!(rel_rinfo_contains_part_attr ||
325+
(ppi && check_rinfo_for_partitioned_attr(ppi->ppi_clauses,
326+
rel->relid,
327+
prel->attnum))))
328+
continue;
329+
298330
if (IsA(cur_path, AppendPath) && pg_pathman_enable_runtimeappend)
299331
inner_path = create_runtimeappend_path(root, cur_path,
300332
ppi, paramsel);

src/utils.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "utils.h"
1111
#include "nodes/nodeFuncs.h"
1212
#include "nodes/makefuncs.h"
13+
#include "optimizer/var.h"
14+
#include "optimizer/restrictinfo.h"
1315
#include "parser/parse_param.h"
1416
#include "utils/builtins.h"
1517
#include "rewrite/rewriteManip.h"
@@ -109,3 +111,33 @@ build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
109111

110112
return tlist;
111113
}
114+
115+
/*
116+
* We should ensure that 'rel->baserestrictinfo' or 'ppi->ppi_clauses' contain
117+
* Var which corresponds to partition attribute before creating RuntimeXXX
118+
* paths since they are used by create_scan_plan() to form 'scan_clauses'
119+
* that are passed to create_customscan_plan().
120+
*/
121+
bool
122+
check_rinfo_for_partitioned_attr(List *rinfo, Index varno, AttrNumber varattno)
123+
{
124+
List *vars;
125+
List *clauses;
126+
ListCell *lc;
127+
128+
clauses = get_actual_clauses(rinfo);
129+
130+
vars = pull_var_clause((Node *) clauses,
131+
PVC_REJECT_AGGREGATES,
132+
PVC_REJECT_PLACEHOLDERS);
133+
134+
foreach (lc, vars)
135+
{
136+
Var *var = (Var *) lfirst(lc);
137+
138+
if (var->varno == varno && var->varoattno == varattno)
139+
return true;
140+
}
141+
142+
return false;
143+
}

src/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ bool clause_contains_params(Node *clause);
2727
List * build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
2828
Relation heapRelation);
2929

30+
bool check_rinfo_for_partitioned_attr(List *rinfo,
31+
Index varno,
32+
AttrNumber varattno);
33+
3034
#endif

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