Index: src/backend/optimizer/util/restrictinfo.c =================================================================== RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/backend/optimizer/util/restrictinfo.c,v retrieving revision 1.49 diff -c -r1.49 restrictinfo.c *** src/backend/optimizer/util/restrictinfo.c 4 Oct 2006 00:29:55 -0000 1.49 --- src/backend/optimizer/util/restrictinfo.c 31 Jul 2007 08:58:40 -0000 *************** *** 651,656 **** --- 651,659 ---- * of the latter, even though they might seem redundant by the pathkey * membership test. * + * The above logic only works for normal join clauses with non-overlapping + * left and right relation sets. + * * Weird special case: if we have two clauses that seem redundant * except one is pushed down into an outer join and the other isn't, * then they're not really redundant, because one constrains the *************** *** 673,685 **** return refrinfo; } ! /* check for redundant merge clauses */ ! if (rinfo->mergejoinoperator != InvalidOid) { - /* do the cheap test first: is it a "var = const" clause? */ - if (bms_is_empty(rinfo->left_relids) || - bms_is_empty(rinfo->right_relids)) - return NULL; /* var = const, so not redundant */ cache_mergeclause_pathkeys(root, rinfo); --- 676,689 ---- return refrinfo; } ! /* ! * check for redundant merge clauses by comparing the pathkeys as ! * explained above. The check for can_join handles the special case ! * of "var = const", as well as any clauses with overlapping left ! * and right rel sets. ! */ ! if (rinfo->mergejoinoperator != InvalidOid && rinfo->can_join) { cache_mergeclause_pathkeys(root, rinfo); *************** *** 687,693 **** { RestrictInfo *refrinfo = (RestrictInfo *) lfirst(refitem); ! if (refrinfo->mergejoinoperator != InvalidOid) { cache_mergeclause_pathkeys(root, refrinfo); --- 691,697 ---- { RestrictInfo *refrinfo = (RestrictInfo *) lfirst(refitem); ! if (refrinfo->mergejoinoperator != InvalidOid && refrinfo->can_join) { cache_mergeclause_pathkeys(root, refrinfo);