@@ -88,6 +88,7 @@ static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRela
8888static void change_varnos_in_restrinct_info (RestrictInfo * rinfo ,change_varno_context * context );
8989static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
9090static 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 */
9394static void set_plain_rel_pathlist (PlannerInfo * root ,RelOptInfo * rel ,RangeTblEntry * rte );
@@ -509,28 +510,38 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
509510bool alwaysTrue ;
510511WrapperNode * wrap = (WrapperNode * )lfirst (lc );
511512Node * 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
515515if (alwaysTrue )
516516{
517517continue ;
518518}
519519Assert (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,
544555heap_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 */
548572static Node *
549573wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue )