]> granicus.if.org Git - postgresql/commit
Weaken the planner's tests for relevant joinclauses.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Apr 2012 19:32:34 +0000 (15:32 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Apr 2012 20:07:17 +0000 (16:07 -0400)
commite3ffd05b02468b1a53de31a322cedf195576a625
tree5631a32e6f9275af24b8382f6c776c56b16aa8ad
parentc0cc526e8b1e821dfced692a68e4c8978c2bdbc1
Weaken the planner's tests for relevant joinclauses.

We should be willing to cross-join two small relations if that allows us
to use an inner indexscan on a large relation (that is, the potential
indexqual for the large table requires both smaller relations).  This
worked in simple cases but fell apart as soon as there was a join clause
to a fourth relation, because the existence of any two-relation join clause
caused the planner to not consider clauseless joins between other base
relations.  The added regression test shows an example case adapted from
a recent complaint from Benoit Delbosc.

Adjust have_relevant_joinclause, have_relevant_eclass_joinclause, and
has_relevant_eclass_joinclause to consider that a join clause mentioning
three or more relations is sufficient grounds for joining any subset of
those relations, even if we have to do so via a cartesian join.  Since such
clauses are relatively uncommon, this shouldn't affect planning speed on
typical queries; in fact it should help a bit, because the latter two
functions in particular get significantly simpler.

Although this is arguably a bug fix, I'm not going to risk back-patching
it, since it might have currently-unforeseen consequences.
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/util/joininfo.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql