Skip to content

Commit 130463a

Browse files
committed
Merge branch 'rel_1_1_beta' of https://github.com/postgrespro/pg_pathman into rel_1_1_beta
2 parents bcaeca0 + 7e7cb1b commit 130463a

File tree

3 files changed

+40
-35
lines changed

3 files changed

+40
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ regression.out
77
*.so
88
*.pyc
99
pg_pathman--*.sql
10+
*.gcda
11+
*.gcno

src/hooks.c

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pathman_join_pathlist_hook(PlannerInfo *root,
5151
ListCell *lc;
5252
WalkerContext context;
5353
double paramsel;
54-
bool innerrel_rinfo_contains_part_attr;
5554

5655
/* Call hooks set by other extensions */
5756
if (set_join_pathlist_next)
@@ -103,11 +102,6 @@ pathman_join_pathlist_hook(PlannerInfo *root,
103102
paramsel *= wrap->paramsel;
104103
}
105104

106-
/* Check that innerrel's RestrictInfos contain partitioned column */
107-
innerrel_rinfo_contains_part_attr =
108-
get_partitioned_attr_clauses(innerrel->baserestrictinfo,
109-
inner_prel, innerrel->relid) != NULL;
110-
111105
foreach (lc, innerrel->pathlist)
112106
{
113107
AppendPath *cur_inner_path = (AppendPath *) lfirst(lc);
@@ -132,14 +126,10 @@ pathman_join_pathlist_hook(PlannerInfo *root,
132126
/* Get the ParamPathInfo for a parameterized path */
133127
ppi = get_baserel_parampathinfo(root, innerrel, inner_required);
134128

135-
/*
136-
* Skip if neither rel->baserestrictinfo nor
137-
* ppi->ppi_clauses reference partition attribute
138-
*/
139-
if (!(innerrel_rinfo_contains_part_attr ||
140-
(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
141-
inner_prel,
142-
innerrel->relid))))
129+
/* Skip ppi->ppi_clauses don't reference partition attribute */
130+
if (!(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
131+
inner_prel,
132+
innerrel->relid)))
143133
continue;
144134

145135
inner = create_runtimeappend_path(root, cur_inner_path, ppi, paramsel);
@@ -213,13 +203,13 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
213203
ListCell *lc;
214204
Oid *children;
215205
List *ranges,
216-
*wrappers;
206+
*wrappers,
207+
*rel_partattr_clauses = NIL;
217208
PathKey *pathkeyAsc = NULL,
218209
*pathkeyDesc = NULL;
219210
double paramsel = 1.0;
220211
WalkerContext context;
221212
int i;
222-
bool rel_rinfo_contains_part_attr = false;
223213

224214
if (prel->parttype == PT_RANGE)
225215
{
@@ -336,20 +326,19 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
336326
pg_pathman_enable_runtime_merge_append))
337327
return;
338328

329+
/* Check that rel's RestrictInfo contains partitioned column */
330+
rel_partattr_clauses = get_partitioned_attr_clauses(rel->baserestrictinfo,
331+
prel, rel->relid);
332+
339333
/* Runtime[Merge]Append is pointless if there are no params in clauses */
340-
if (!clause_contains_params((Node *) get_actual_clauses(rel->baserestrictinfo)))
334+
if (!clause_contains_params((Node *) rel_partattr_clauses))
341335
return;
342336

343-
/* Check that rel's RestrictInfo contains partitioned column */
344-
rel_rinfo_contains_part_attr =
345-
get_partitioned_attr_clauses(rel->baserestrictinfo,
346-
prel, rel->relid) != NULL;
347-
348337
foreach (lc, rel->pathlist)
349338
{
350339
AppendPath *cur_path = (AppendPath *) lfirst(lc);
351340
Relids inner_required = PATH_REQ_OUTER((Path *) cur_path);
352-
ParamPathInfo *ppi = get_appendrel_parampathinfo(rel, inner_required);
341+
ParamPathInfo *ppi = get_baserel_parampathinfo(root, rel, inner_required);
353342
Path *inner_path = NULL;
354343

355344
/* Skip if rel contains some join-related stuff or path type mismatched */
@@ -363,7 +352,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
363352
* Skip if neither rel->baserestrictinfo nor
364353
* ppi->ppi_clauses reference partition attribute
365354
*/
366-
if (!(rel_rinfo_contains_part_attr ||
355+
if (!(rel_partattr_clauses ||
367356
(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
368357
prel, rel->relid))))
369358
continue;

src/pg_pathman.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void handle_binary_opexpr_param(const PartRelationInfo *prel, WrapperNode
8383
static WrapperNode *handle_opexpr(const OpExpr *expr, WalkerContext *context);
8484
static WrapperNode *handle_boolexpr(const BoolExpr *expr, WalkerContext *context);
8585
static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, WalkerContext *context);
86+
static double estimate_paramsel_using_prel(const PartRelationInfo *prel, int strategy);
8687
static RestrictInfo *rebuild_restrictinfo(Node *clause, RestrictInfo *old_rinfo);
8788
static bool pull_var_param(const WalkerContext *ctx, const OpExpr *expr, Node **var_ptr, Node **param_ptr);
8889

@@ -1189,6 +1190,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
11891190
uint32 idx = hash_to_part_index(DatumGetInt32(value),
11901191
PrelChildrenCount(prel));
11911192

1193+
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
11921194
result->rangeset = list_make1_irange(make_irange(idx, idx, true));
11931195

11941196
return; /* exit on equal */
@@ -1203,6 +1205,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
12031205
PrelChildrenCount(context->prel),
12041206
strategy,
12051207
result);
1208+
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
12061209
return;
12071210
}
12081211

@@ -1237,19 +1240,25 @@ handle_binary_opexpr_param(const PartRelationInfo *prel,
12371240
strategy = get_op_opfamily_strategy(expr->opno, tce->btree_opf);
12381241

12391242
result->rangeset = list_make1_irange(make_irange(0, PrelLastChild(prel), true));
1243+
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
1244+
}
12401245

1246+
/*
1247+
* Extracted common 'paramsel' estimator.
1248+
*/
1249+
static double
1250+
estimate_paramsel_using_prel(const PartRelationInfo *prel, int strategy)
1251+
{
1252+
/* If it's "=", divide by partitions number */
12411253
if (strategy == BTEqualStrategyNumber)
1242-
{
1243-
result->paramsel = 1.0 / (double) PrelChildrenCount(prel);
1244-
}
1254+
return 1.0 / (double) PrelChildrenCount(prel);
1255+
1256+
/* Default selectivity estimate for inequalities */
12451257
else if (prel->parttype == PT_RANGE && strategy > 0)
1246-
{
1247-
result->paramsel = DEFAULT_INEQ_SEL;
1248-
}
1249-
else
1250-
{
1251-
result->paramsel = 1.0;
1252-
}
1258+
return DEFAULT_INEQ_SEL;
1259+
1260+
/* Else there's not much to do */
1261+
else return 1.0;
12531262
}
12541263

12551264
/*
@@ -1324,6 +1333,7 @@ handle_const(const Const *c, WalkerContext *context)
13241333
{
13251334
const PartRelationInfo *prel = context->prel;
13261335
WrapperNode *result = (WrapperNode *) palloc(sizeof(WrapperNode));
1336+
int strategy = BTEqualStrategyNumber;
13271337

13281338
result->orig = (const Node *) c;
13291339

@@ -1348,6 +1358,8 @@ handle_const(const Const *c, WalkerContext *context)
13481358
Datum value = OidFunctionCall1(prel->hash_proc, c->constvalue);
13491359
uint32 idx = hash_to_part_index(DatumGetInt32(value),
13501360
PrelChildrenCount(prel));
1361+
1362+
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
13511363
result->rangeset = list_make1_irange(make_irange(idx, idx, true));
13521364
}
13531365
break;
@@ -1362,8 +1374,10 @@ handle_const(const Const *c, WalkerContext *context)
13621374
&tce->cmp_proc_finfo,
13631375
PrelGetRangesArray(context->prel),
13641376
PrelChildrenCount(context->prel),
1365-
BTEqualStrategyNumber,
1377+
strategy,
13661378
result);
1379+
1380+
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
13671381
}
13681382
break;
13691383

0 commit comments

Comments
 (0)