Skip to content

Commit 66cd411

Browse files
committed
fixed recreation of AND restrictions for partitions
1 parent 337a092 commit 66cd411

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
@@ -88,6 +88,7 @@ static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRela
8888
static void change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *context);
8989
static void change_varnos(Node *node, Oid old_varno, Oid new_varno);
9090
static bool change_varno_walker(Node *node, change_varno_context *context);
91+
static RestrictInfo *rebuild_restrictinfo(Node *clause, RestrictInfo *old_rinfo);
9192

9293
/* copied from allpaths.h */
9394
static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte);
@@ -509,28 +510,38 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
509510
bool alwaysTrue;
510511
WrapperNode *wrap = (WrapperNode *) lfirst(lc);
511512
Node *new_clause = wrapper_make_expression(wrap, index, &alwaysTrue);
512-
RestrictInfo *old_rinfo = (RestrictInfo *) lfirst(lc2),
513-
*new_rinfo;
513+
RestrictInfo *old_rinfo = (RestrictInfo *) lfirst(lc2);
514514

515515
if (alwaysTrue)
516516
{
517517
continue;
518518
}
519519
Assert(new_clause);
520520

521-
new_rinfo = make_restrictinfo((Expr *) new_clause,
522-
old_rinfo->is_pushed_down,
523-
old_rinfo->outerjoin_delayed,
524-
old_rinfo->pseudoconstant,
525-
old_rinfo->required_relids,
526-
old_rinfo->outer_relids,
527-
old_rinfo->nullable_relids);
521+
if (and_clause((Node *) new_clause))
522+
{
523+
ListCell *alc;
524+
525+
foreach(alc, ((BoolExpr *) new_clause)->args)
526+
{
527+
Node *arg = (Node *) lfirst(alc);
528+
RestrictInfo *new_rinfo = rebuild_restrictinfo(arg, old_rinfo);
529+
530+
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
531+
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
532+
new_rinfo);
533+
}
534+
}
535+
else
536+
{
537+
RestrictInfo *new_rinfo = rebuild_restrictinfo(new_clause, old_rinfo);
528538

529-
/* Replace old relids with new ones */
530-
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
539+
/* Replace old relids with new ones */
540+
change_varnos((Node *)new_rinfo, rel->relid, childrel->relid);
531541

532-
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
533-
(void *) new_rinfo);
542+
childrel->baserestrictinfo = lappend(childrel->baserestrictinfo,
543+
(void *) new_rinfo);
544+
}
534545
}
535546

536547
/* Build an AppendRelInfo for this parent and child */
@@ -544,6 +555,19 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
544555
heap_close(newrelation, NoLock);
545556
}
546557

558+
/* Create new restriction based on clause */
559+
static RestrictInfo *
560+
rebuild_restrictinfo(Node *clause, RestrictInfo *old_rinfo)
561+
{
562+
return make_restrictinfo((Expr *) clause,
563+
old_rinfo->is_pushed_down,
564+
old_rinfo->outerjoin_delayed,
565+
old_rinfo->pseudoconstant,
566+
old_rinfo->required_relids,
567+
old_rinfo->outer_relids,
568+
old_rinfo->nullable_relids);
569+
}
570+
547571
/* Convert wrapper into expression for given index */
548572
static Node *
549573
wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue)

0 commit comments

Comments
 (0)