Re: Foreign key joins revisited

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: "Isaac Morland" <isaac(dot)morland(at)gmail(dot)com>
Cc: "Corey Huinker" <corey(dot)huinker(at)gmail(dot)com>, "PostgreSQL Developers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Foreign key joins revisited
Date: 2021-12-27 15:20:33
Message-ID: 3118c302-3e08-4522-818d-8346fd18ca26@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>On Mon, Dec 27, 2021, at 15:48, Isaac Morland wrote:
>I thought the proposal was to give the FK constraint name.
>However, if the idea now is to allow leaving that out also if there
>is only one FK, then that's also OK as long as people understand it can break in the same way NATURAL JOIN can break
>when columns are added later. For that matter, a join mentioning column names can break if the columns are changed. But
>breakage where the query no longer compiles are better than ones where it suddenly means something very different so
>overall I wouldn't worry about this too much.

Yes, my proposal was indeed to give the FK constraint name.
I just commented on Corey's different proposal that instead specified FK columns.
I agree with your reasoning regarding the trade-offs and problems with such a proposal.

I still see more benefits in using the FK constraint name though.

I have made some new progress on the idea since last proposal:

SYNTAX

join_type JOIN KEY referencing_alias.fk_name [ [ AS ] alias ]

join_type table_name [ [ AS ] alias ] KEY fk_name REF referenced_alias

EXAMPLE

FROM permission p
LEFT JOIN KEY p.role r
LEFT JOIN team_role tr KEY role REF r
LEFT JOIN KEY tr.team t
LEFT JOIN user_role ur KEY role REF r
LEFT JOIN KEY ur.user u
WHERE p.id = 1;

Foreign key constraint names have been given the same names as the referenced tables.

Thoughts?

/Joel

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sascha Kuhl 2021-12-27 15:28:43 Re: Foreign key joins revisited
Previous Message Alvaro Herrera 2021-12-27 15:10:12 Re: Add Boolean node