Skip to content

Commit 3fe1b83

Browse files
committed
Merge branch 'master' into picky_nodes
2 parents b05ee92 + 66cd411 commit 3fe1b83

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

pg_pathman.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static WrapperNode *handle_arrexpr(WalkerContext *wcxt, const ScalarArrayOpExpr
8383
static void change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *context);
8484
static void change_varnos(Node *node, Oid old_varno, Oid new_varno);
8585
static bool change_varno_walker(Node *node, change_varno_context *context);
86+
static RestrictInfo *rebuild_restrictinfo(Node *clause, RestrictInfo *old_rinfo);
8687

8788
/* copied from allpaths.h */
8889
static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte);
@@ -536,28 +537,38 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
536537
bool alwaysTrue;
537538
WrapperNode *wrap = (WrapperNode *) lfirst(lc);
538539
Node *new_clause = wrapper_make_expression(wrap, index, &alwaysTrue);
539-
RestrictInfo *old_rinfo = (RestrictInfo *) lfirst(lc2),
540-
*new_rinfo;
540+
RestrictInfo *old_rinfo = (RestrictInfo *) lfirst(lc2);
541541

542542
if (alwaysTrue)
543543
{
544544
continue;
545545
}
546546
Assert(new_clause);
547547

548-
new_rinfo = make_restrictinfo((Expr *) new_clause,
549-
old_rinfo->is_pushed_down,
550-
old_rinfo->outerjoin_delayed,
551-
old_rinfo->pseudoconstant,
552-
old_rinfo->required_relids,
553-
old_rinfo->outer_relids,
554-
old_rinfo->nullable_relids);
548+
if (and_clause((Node *) new_clause))
549+
{
550+
ListCell *alc;
551+
552+
foreach(alc, ((BoolExpr *) new_clause)->args)
553+
{
554+
Node *arg = (Node *) lfirst(alc);
555+
RestrictInfo *new_rinfo = rebuild_restrictinfo(arg, old_rinfo);
556+
557+
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
558+
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
559+
new_rinfo);
560+
}
561+
}
562+
else
563+
{
564+
RestrictInfo *new_rinfo = rebuild_restrictinfo(new_clause, old_rinfo);
555565

556-
/* Replace old relids with new ones */
557-
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
566+
/* Replace old relids with new ones */
567+
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
558568

559-
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
560-
(void *) new_rinfo);
569+
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
570+
(void *) new_rinfo);
571+
}
561572
}
562573

563574
/* Build an AppendRelInfo for this parent and child */
@@ -571,6 +582,19 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
571582
heap_close(newrelation, NoLock);
572583
}
573584

585+
/* Create new restriction based on clause */
586+
static RestrictInfo *
587+
rebuild_restrictinfo(Node *clause, RestrictInfo *old_rinfo)
588+
{
589+
return make_restrictinfo((Expr *) clause,
590+
old_rinfo->is_pushed_down,
591+
old_rinfo->outerjoin_delayed,
592+
old_rinfo->pseudoconstant,
593+
old_rinfo->required_relids,
594+
old_rinfo->outer_relids,
595+
old_rinfo->nullable_relids);
596+
}
597+
574598
/* Convert wrapper into expression for given index */
575599
static Node *
576600
wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue)

0 commit comments

Comments
 (0)