@@ -88,6 +88,7 @@ static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRela
88
88
static void change_varnos_in_restrinct_info (RestrictInfo * rinfo , change_varno_context * context );
89
89
static void change_varnos (Node * node , Oid old_varno , Oid new_varno );
90
90
static bool change_varno_walker (Node * node , change_varno_context * context );
91
+ static RestrictInfo * rebuild_restrictinfo (Node * clause , RestrictInfo * old_rinfo );
91
92
92
93
/* copied from allpaths.h */
93
94
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,
509
510
bool alwaysTrue ;
510
511
WrapperNode * wrap = (WrapperNode * ) lfirst (lc );
511
512
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 );
514
514
515
515
if (alwaysTrue )
516
516
{
517
517
continue ;
518
518
}
519
519
Assert (new_clause );
520
520
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 );
528
538
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 );
531
541
532
- childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
533
- (void * ) new_rinfo );
542
+ childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
543
+ (void * ) new_rinfo );
544
+ }
534
545
}
535
546
536
547
/* Build an AppendRelInfo for this parent and child */
@@ -544,6 +555,19 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
544
555
heap_close (newrelation , NoLock );
545
556
}
546
557
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
+
547
571
/* Convert wrapper into expression for given index */
548
572
static Node *
549
573
wrapper_make_expression (WrapperNode * wrap , int index , bool * alwaysTrue )
0 commit comments