diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 243c8fb1e42..7159c775fbd 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -1549,16 +1549,17 @@ relation_excluded_by_constraints(PlannerInfo *root, /* * Regardless of the setting of constraint_exclusion, detect - * constant-FALSE-or-NULL restriction clauses. Because const-folding will - * reduce "anything AND FALSE" to just "FALSE", any such case should - * result in exactly one baserestrictinfo entry. This doesn't fire very - * often, but it seems cheap enough to be worth doing anyway. (Without - * this, we'd miss some optimizations that 9.5 and earlier found via much - * more roundabout methods.) + * constant-FALSE-or-NULL restriction clauses. Although const-folding + * will reduce "anything AND FALSE" to just "FALSE", the baserestrictinfo + * list can still have other members besides the FALSE constant, due to + * qual pushdown and other mechanisms; so check them all. This doesn't + * fire very often, but it seems cheap enough to be worth doing anyway. + * (Without this, we'd miss some optimizations that 9.5 and earlier found + * via much more roundabout methods.) */ - if (list_length(rel->baserestrictinfo) == 1) + foreach(lc, rel->baserestrictinfo) { - RestrictInfo *rinfo = (RestrictInfo *) linitial(rel->baserestrictinfo); + RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc); Expr *clause = rinfo->clause; if (clause && IsA(clause, Const) && diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out index 9b8638f286a..b95d30f6586 100644 --- a/src/test/regress/expected/join.out +++ b/src/test/regress/expected/join.out @@ -5788,13 +5788,11 @@ explain (costs off) select p.* from parent p left join child c on (p.k = c.k) where p.k = 1 and p.k = 2; - QUERY PLAN ------------------------------------------------- + QUERY PLAN +-------------------------- Result One-Time Filter: false - -> Index Scan using parent_pkey on parent p - Index Cond: (k = 1) -(4 rows) +(2 rows) select p.* from (parent p left join child c on (p.k = c.k)) join parent x on p.k = x.k