| From: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> |
|---|---|
| To: | baji(dot)pgdev(at)gmail(dot)com |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, etsuro(dot)fujita(at)gmail(dot)com |
| Subject: | Re: postgres_fdw: statistics import can silently fall back to sampling across encodings |
| Date: | 2026-11-24 04:09:57 |
| Message-ID: | 20261124.130957.1287739411328043618.horikyota.ntt@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hello,
At Mon, 23 Nov 2026 16:41:17 -0600, Baji Shaik <baji(dot)pgdev(at)gmail(dot)com> wrote in
> The attached patch makes postgres_fdw detect that case and fall back
> on purpose, rather than by accident.
>
> Thoughts?
It seems to me that the issue here is simply that the sort order of
column names differs between the remote and local databases. If so,
re-sorting the results from the remote server in byte order in the
local encoding should be sufficient. If the non-injectivity of
encoding conversion itself is a concern, it should affect not only
column names but also the contents of the imported statistics.
On the other hand, the target columns are selected on the remote side
using the column names sent from the local side. If distinct remote
column names are converted to the same local name, there will be
unmatched result rows. Conversely, if distinct local column names are
converted to the same remote name, at least one of them will not
survive the round trip unchanged. In either case, the existing
matching logic should detect the mismatch. The resulting error message
might not be particularly helpful, but I don't think this is a problem
in practice.
Therefore, as far as column name matching is concerned, I don't think
we need any special handling for the non-injectivity of encoding
conversion. Dealing with the difference in sort order should be
sufficient.
We could simply build an array of result row indexes and sort it
locally by column name before applying the existing matching logic in
match_attrmap().
rowmap = palloc_array(int, numrows);
for (int i = 0; i < numrows; i++)
rowmap[i] = i;
qsort_arg(rowmap, numrows, sizeof(int), attstats_row_cmp, res);
(Then, use rowmap[row] instead of row when accessing the result set.)
Regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Michael Paquier | 2026-11-24 03:52:33 | Re: Injection point: fix race condition between attach and cleanup |