Re: Fixing Grittner's planner issues - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Fixing Grittner's planner issues
Date
Msg-id 17441.1235068731@sss.pgh.pa.us
Whole thread Raw
In response to Re: Fixing Grittner's planner issues  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Fixing Grittner's planner issues  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
[ after re-reading the code a bit ]

Robert Haas <robertmhaas@gmail.com> writes:
> Cool.  On the topic of documentation, I find the following comment in
> joinrels.c rather impenetrable:

>                         /*
>                          * Do these steps only if we actually have a
> regular semijoin,
>                          * as opposed to a case where we should
> unique-ify the RHS.
>                          */

The point here is that a semijoin ordinarily requires forming the whole
LHS relation (ie, min_lefthand) before applying the special join rule.
However, if you unique-ify the RHS then it's a regular inner join and
you don't have to obey that restriction, ie, you can join to just part
of min_lefthand.  Now ordinarily that's not an amazingly good idea but
there are important special cases where it is.  IIRC the case that
motivated this was
SELECT FROM a, b WHERE (a.x, b.y) IN (SELECT c1, c2 FROM c)

If you do this as a semijoin then you are forced to form the cartesian
product of a*b before you can semijoin to c.  If you uniqueify c
then you can join it to a first and then b using regular joins (possibly
indexscans on a.x and then b.y), or b and then a.

So join_is_legal allows such a join order, and the code in make_join_rel
has to be careful not to claim that "a semijoin c" is a valid way of
forming that join.

I'll change the comment.  Does this help?
           /*            * We might have a normal semijoin, or a case where we don't have            * enough rels to
dothe semijoin but can unique-ify the RHS and            * then do an innerjoin.  In the latter case we can't apply
      * JOIN_SEMI joining.            */
 
        regards, tom lane


pgsql-hackers by date:

Previous
From: Sam Mason
Date:
Subject: Re: WIP: hooking parser
Next
From: Kenneth Marshall
Date:
Subject: Re: WIP: hooking parser