@@ -83,6 +83,7 @@ static WrapperNode *handle_arrexpr(WalkerContext *wcxt, const ScalarArrayOpExpr
83
83
static void change_varnos_in_restrinct_info (RestrictInfo * rinfo ,change_varno_context * context );
84
84
static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
85
85
static bool change_varno_walker (Node * node ,change_varno_context * context );
86
+ static RestrictInfo * rebuild_restrictinfo (Node * clause ,RestrictInfo * old_rinfo );
86
87
87
88
/* copied from allpaths.h */
88
89
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,
536
537
bool alwaysTrue ;
537
538
WrapperNode * wrap = (WrapperNode * )lfirst (lc );
538
539
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 );
541
541
542
542
if (alwaysTrue )
543
543
{
544
544
continue ;
545
545
}
546
546
Assert (new_clause );
547
547
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 );
555
565
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 );
558
568
559
- childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
560
- (void * )new_rinfo );
569
+ childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
570
+ (void * )new_rinfo );
571
+ }
561
572
}
562
573
563
574
/* Build an AppendRelInfo for this parent and child */
@@ -571,6 +582,19 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
571
582
heap_close (newrelation ,NoLock );
572
583
}
573
584
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
+
574
598
/* Convert wrapper into expression for given index */
575
599
static Node *
576
600
wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue )