Skip to content

Commit 2a3c645

Browse files
committed
fix JOIN_UNIQUE_OUTER & JOIN_UNIQUE_INNER in NestLoop, fix handle_arrexpr() (WHERE IN), clean code, check for NULL partitioned attribute (return NIL)
1 parent 7e7cb1b commit 2a3c645

File tree

3 files changed

+172
-66
lines changed

3 files changed

+172
-66
lines changed

src/hooks.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4343
JoinPathExtraData *extra)
4444
{
4545
JoinCostWorkspace workspace;
46+
JoinType saved_jointype = jointype;
4647
RangeTblEntry *inner_rte = root->simple_rte_array[innerrel->relid];
4748
const PartRelationInfo *inner_prel;
4849
List *pathkeys = NIL,
@@ -118,6 +119,12 @@ pathman_join_pathlist_hook(PlannerInfo *root,
118119

119120
/* Select cheapest path for outerrel */
120121
outer = outerrel->cheapest_total_path;
122+
if (saved_jointype == JOIN_UNIQUE_OUTER)
123+
{
124+
outer = (Path *) create_unique_path(root, outerrel,
125+
outer, extra->sjinfo);
126+
Assert(outer);
127+
}
121128

122129
/* Make innerrel path depend on outerrel's column */
123130
inner_required = bms_union(PATH_REQ_OUTER((Path *) cur_inner_path),
@@ -133,6 +140,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
133140
continue;
134141

135142
inner = create_runtimeappend_path(root, cur_inner_path, ppi, paramsel);
143+
if (saved_jointype == JOIN_UNIQUE_INNER)
144+
return; /* No way to do this with a parameterized inner path */
136145

137146
initial_cost_nestloop(root, &workspace, jointype,
138147
outer, inner, /* built paths */
@@ -204,7 +213,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
204213
Oid *children;
205214
List *ranges,
206215
*wrappers,
207-
*rel_partattr_clauses = NIL;
216+
*rel_part_clauses = NIL;
208217
PathKey *pathkeyAsc = NULL,
209218
*pathkeyDesc = NULL;
210219
double paramsel = 1.0;
@@ -310,8 +319,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
310319
IndexRange irange = lfirst_irange(lc);
311320

312321
for (i = irange.ir_lower; i <= irange.ir_upper; i++)
313-
append_child_relation(root, rel, rti, rte, i, children[i],
314-
wrappers);
322+
append_child_relation(root, rel, rti, rte, i, children[i], wrappers);
315323
}
316324

317325
/* Clear old path list */
@@ -327,19 +335,26 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
327335
return;
328336

329337
/* Check that rel's RestrictInfo contains partitioned column */
330-
rel_partattr_clauses = get_partitioned_attr_clauses(rel->baserestrictinfo,
331-
prel, rel->relid);
338+
rel_part_clauses = get_partitioned_attr_clauses(rel->baserestrictinfo,
339+
prel, rel->relid);
332340

333341
/* Runtime[Merge]Append is pointless if there are no params in clauses */
334-
if (!clause_contains_params((Node *) rel_partattr_clauses))
342+
if (!clause_contains_params((Node *) rel_part_clauses))
335343
return;
336344

337345
foreach (lc, rel->pathlist)
338346
{
339347
AppendPath *cur_path = (AppendPath *) lfirst(lc);
340348
Relids inner_required = PATH_REQ_OUTER((Path *) cur_path);
341-
ParamPathInfo *ppi = get_baserel_parampathinfo(root, rel, inner_required);
342349
Path *inner_path = NULL;
350+
ParamPathInfo *ppi;
351+
List *ppi_part_clauses = NIL;
352+
353+
/* Fetch ParamPathInfo & try to extract part-related clauses */
354+
ppi = get_baserel_parampathinfo(root, rel, inner_required);
355+
if (ppi && ppi->ppi_clauses)
356+
ppi_part_clauses = get_partitioned_attr_clauses(ppi->ppi_clauses,
357+
prel, rel->relid);
343358

344359
/* Skip if rel contains some join-related stuff or path type mismatched */
345360
if (!(IsA(cur_path, AppendPath) || IsA(cur_path, MergeAppendPath)) ||
@@ -352,9 +367,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
352367
* Skip if neither rel->baserestrictinfo nor
353368
* ppi->ppi_clauses reference partition attribute
354369
*/
355-
if (!(rel_partattr_clauses ||
356-
(ppi && get_partitioned_attr_clauses(ppi->ppi_clauses,
357-
prel, rel->relid))))
370+
if (!(rel_part_clauses || ppi_part_clauses))
358371
continue;
359372

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

src/init.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ validate_range_constraint(const Expr *expr,
841841
const TypeCacheEntry *tce;
842842
const BoolExpr *boolexpr = (const BoolExpr *) expr;
843843
const OpExpr *opexpr;
844+
int strategy;
844845

845846
if (!expr)
846847
return false;
@@ -853,8 +854,9 @@ validate_range_constraint(const Expr *expr,
853854

854855
/* check that left operand is >= operator */
855856
opexpr = (OpExpr *) linitial(boolexpr->args);
856-
if (BTGreaterEqualStrategyNumber == get_op_opfamily_strategy(opexpr->opno,
857-
tce->btree_opf))
857+
strategy = get_op_opfamily_strategy(opexpr->opno, tce->btree_opf);
858+
859+
if (strategy == BTGreaterEqualStrategyNumber)
858860
{
859861
if (!read_opexpr_const(opexpr, prel, min))
860862
return false;
@@ -864,8 +866,9 @@ validate_range_constraint(const Expr *expr,
864866

865867
/* check that right operand is < operator */
866868
opexpr = (OpExpr *) lsecond(boolexpr->args);
867-
if (BTLessStrategyNumber == get_op_opfamily_strategy(opexpr->opno,
868-
tce->btree_opf))
869+
strategy = get_op_opfamily_strategy(opexpr->opno, tce->btree_opf);
870+
871+
if (strategy == BTLessStrategyNumber)
869872
{
870873
if (!read_opexpr_const(opexpr, prel, max))
871874
return false;

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