Re: Make subquery alias optional in FROM clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Make subquery alias optional in FROM clause
Date: 2017-02-23 14:20:58
Message-ID: 4533.1487859658@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bernd Helmle <mailings(at)oopsware(dot)de> writes:
> Right, i'm going to give it a try then. Currently i see these options:

> * Validate any generated alias against a list of explicit alias names.

> This means we have to collect explicit alias names in, say a hashtable,
> and validate a generated name against potential collisions and retry.

TBH I think a hashtable is overkill. You could just run through the FROM
clause and see what's there (compare what happens in ruleutils.c when it
has to invent an alias). The difficulty is not so much with time taken
as that it's not very clear how to manage things when the querytree is
only half-transformed. You don't really want this code having to deal
with both transformed and untransformed querytrees, much less knowing
which parts are where.

Maybe the best answer is to not do it immediately when transforming the
subselect's RTE, but to go back after we've finished transforming the
entire FROM clause and add aliases to any RTEs that lack them. I think
probably at that point you could just examine the RTE list and not worry
about any jointree data structures at all. It might be worth adding a
flag to ParseState to remember whether any aliases require assignment, so
that you could skip looking in the standard case.

> * Don't force/generate an alias at all.

> I've no idea for this yet and Tom already was concerned what this might
> break. There are several places in the transform phase where the
> refnames are required (e.g. isLockedRefname()).

Yeah. This would be cleaner in some sense but also a lot more delicate.
Not sure it's worth the trouble.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dr. Michael Meskes 2017-02-23 14:46:02 Re: Keep ECPG comment for log_min_duration_statement
Previous Message Stephen Frost 2017-02-23 13:54:03 Re: Automatic cleanup of oldest WAL segments with pg_receivexlog