Re: Allowing join removals for more join types - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Allowing join removals for more join types
Date
Msg-id 5403.1400857991@sss.pgh.pa.us
Whole thread Raw
In response to Re: Allowing join removals for more join types  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Allowing join removals for more join types  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes:
> I've just had a bit of a look at implementing checks allowing subqueries
> with unique indexes on the join cols being removed,

I'm a bit confused by this statement of the problem.  I thought the idea
was to recognize that subqueries with DISTINCT or GROUP BY clauses produce
known-unique output column(s), which permits join removal in the same way
that unique indexes on a base table allow us to deduce that certain
columns are known-unique and hence can offer no more than one match for
a join.  That makes it primarily a syntactic check, which you can perform
despite the fact that the subquery hasn't been planned yet (since the
parser has done sufficient analysis to determine the semantics of
DISTINCT/GROUP BY).

Drilling down into the subquery is a whole different matter.  For one
thing, there's no point in targeting cases in which the subquery would be
eligible to be flattened into the parent query, and your proposed list of
restrictions seems to eliminate most cases in which it couldn't be
flattened.  For another, you don't have access to any planning results for
the subquery yet, which is the immediate problem you're complaining of.
Duplicating the work of looking up a relation's indexes seems like a
pretty high price to pay for whatever improvement you might get here.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Sandro Santilli
Date:
Subject: Re: postgres_fdw and connection management
Next
From: Matteo Beccati
Date:
Subject: Re: uuid-ossp (Re: [pgsql-packagers] Postgresapp 9.4 beta build ready)