@@ -89,6 +89,7 @@ static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRela
89
89
static void change_varnos_in_restrinct_info (RestrictInfo * rinfo ,change_varno_context * context );
90
90
static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
91
91
static bool change_varno_walker (Node * node ,change_varno_context * context );
92
+ static RestrictInfo * rebuild_restrictinfo (Node * clause ,RestrictInfo * old_rinfo );
92
93
93
94
/* copied from allpaths.h */
94
95
static void set_plain_rel_size (PlannerInfo * root ,RelOptInfo * rel ,
@@ -636,28 +637,38 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
636
637
bool alwaysTrue ;
637
638
WrapperNode * wrap = (WrapperNode * )lfirst (lc );
638
639
Node * new_clause = wrapper_make_expression (wrap ,index ,& alwaysTrue );
639
- RestrictInfo * old_rinfo = (RestrictInfo * )lfirst (lc2 ),
640
- * new_rinfo ;
640
+ RestrictInfo * old_rinfo = (RestrictInfo * )lfirst (lc2 );
641
641
642
642
if (alwaysTrue )
643
643
{
644
644
continue ;
645
645
}
646
646
Assert (new_clause );
647
647
648
- new_rinfo = make_restrictinfo ((Expr * )new_clause ,
649
- old_rinfo -> is_pushed_down ,
650
- old_rinfo -> outerjoin_delayed ,
651
- old_rinfo -> pseudoconstant ,
652
- old_rinfo -> required_relids ,
653
- old_rinfo -> outer_relids ,
654
- old_rinfo -> nullable_relids );
648
+ if (and_clause ((Node * )new_clause ))
649
+ {
650
+ ListCell * alc ;
651
+
652
+ foreach (alc , ((BoolExpr * )new_clause )-> args )
653
+ {
654
+ Node * arg = (Node * )lfirst (alc );
655
+ RestrictInfo * new_rinfo = rebuild_restrictinfo (arg ,old_rinfo );
656
+
657
+ change_varnos ((Node * )new_rinfo ,rel -> relid ,childrel -> relid );
658
+ childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
659
+ new_rinfo );
660
+ }
661
+ }
662
+ else
663
+ {
664
+ RestrictInfo * new_rinfo = rebuild_restrictinfo (new_clause ,old_rinfo );
655
665
656
- /* Replace old relids with new ones */
657
- change_varnos ((Node * )new_rinfo ,rel -> relid ,childrel -> relid );
666
+ /* Replace old relids with new ones */
667
+ change_varnos ((Node * )new_rinfo ,rel -> relid ,childrel -> relid );
658
668
659
- childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
660
- (void * )new_rinfo );
669
+ childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
670
+ (void * )new_rinfo );
671
+ }
661
672
}
662
673
663
674
/* Build an AppendRelInfo for this parent and child */
@@ -707,6 +718,19 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
707
718
return childRTindex ;
708
719
}
709
720
721
+ /* Create new restriction based on clause */
722
+ static RestrictInfo *
723
+ rebuild_restrictinfo (Node * clause ,RestrictInfo * old_rinfo )
724
+ {
725
+ return make_restrictinfo ((Expr * )clause ,
726
+ old_rinfo -> is_pushed_down ,
727
+ old_rinfo -> outerjoin_delayed ,
728
+ old_rinfo -> pseudoconstant ,
729
+ old_rinfo -> required_relids ,
730
+ old_rinfo -> outer_relids ,
731
+ old_rinfo -> nullable_relids );
732
+ }
733
+
710
734
/* Convert wrapper into expression for given index */
711
735
static Node *
712
736
wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue )