Re: --EXTERNAL--Re: PSQL does not remove obvious useless joins

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: "Sfiligoi, Igor" <Igor(dot)Sfiligoi(at)ga(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: --EXTERNAL--Re: PSQL does not remove obvious useless joins
Date: 2016-07-01 20:57:24
Message-ID: CACjxUsMw7JOWvjA8b+8veBJv1oG5GZVEy=3U1oWS0X-sLzgfXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 1, 2016 at 3:33 PM, Sfiligoi, Igor <Igor(dot)Sfiligoi(at)ga(dot)com> wrote:
> No, I don't want to use LEFT JOINS.
> I want to use regular joins.
>
> But (as mentioned in my other follow-up), all the fields are not
> null (was not in the original email, sorry), and are foreign
> keys, so it is guaranteed to always match.

In that case there is no difference between the inner join and the
left join except that the left join currently supports and
optimization that makes your query faster if the optional table is
not reference. Whether you want to take advantage of that is up to
you.

> The key part (in my mind) is that I am not filtering on any of
> the useless tables, and I am not returning any columns from those
> tables either.
> Both is known at planning time.

The fact that something can be determined at planning time doesn't
mean that checking for it is free.

> is my logic still broken?

Your logic seems OK with the table definitions you are now showing.

Whether we ever decide it is OK to omit tables which use an inner
join rather than only considering omitting them when the query
specifies that the join is optional is anybody's guess. If it is
important enough to you you could submit a patch or fund
development of such a feature; but since it would add at least some
small amount of planning time to every inner join just to avoid
specifying that the join is an optional one when writing the query,
it seems to me unlikely to be accepted.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2016-07-01 21:39:28 Re: 9.6 beta2 win-x64 download links still point to beta1
Previous Message Sfiligoi, Igor 2016-07-01 20:42:24 Re: --EXTERNAL--Re: PSQL does not remove obvious useless joins