/*
* 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) &&
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