Re: magical eref alias names
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2025-01-02T22:11:32Z
Lists: pgsql-hackers
Attachments
- dont-pretend-*SELECT*-is-a-user-alias.patch (text/x-diff) patch
Robert Haas <robertmhaas@gmail.com> writes: > Oh, I agree, but I don't see why anyone would care whether rel names > are unique across different queries. When I mentioned global > uniqueness, I meant unique within a query, like what > set_rtable_names() does after the fact. Okay, but then we still have the problem of how to ensure that in a query that has inline'd some views. I think solving the sort of I-want-to-reference-this problem you describe would require that we unique-ify the aliases in the rewriter, just after it finishes incorporating any views. We could do that, but it seems like a lot of cycles to expend on something that would be pointless in the typical case where nobody ever looks at the aliases later. > Now, I'm firmly convinced that this is a real problem and worth > solving, but let me be clear that I don't think the solution is > anywhere on this thread, nor do I think that it is simple. Agreed. > My original > proposal of getting rid of system-generated fake names isn't > necessary, because you very helpfully pointed out that I can look at > whether RTE->alias->aliasname exists to figure that out. Actually, I noticed that we are failing to honor that in the places where we inject "*SELECT*" and "*SELECT* %d" names, because that code puts those names into RTE->alias not only RTE->eref. I experimented with the attached patch to not do that anymore, which is sort of a subset of what you did but just focused on not lying about what's generated versus user-written. We could alternatively keep the current generated names by extending addRangeTableEntryForSubquery's API so that alias and generated eref are passed separately. (I didn't look to see if anyplace else is messing up this distinction similarly.) regards, tom lane
Commits
-
Don't generate fake "*TLOCRN*" or "*TROCRN*" aliases, either.
- 5a170e992a4d 19 (unreleased) landed
-
Don't generate fake "ANY_subquery" aliases, either.
- 6f79024df346 19 (unreleased) landed
-
Don't generate fake "*SELECT*" or "*SELECT* %d" subquery aliases.
- 585e31fcb6df 19 (unreleased) landed
-
Subselects in FROM clause, per ISO syntax: FROM (SELECT ...) [AS] alias.
- 3a94e789f5c9 7.1.1 cited