Re: Bogus EXPLAIN results with column aliases for mismatched partitions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Bogus EXPLAIN results with column aliases for mismatched partitions
Date: 2019-12-01 21:34:38
Message-ID: 10395.1575236078@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> Now, there is another thing that set_rtable_names() is doing that
> postgres_fdw doesn't do, which is to unique-ify the chosen alias
> names by adding "_NN" if the querytree contains multiple uses of
> the same table alias. I don't see any practical way for postgres_fdw
> to match that behavior, since it lacks global information about the
> query. If we wanted to fix it, what we'd likely need to do is
> postpone creation of the relation_name strings until EXPLAIN,
> providing some way for postgres_fdw to ask ruleutils.c what alias
> it'd assigned to a particular RTE.

Hmmm ... so actually, that isn't *quite* as bad as I thought:
ExplainState does already expose that information, so we just need
to rearrange how postgres_fdw does things. Here's a revised proposed
patch, which exposes (and fixes) several additional test cases where
the Relations: string was previously visibly out of sync with what
ruleutils was using for Var names.

BTW, the existing code always schema-qualifies the relation names,
on the rather lame grounds that it's producing the string without
knowing whether EXPLAIN VERBOSE will be specified. In this code,
the verbose flag is available so it would be trivial to make the
output conform to EXPLAIN's normal policy. I didn't change that
here because there'd be a bunch more test output diffs of no
intellectual interest. Should we change it, or leave well enough
alone?

regards, tom lane

Attachment Content-Type Size
fix-alias-usage-in-postgres_fdw-explain-2.patch text/x-diff 14.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2019-12-01 22:50:00 Re: Since '2001-09-09 01:46:40'::timestamp microseconds are lost when extracting epoch
Previous Message Tom Lane 2019-12-01 19:38:36 Re: Bogus EXPLAIN results with column aliases for mismatched partitions