postgres_fdw: statistics import can silently fall back to sampling across encodings

From: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Subject: postgres_fdw: statistics import can silently fall back to sampling across encodings
Date: 2026-11-23 22:41:17
Message-ID: CA+fm-ROJ14=X9h-yBBdCJF87Da3Nq4Zzp3f1NttjGhC6sz0uAA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

After an offline chat with Etsuro, starting a discussion here
on an issue in postgres_fdw's statistics import (28972b6fc3d).

It matches up a remote table's columns with the local ones by name to
copy over their stats. When the remote and local databases use
different encodings and a column name has a non-ASCII character, that
match can miss, because the same local name can correspond to more
than one distinct byte sequence on the remote side once encoding
conversion is involved [1]. When that happens, postgres_fdw quietly
falls back to sampling instead of importing the remote's stats, with
no indication that it happened for this reason.

The attached patch makes postgres_fdw detect that case and fall back
on purpose, rather than by accident.

Thoughts?

[1] Example: an EUC_JP remote and a UTF-8 local database, table with a
column named 日付.
Unpatched: WARNING: no attribute statistics found for column "日付"
ANALYZE falls back to sampling even though the remote has stats
for that column, with no hint as to why.
Patched: WARNING: could not import statistics for foreign table
"public.注文" --- remote server encoding "EUC_JP" differs from
local encoding "UTF8"

Regards,
Baji Shaik

Attachment Content-Type Size
0001-postgres_fdw-Fall-back-to-sampling-when-remote-encoding.patch application/octet-stream 8.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-11-23 22:55:35 Re: Include schema-qualified names in publication error messages (generalised to all of LR).
Previous Message Masahiko Sawada 2026-11-23 22:25:31 Re: Fix LogStandbySnapshot() race during logical decoding activation