From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | David Steele <david(at)pgmasters(dot)net>, Georgios Kokolatos <gkokolatos(at)protonmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Allow an alias to be attached directly to a JOIN ... USING |
Date: | 2021-03-31 15:49:01 |
Message-ID: | 3d945d71-25d8-22b9-cc4e-aaad817eeda3@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 23.03.21 00:18, Tom Lane wrote:
> However, ParseNamespaceItem as it stands needs some help for this.
> It has a wired-in assumption that p_rte->eref describes the table
> and column aliases exposed by the nsitem. 0001 below fixes this by
> creating a separate p_names field in an nsitem. (There are some
> comments in 0001 referencing JOIN USING aliases, but no actual code
> for the feature.) That saves one indirection in common code paths,
> so it's possibly a win on its own. Then 0002 is your patch rebased
> onto that infrastructure, and with some cleanup of my own.
Makes sense. I've committed it based on that.
> Speaking of decompiled views, I feel like ruleutils.c could do with
> a little more work to teach it that these aliases are available.
> Right now, it resorts to ugly workarounds:
Yeah, the whole has_dangerous_join_using() can probably be unwound and
removed with this. But it's a bit of work.
> One other cosmetic thing is that this:
>
> regression=# select tu.* from (t1 join t2 using(a) as tu) tx;
> ERROR: missing FROM-clause entry for table "tu"
> LINE 1: select tu.* from (t1 join t2 using(a) as tu) tx;
> ^
>
> is a relatively dumb error message, compared to
>
> regression=# select t1.* from (t1 join t2 using(a) as tu) tx;
> ERROR: invalid reference to FROM-clause entry for table "t1"
> LINE 1: select t1.* from (t1 join t2 using(a) as tu) tx;
> ^
> HINT: There is an entry for table "t1", but it cannot be referenced from this part of the query.
>
> I didn't look into why that isn't working, but maybe errorMissingRTE
> needs to trawl all of the ParseNamespaceItems not just the RTEs.
Yes, I've prototyped that and it would have the desired effect. Might
need some code rearranging, like either change searchRangeTableForRel()
to not return an RTE or make a similar function for ParseNamespaceItem
search. Needs some more thought. I have left a test case in that would
show any changes here.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-03-31 15:58:38 | Re: making update/delete of inheritance trees scale better |
Previous Message | Kohei KaiGai | 2021-03-31 15:09:01 | Re: TRUNCATE on foreign table |