Re: Idea: Avoid JOINs by using path expressions to follow FKs

From: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
To: Joel Jacobson <joel(at)compiler(dot)org>
Cc: Vik Fearing <vik(at)postgresfriends(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Idea: Avoid JOINs by using path expressions to follow FKs
Date: 2021-03-30 20:01:16
Message-ID: CAMsGm5eeDXFX7oA9H6hF0E+aZZP4D8nbChtt_3BSotGPLXshNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 30 Mar 2021 at 15:33, Joel Jacobson <joel(at)compiler(dot)org> wrote:

> Also, should the join be a left join, which would therefore return a NULL
> when there is no matching record? Or could we have a variation such as ->?
> to give a left join (NULL when no matching record) with -> using an inner
> join (record is not included in result when no matching record).
>
>
> Interesting idea, but I think we can keep it simple, and still support the
> case you mention:
>
> If we only have -> and you want to exclude records where the column is
> NULL (i.e. INNER JOIN),
> I think we should just use the WHERE clause and filter on such condition.
>

Just to be clear, it will always be a left join? Agreed that getting the
inner join behaviour can be done in the WHERE clause. I think this is a
case where simple is good. As long as the left join case is supported I'm
happy.

> Thanks for the encouraging words. I have exactly the same experience
> myself and share your view.
>
> I look forward to continued discussion on this matter.
>

I had another idea: maybe the default name of a foreign key constraint to a
primary key should simply be the name of the target table? That is, if I
say:

FOREIGN KEY (...) REFERENCES t

... then unless the table name t is already in use as a constraint name, it
will be used as the constraint name. It would be nice not to have to keep
repeating, like this:

CONSTRAINT t FOREIGN KEY (...) REFERENCES t

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-03-30 20:11:00 Re: "has_column_privilege()" issue with attnums and non-existent columns
Previous Message Robert Haas 2021-03-30 19:45:03 Re: pg_amcheck contrib application