Fix join-removal logic for pseudoconstant and outerjoin-delayed quals.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Sep 2010 23:15:29 +0000 (23:15 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Sep 2010 23:15:29 +0000 (23:15 +0000)
commit4e97631e6a9d31acfde1057ad966e73f9d28c28d
treea4f97e3e140119921d60b33cdd285d8b8e519823
parent3522217b63ce9e88cd33a43e9481961a7c49ffb1
Fix join-removal logic for pseudoconstant and outerjoin-delayed quals.

In these cases a qual can get marked with the removable rel in its
required_relids, but this is just to schedule its evaluation correctly, not
because it really depends on the rel.  We were assuming that, in effect,
we could throw away *all* quals so marked, which is nonsense.  Tighten up
the logic to be a little more paranoid about which quals belong to the
outer join being considered for removal, and arrange for all quals that
don't belong to be updated so they will still get evaluated correctly.

Also fix another problem that happened to be exposed by this test case,
which was that make_join_rel() was failing to notice some cases where
a constant-false qual could be used to prove a join relation empty.  If it's
a pushed-down constant false, then the relation is empty even if it's an
outer join, because the qual applies after the outer join expansion.

Per report from Nathan Grange.  Back-patch into 9.0.
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/plan/analyzejoins.c
src/backend/optimizer/util/joininfo.c
src/include/optimizer/joininfo.h
src/test/regress/expected/join.out
src/test/regress/sql/join.sql