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: 0001-postgres_fdw-Fall-back-to-sampling-when-remote-encoding.patch
Description: Binary data

Reply via email to