Thread

Commits

  1. postgres_fdw: be more wary about shippability of reg* constants.

  2. Fix omissions in support for the "regcollation" type.

  3. postgres_fdw: set search_path to 'pg_catalog' while deparsing constants.

  1. postgres_fdw versus regconfig and similar constants

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-05-16T17:33:26Z

    Bug #17483 points out that postgres_fdw falls down pretty badly when
    a potentially shippable clause contains a "regconfig" constant [1].
    It doesn't check whether the constant refers to an object that's
    likely to exist on the remote side, and it fails to ensure that
    the printed name is properly schema-qualified.  The same flaws apply
    to constants of other OID alias types.  Below are some draft patches
    to address this.
    
    0001 deals with the lack-of-schema-qualification issue by forcing
    search_path to be just "pg_catalog" while we're deparsing constants.
    This seems straightforward, if annoyingly expensive, and it's enough
    to fix the bug as presented.
    
    0002 tightens deparse.c's rules to only consider an OID alias constant
    as shippable if the object it refers to is shippable.  This seems
    obvious in hindsight; I wonder how come we've not realized it before?
    However, this has one rather nasty problem for regconfig in particular:
    with our standard shippability rules none of the built-in text search
    configurations would be treated as shippable, because initdb gives them
    non-fixed OIDs above 9999.  That seems like a performance hit we don't
    want to take.  In the attached, I hacked around that by making a special
    exception for OIDs up to 16383, but that seems like a fairly ugly kluge.
    Anybody have a better idea?
    
    While using find_expr_references() as a reference for writing the new code
    in 0002, I was dismayed to find that it omitted handling regcollation;
    and a quick search showed that other places that specially process REG*
    types hadn't been updated for that addition either.  0003 closes those
    oversights.
    
    I've split this into three parts partially because they probably should be
    back-patched differently.  It seems like 0001 should go into all branches.
    0003 should go back to v13 where regcollation was added.  But I wonder if
    0002 should get back-patched at all: it seems like we're more likely to
    get performance complaints about quals no longer being shipped than we are
    to get kudos for not mistakenly shipping an unportable tsconfig reference.
    People could fix such performance issues by putting the config into an
    extension marked safe-to-ship, but they probably won't want to have to
    deal with that in a minor release.
    
    I've not done anything about a regression test yet.
    
    Thoughts?
    
    			regards, tom lane
    
    [1] https://www.postgresql.org/message-id/17483-795757fa99607659%40postgresql.org
    
    
  2. Re: postgres_fdw versus regconfig and similar constants

    Robert Haas <robertmhaas@gmail.com> — 2022-07-01T20:47:00Z

    On Mon, May 16, 2022 at 1:33 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > 0001 deals with the lack-of-schema-qualification issue by forcing
    > search_path to be just "pg_catalog" while we're deparsing constants.
    > This seems straightforward, if annoyingly expensive, and it's enough
    > to fix the bug as presented.
    
    Yeah, that does seem like the thing to do. I doubt it will be the last
    problem setting we need to add to that list, either. It's kind of
    unfortunate that data type output formatting is context-dependent like
    this, but I don't have an idea.
    
    > 0002 tightens deparse.c's rules to only consider an OID alias constant
    > as shippable if the object it refers to is shippable.  This seems
    > obvious in hindsight; I wonder how come we've not realized it before?
    > However, this has one rather nasty problem for regconfig in particular:
    > with our standard shippability rules none of the built-in text search
    > configurations would be treated as shippable, because initdb gives them
    > non-fixed OIDs above 9999.  That seems like a performance hit we don't
    > want to take.  In the attached, I hacked around that by making a special
    > exception for OIDs up to 16383, but that seems like a fairly ugly kluge.
    > Anybody have a better idea?
    
    No. It feels to me like there are not likely to be any really
    satisfying answers here. We have a way of mapping a given local table
    to a given foreign table, but to the best of my knowledge we have no
    similar mechanism for any other type of object. So it's just crude
    guesswork. Who is to say whether the fact that we have a local text
    search configuration means that there is a remote text search
    configuration with the same name, and even if yes, that it has the
    same semantics? And similarly for any other object types? Every
    release adds and occasionally removes SQL objects from the system
    catalogs, and depending on the object type, it can also vary by
    operating system. There are several multiple forks of PostgreSQL, too.
    
    > While using find_expr_references() as a reference for writing the new code
    > in 0002, I was dismayed to find that it omitted handling regcollation;
    > and a quick search showed that other places that specially process REG*
    > types hadn't been updated for that addition either.  0003 closes those
    > oversights.
    
    Makes sense.
    
    -- 
    Robert Haas
    EDB: http://www.enterprisedb.com
    
    
    
    
  3. Re: postgres_fdw versus regconfig and similar constants

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-07-17T22:25:19Z

    Robert Haas <robertmhaas@gmail.com> writes:
    > On Mon, May 16, 2022 at 1:33 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >> 0002 tightens deparse.c's rules to only consider an OID alias constant
    >> as shippable if the object it refers to is shippable.  This seems
    >> obvious in hindsight; I wonder how come we've not realized it before?
    >> However, this has one rather nasty problem for regconfig in particular:
    >> with our standard shippability rules none of the built-in text search
    >> configurations would be treated as shippable, because initdb gives them
    >> non-fixed OIDs above 9999.  That seems like a performance hit we don't
    >> want to take.  In the attached, I hacked around that by making a special
    >> exception for OIDs up to 16383, but that seems like a fairly ugly kluge.
    >> Anybody have a better idea?
    
    > No. It feels to me like there are not likely to be any really
    > satisfying answers here.
    
    Yeah.  Hearing no better ideas from anyone else either, pushed that way.
    
    I noted one interesting factoid while trying to make a test case for the
    missing-schema-qualification issue.  I thought of making a foreign table
    that maps to pg_class and checking what is shipped for
    
    select oid, relname from remote_pg_class where oid =
    'information_schema.key_column_usage'::regclass;
    
    (In hindsight, this wouldn't have worked anyway after patch 0002,
    because that OID would have been above 9999.)  But what I got was
    
     Foreign Scan on public.remote_pg_class  (cost=100.00..121.21 rows=4 width=68)
       Output: oid, relname
       Remote SQL: SELECT oid, relname FROM pg_catalog.pg_class WHERE ((oid = 13527::oid))
    
    The reason for that is that the constant is smashed to type OID so hard
    that we can no longer tell that it ever was regclass, thus there's no
    hope of deparsing it in a more-symbolic fashion.  I'm not sure if there's
    anything we could do about that that wouldn't break more things than
    it fixes (e.g. by making things that should look equal() not be so).
    But anyway, this effect may help explain the lack of previous complaints
    in this area.  regconfig arguments to text search functions might be
    pretty nearly the only realistic use-case for shipping symbolic reg*
    values to the remote.
    
    			regards, tom lane