Skip to content
Snippets Groups Projects
  1. Jul 15, 2016
    • Tom Lane's avatar
      Avoid invalidating all foreign-join cached plans when user mappings change. · 45639a05
      Tom Lane authored
      We must not push down a foreign join when the foreign tables involved
      should be accessed under different user mappings.  Previously we tried
      to enforce that rule literally during planning, but that meant that the
      resulting plans were dependent on the current contents of the
      pg_user_mapping catalog, and we had to blow away all cached plans
      containing any remote join when anything at all changed in pg_user_mapping.
      This could have been improved somewhat, but the fact that a syscache inval
      callback has very limited info about what changed made it hard to do better
      within that design.  Instead, let's change the planner to not consider user
      mappings per se, but to allow a foreign join if both RTEs have the same
      checkAsUser value.  If they do, then they necessarily will use the same
      user mapping at runtime, and we don't need to know specifically which one
      that is.  Post-plan-time changes in pg_user_mapping no longer require any
      plan invalidation.
      
      This rule does give up some optimization ability, to wit where two foreign
      table references come from views with different owners or one's from a view
      and one's directly in the query, but nonetheless the same user mapping
      would have applied.  We'll sacrifice the first case, but to not regress
      more than we have to in the second case, allow a foreign join involving
      both zero and nonzero checkAsUser values if the nonzero one is the same as
      the prevailing effective userID.  In that case, mark the plan as only
      runnable by that userID.
      
      The plancache code already had a notion of plans being userID-specific,
      in order to support RLS.  It was a little confused though, in particular
      lacking clarity of thought as to whether it was the rewritten query or just
      the finished plan that's dependent on the userID.  Rearrange that code so
      that it's clearer what depends on which, and so that the same logic applies
      to both RLS-injected role dependency and foreign-join-injected role
      dependency.
      
      Note that this patch doesn't remove the other issue mentioned in the
      original complaint, which is that while we'll reliably stop using a foreign
      join if it's disallowed in a new context, we might fail to start using a
      foreign join if it's now allowed, but we previously created a generic
      cached plan that didn't use one.  It was agreed that the chance of winning
      that way was not high enough to justify the much larger number of plan
      invalidations that would have to occur if we tried to cause it to happen.
      
      In passing, clean up randomly-varying spelling of EXPLAIN commands in
      postgres_fdw.sql, and fix a COSTS ON example that had been allowed to
      leak into the committed tests.
      
      This reverts most of commits fbe5a3fb and 5d4171d1, which were the
      previous attempt at ensuring we wouldn't push down foreign joins that
      span permissions contexts.
      
      Etsuro Fujita and Tom Lane
      
      Discussion: <d49c1e5b-f059-20f4-c132-e9752ee0113e@lab.ntt.co.jp>
      45639a05
  2. Jul 01, 2016
  3. Jun 25, 2016
    • Alvaro Herrera's avatar
      Fix handling of multixacts predating pg_upgrade · e3ad3ffa
      Alvaro Herrera authored
      After pg_upgrade, it is possible that some tuples' Xmax have multixacts
      corresponding to the old installation; such multixacts cannot have
      running members anymore.  In many code sites we already know not to read
      them and clobber them silently, but at least when VACUUM tries to freeze
      a multixact or determine whether one needs freezing, there's an attempt
      to resolve it to its member transactions by calling GetMultiXactIdMembers,
      and if the multixact value is "in the future" with regards to the
      current valid multixact range, an error like this is raised:
          ERROR:  MultiXactId 123 has not been created yet -- apparent wraparound
      and vacuuming fails.  Per discussion with Andrew Gierth, it is completely
      bogus to try to resolve multixacts coming from before a pg_upgrade,
      regardless of where they stand with regards to the current valid
      multixact range.
      
      It's possible to get from under this problem by doing SELECT FOR UPDATE
      of the problem tuples, but if tables are large, this is slow and
      tedious, so a more thorough solution is desirable.
      
      To fix, we realize that multixacts in xmax created in 9.2 and previous
      have a specific bit pattern that is never used in 9.3 and later (we
      already knew this, per comments and infomask tests sprinkled in various
      places, but we weren't leveraging this knowledge appropriately).
      Whenever the infomask of the tuple matches that bit pattern, we just
      ignore the multixact completely as if Xmax wasn't set; or, in the case
      of tuple freezing, we act as if an unwanted value is set and clobber it
      without decoding.  This guarantees that no errors will be raised, and
      that the values will be progressively removed until all tables are
      clean.  Most callers of GetMultiXactIdMembers are patched to recognize
      directly that the value is a removable "empty" multixact and avoid
      calling GetMultiXactIdMembers altogether.
      
      To avoid changing the signature of GetMultiXactIdMembers() in back
      branches, we keep the "allow_old" boolean flag but rename it to
      "from_pgupgrade"; if the flag is true, we always return an empty set
      instead of looking up the multixact.  (I suppose we could remove the
      argument in the master branch, but I chose not to do so in this commit).
      
      This was broken all along, but the error-facing message appeared first
      because of commit 8e9a16ab and was partially fixed in a25c2b7c.
      This fix, backpatched all the way back to 9.3, goes approximately in the
      same direction as a25c2b7c but should cover all cases.
      
      Bug analysis by Andrew Gierth and Álvaro Herrera.
      
      A number of public reports match this bug:
        https://www.postgresql.org/message-id/20140330040029.GY4582@tamriel.snowman.net
        https://www.postgresql.org/message-id/538F3D70.6080902@publicrelay.com
        https://www.postgresql.org/message-id/556439CF.7070109@pscs.co.uk
        https://www.postgresql.org/message-id/SG2PR06MB0760098A111C88E31BD4D96FB3540@SG2PR06MB0760.apcprd06.prod.outlook.com
        https://www.postgresql.org/message-id/20160615203829.5798.4594@wrigleys.postgresql.org
      e3ad3ffa
  4. Jun 24, 2016
  5. Jun 20, 2016
    • Tom Lane's avatar
      pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. · e611515d
      Tom Lane authored
      Per buildfarm.  Fortunately, it's not quite too late to squeeze this fix
      into the pg_trgm 1.3 update.
      e611515d
    • Tom Lane's avatar
      Fix comparison of similarity to threshold in GIST trigram searches. · 9c852566
      Tom Lane authored
      There was some very strange code here, dating to commit b525bf77, that
      purported to work around an ancient gcc bug by forcing a float4 comparison
      to be done as int instead.  Commit 5871b884 broke that when it changed
      one side of the comparison to "double" but left the comparison code alone.
      Commit f576b17c doubled down on the weirdness by introducing a "volatile"
      marker, which had nothing to do with the actual problem.
      
      Guess that the gcc bug, even if it's still present in the wild, was
      triggered by comparison of float4's and can be avoided if we store the
      result of cnt_sml() into a double before comparing to the double "nlimit".
      This will at least work correctly on non-broken compilers, and it's way
      more readable.
      
      Per bug #14202 from Greg Navis.  Add a regression test based on his
      example.
      
      Report: <20160620115321.5792.10766@wrigleys.postgresql.org>
      9c852566
  6. Jun 18, 2016
    • Tom Lane's avatar
      Fix parallel-safety markings for contrib/dblink. · 7e81a18d
      Tom Lane authored
      As shown by buildfarm reports, dblink_build_sql_insert and
      dblink_build_sql_update are *not* parallel safe, because they
      may attempt to access temporary tables of the local session.
      
      Although dblink_build_sql_delete doesn't actually touch the
      contents of the referenced table, it seems consistent and prudent
      to mark it PARALLEL RESTRICTED too.
      7e81a18d
  7. Jun 17, 2016
    • Robert Haas's avatar
      pg_visibility: Add pg_truncate_visibility_map function. · 71d05a2c
      Robert Haas authored
      This requires some core changes as well so that we can properly
      WAL-log the truncation.  Specifically, it changes the format of the
      XLOG_SMGR_TRUNCATE WAL record, so bump XLOG_PAGE_MAGIC.
      
      Patch by me, reviewed but not fully endorsed by Andres Freund.
      71d05a2c
    • Robert Haas's avatar
      Update dblink extension for parallel query. · 20eb2731
      Robert Haas authored
      Almost all functions provided by this extension are PARALLEL
      RESTRICTED.  Mostly, that's because the leader's TCP connections won't
      be shared with the workers, but in some cases like dblink_get_pkey
      it's because they obtain locks which might be released early if taken
      within a parallel worker.  dblink_fdw_validator probably can't be used
      in a query anyway, but there would be no problem from the point of
      view of parallel query if it were, so it's PARALLEL SAFE.
      
      Andreas Karlsson
      20eb2731
    • Robert Haas's avatar
      postgres_fdw: Rephrase comment. · 177c56d6
      Robert Haas authored
      Per gripe from Thomas Munro, who only complained about a more
      localized problem, but I couldn't resist a bit more wordsmithing.
      177c56d6
  8. Jun 15, 2016
    • Robert Haas's avatar
      Add integrity-checking functions to pg_visibility. · e472ce96
      Robert Haas authored
      The new pg_check_visible() and pg_check_frozen() functions can be used to
      verify that the visibility map bits for a relation's data pages match the
      actual state of the tuples on those pages.
      
      Amit Kapila and Robert Haas, reviewed (in earlier versions) by Andres
      Freund.  Additional testing help by Thomas Munro.
      e472ce96
  9. Jun 14, 2016
    • Robert Haas's avatar
      Update xml2 extension for parallel query. · 13e74531
      Robert Haas authored
      All functions provided by this extension are PARALLEL SAFE.
      
      Andreas Karlsson
      13e74531
    • Robert Haas's avatar
      Update uuid-ossp extension for parallel query. · 20f6c3a2
      Robert Haas authored
      All functions provided by this extension are PARALLEL SAFE.
      
      Andreas Karlsson
      20f6c3a2
    • Robert Haas's avatar
      Update unaccent extension for parallel query. · 202ac08c
      Robert Haas authored
      All functions provided by this extension are PARALLEL SAFE.
      
      Andreas Karlsson
      202ac08c
    • Robert Haas's avatar
      Update sslinfo extension for parallel query. · 6b7d11ff
      Robert Haas authored
      All functions provided by this extension are PARALLEL RESTRICTED,
      because they provide information about the connection state.  Parallel
      workers don't have this information and therefore these functions
      can't be executed in a worker (but they can be present in a query some
      other part of which uses parallelism).
      
      Andreas Karlsson
      6b7d11ff
    • Robert Haas's avatar
      Update extensions with GIN/GIST support for parallel query. · 2910fc82
      Robert Haas authored
      Commit 749a787c bumped the extension
      version on all of these extensions already, and we haven't had a
      release since then, so we can make further changes without bumping the
      extension version again.  Take this opportunity to mark all of the
      functions exported by these modules PARALLEL SAFE -- except for
      pg_trgm's set_limit().  Mark that one PARALLEL RESTRICTED, because it
      makes a persistent change to a GUC value.
      
      Note that some of the markings added by this commit don't have any
      effect; for example, gseg_picksplit() isn't likely to be mentioned
      explicitly in a query and therefore it's parallel-safety marking will
      never be consulted.  But this commit just marks everything for
      consistency: if it were somehow used in a query, that would be fine as
      far as parallel query is concerned, since it does not consult any
      backend-private state, attempt to write data, etc.
      
      Andreas Karlsson, with a few revisions by me.
      2910fc82
    • Robert Haas's avatar
      postgres_fdw: Check PlaceHolderVars before pushing down a join. · 131c7e70
      Robert Haas authored
      As discovered by Andreas Seltenreich via sqlsmith, it's possible for a
      remote join to need to generate a target list which contains a
      PlaceHolderVar which would need to be evaluated on the remote server.
      This happens when we try to push down a join tree which contains outer
      joins and the nullable side of the join contains a subquery which
      evauates some expression which can go to NULL above the level of the
      join.  Since the deparsing logic can't build a remote query that
      involves subqueries, it fails while trying to produce an SQL query
      that can be sent to the remote side.  Detect such cases and don't try
      to push down the join at all.
      
      It's actually fine to push down the join if the PlaceHolderVar needs
      to be evaluated at the current join level.  This patch makes a small
      change to build_tlist_to_deparse so that this case will work.
      
      Amit Langote, Ashutosh Bapat, and me.
      131c7e70
    • Tom Lane's avatar
      Minor fixes in contrib installation scripts. · 5484c0a9
      Tom Lane authored
      Extension scripts should never use CREATE OR REPLACE for initial object
      creation.  If there is a collision with a pre-existing (probably
      user-created) object, we want extension installation to fail, not silently
      overwrite the user's object.  Bloom and sslinfo both violated this precept.
      
      Also fix a number of scripts that had no standard header (the file name
      comment and the \echo...\quit guard).  Probably the \echo...\quit hack
      is less important now than it was in 9.1 days, but that doesn't mean
      that individual extensions get to choose whether to use it or not.
      
      And fix a couple of evident copy-and-pasteos in file name comments.
      
      No need for back-patch: the REPLACE bugs are both new in 9.6, and the
      rest of this is pretty much cosmetic.
      
      Andreas Karlsson and Tom Lane
      5484c0a9
    • Robert Haas's avatar
      postgres_fdw: Promote an Assert() to elog(). · 332fdbef
      Robert Haas authored
      Andreas Seltenreich reports that it is possible for a PlaceHolderVar
      to creep into this tlist, and I fear that even after that's fixed we
      might have other, similar bugs in this area either now or in the
      future.  There's a lot of action-at-a-distance here, because the
      validity of this assertion depends on core planner behavior; so, let's
      use elog() to make sure we catch this even in non-assert builds,
      rather than just crashing.
      332fdbef
  10. Jun 12, 2016
  11. Jun 10, 2016
  12. Jun 09, 2016
  13. Jun 07, 2016
Loading