Skip to content
Snippets Groups Projects
  1. Sep 30, 2016
    • Peter Eisentraut's avatar
      Remove unnecessary prototypes · 0665023b
      Peter Eisentraut authored
      
      Prototypes for functions implementing V1-callable functions are no
      longer necessary.
      
      Reviewed-by: default avatarHeikki Linnakangas <hlinnaka@iki.fi>
      Reviewed-by: default avatarThomas Munro <thomas.munro@enterprisedb.com>
      0665023b
    • Peter Eisentraut's avatar
      Fix use of offsetof() · f1a469c9
      Peter Eisentraut authored
      
      Using offsetof() with a run-time computed argument is not allowed in
      either C or C++.  Apparently, gcc allows it, but g++ doesn't.
      
      Reviewed-by: default avatarHeikki Linnakangas <hlinnaka@iki.fi>
      Reviewed-by: default avatarThomas Munro <thomas.munro@enterprisedb.com>
      f1a469c9
    • Stephen Frost's avatar
      Remove superuser checks in pgstattuple · fd321a1d
      Stephen Frost authored
      Now that we track initial privileges on extension objects and changes to
      those permissions, we can drop the superuser() checks from the various
      functions which are part of the pgstattuple extension and rely on the
      GRANT system to control access to those functions.
      
      Since a pg_upgrade will preserve the version of the extension which
      existed prior to the upgrade, we can't simply modify the existing
      functions but instead need to create new functions which remove the
      checks and update the SQL-level functions to use the new functions
      (and to REVOKE EXECUTE rights on those functions from PUBLIC).
      
      Thanks to Tom and Andres for adding support for extensions to follow
      update paths (see: 40b449ae), allowing this patch to be much smaller
      since no new base version script needed to be included.
      
      Approach suggested by Noah.
      
      Reviewed by Michael Paquier.
      fd321a1d
  2. Sep 29, 2016
    • Tom Lane's avatar
      Allow contrib/file_fdw to read from a program, like COPY FROM PROGRAM. · 8e91e12b
      Tom Lane authored
      This patch just exposes COPY's FROM PROGRAM option in contrib/file_fdw.
      There don't seem to be any security issues with that that are any worse
      than what already exist with file_fdw and COPY; as in the existing cases,
      only superusers are allowed to control what gets executed.
      
      A regression test case might be nice here, but choosing a 100% portable
      command to run is hard.  (We haven't got a test for COPY FROM PROGRAM
      itself, either.)
      
      Corey Huinker and Adam Gomaa, reviewed by Amit Langote
      
      Discussion: <CADkLM=dGDGmaEiZ=UDepzumWg-CVn7r8MHPjr2NArj8S3TsROQ@mail.gmail.com>
      8e91e12b
    • Heikki Linnakangas's avatar
      Don't bother to lock bufmgr partitions in pg_buffercache. · 6e654546
      Heikki Linnakangas authored
      That makes the view a lot less disruptive to use on a production system.
      Without the locks, you don't get a consistent snapshot across all buffers,
      but that's OK. It wasn't a very useful guarantee in practice.
      
      Ivan Kartyshov, reviewed by Tomas Vondra and Robert Haas.
      
      Discusssion: <f9d6cab2-73a7-7a84-55a8-07dcb8516ae5@postgrespro.ru>
      6e654546
  3. Sep 27, 2016
    • Tom Lane's avatar
      Improve contrib/cube's handling of zero-D cubes, infinities, and NaNs. · f31a931f
      Tom Lane authored
      It's always been possible to create a zero-dimensional cube by converting
      from a zero-length float8 array, but cube_in failed to accept the '()'
      representation that cube_out produced for that case, resulting in a
      dump/reload hazard.  Make it accept the case.  Also fix a couple of
      other places that didn't behave sanely for zero-dimensional cubes:
      cube_size would produce 1.0 when surely the answer should be 0.0,
      and g_cube_distance risked a divide-by-zero failure.
      
      Likewise, it's always been possible to create cubes containing float8
      infinity or NaN coordinate values, but cube_in couldn't parse such input,
      and cube_out produced platform-dependent spellings of the values.  Convert
      them to use float8in_internal and float8out_internal so that the behavior
      will be the same as for float8, as we recently did for the core geometric
      types (cf commit 50861cd6).  As in that commit, I don't pretend that this
      patch fixes all insane corner-case behaviors that may exist for NaNs, but
      it's a step forward.
      
      (This change allows removal of the separate cube_1.out and cube_3.out
      expected-files, as the platform dependency that previously required them
      is now gone: an underflowing coordinate value will now produce an error
      not plus or minus zero.)
      
      Make errors from cube_in follow project conventions as to spelling
      ("invalid input syntax for cube" not "bad cube representation")
      and errcode (INVALID_TEXT_REPRESENTATION not SYNTAX_ERROR).
      
      Also a few marginal code cleanups and comment improvements.
      
      Tom Lane, reviewed by Amul Sul
      
      Discussion: <15085.1472494782@sss.pgh.pa.us>
      f31a931f
  4. Sep 15, 2016
    • Heikki Linnakangas's avatar
      Fix building with LibreSSL. · 5c6df67e
      Heikki Linnakangas authored
      LibreSSL defines OPENSSL_VERSION_NUMBER to claim that it is version 2.0.0,
      but it doesn't have the functions added in OpenSSL 1.1.0. Add autoconf
      checks for the individual functions we need, and stop relying on
      OPENSSL_VERSION_NUMBER.
      
      Backport to 9.5 and 9.6, like the patch that broke this. In the
      back-branches, there are still a few OPENSSL_VERSION_NUMBER checks left,
      to check for OpenSSL 0.9.8 or 0.9.7. I left them as they were - LibreSSL
      has all those functions, so they work as intended.
      
      Per buildfarm member curculio.
      
      Discussion: <2442.1473957669@sss.pgh.pa.us>
      5c6df67e
    • Robert Haas's avatar
      pg_buffercache: Allow huge allocations. · 8a503526
      Robert Haas authored
      Otherwise, users who have configured shared_buffers >= 256GB won't
      be able to use this module.  There probably aren't many of those, but
      it doesn't hurt anything to fix it so that it works.
      
      Backpatch to 9.4, where MemoryContextAllocHuge was introduced.  The
      same problem exists in older branches, but there's no easy way to
      fix it there.
      
      KaiGai Kohei
      8a503526
    • Heikki Linnakangas's avatar
      Support OpenSSL 1.1.0. · 593d4e47
      Heikki Linnakangas authored
      Changes needed to build at all:
      
      - Check for SSL_new in configure, now that SSL_library_init is a macro.
      - Do not access struct members directly. This includes some new code in
        pgcrypto, to use the resource owner mechanism to ensure that we don't
        leak OpenSSL handles, now that we can't embed them in other structs
        anymore.
      - RAND_SSLeay() -> RAND_OpenSSL()
      
      Changes that were needed to silence deprecation warnings, but were not
      strictly necessary:
      
      - RAND_pseudo_bytes() -> RAND_bytes().
      - SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
      - ASN1_STRING_data() -> ASN1_STRING_get0_data()
      - DH_generate_parameters() -> DH_generate_parameters()
      - Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
        riddance!)
      
      Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
      for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
      immemorial.
      
      Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
      the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
      Regenerate the test certificates with that. The "openssl" binary, used to
      generate the certificates, is also now more picky, and throws an error
      if an X509 extension is specified in "req_extensions", but that section
      is empty.
      
      Backpatch to all supported branches, per popular demand. In back-branches,
      we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
      too, but I didn't test it. In master, we only support 0.9.8 and above.
      
      Patch by Andreas Karlsson, with additional changes by me.
      
      Discussion: <20160627151604.GD1051@msg.df7cb.de>
      593d4e47
  5. Sep 06, 2016
    • Peter Eisentraut's avatar
      Add location field to DefElem · 49eb0fd0
      Peter Eisentraut authored
      
      Add a location field to the DefElem struct, used to parse many utility
      commands.  Update various error messages to supply error position
      information.
      
      To propogate the error position information in a more systematic way,
      create a ParseState in standard_ProcessUtility() and pass that to
      interested functions implementing the utility commands.  This seems
      better than passing the query string and then reassembling a parse state
      ad hoc, which violates the encapsulation of the ParseState type.
      
      Reviewed-by: default avatarPavel Stehule <pavel.stehule@gmail.com>
      49eb0fd0
  6. Sep 02, 2016
    • Heikki Linnakangas's avatar
      Move code shared between libpq and backend from backend/libpq/ to common/. · ec136d19
      Heikki Linnakangas authored
      When building libpq, ip.c and md5.c were symlinked or copied from
      src/backend/libpq into src/interfaces/libpq, but now that we have a
      directory specifically for routines that are shared between the server and
      client binaries, src/common/, move them there.
      
      Some routines in ip.c were only used in the backend. Keep those in
      src/backend/libpq, but rename to ifaddr.c to avoid confusion with the file
      that's now in common.
      
      Fix the comment in src/common/Makefile to reflect how libpq actually links
      those files.
      
      There are two more files that libpq symlinks directly from src/backend:
      encnames.c and wchar.c. I don't feel compelled to move those right now,
      though.
      
      Patch by Michael Paquier, with some changes by me.
      
      Discussion: <69938195-9c76-8523-0af8-eb718ea5b36e@iki.fi>
      ec136d19
  7. Aug 31, 2016
    • Tom Lane's avatar
      Fix a bunch of places that called malloc and friends with no NULL check. · 052cc223
      Tom Lane authored
      Where possible, use palloc or pg_malloc instead; otherwise, insert
      explicit NULL checks.
      
      Generally speaking, these are places where an actual OOM is quite
      unlikely, either because they're in client programs that don't
      allocate all that much, or they're very early in process startup
      so that we'd likely have had a fork() failure instead.  Hence,
      no back-patch, even though this is nominally a bug fix.
      
      Michael Paquier, with some adjustments by me
      
      Discussion: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
      052cc223
  8. Aug 30, 2016
    • Tom Lane's avatar
      Simplify correct use of simple_prompt(). · 9daec77e
      Tom Lane authored
      The previous API for this function had it returning a malloc'd string.
      That meant that callers had to check for NULL return, which few of them
      were doing, and it also meant that callers had to remember to free()
      the string later, which required extra logic in most cases.
      
      Instead, make simple_prompt() write into a buffer supplied by the caller.
      Anywhere that the maximum required input length is reasonably small,
      which is almost all of the callers, we can just use a local or static
      array as the buffer instead of dealing with malloc/free.
      
      A fair number of callers used "pointer == NULL" as a proxy for "haven't
      requested the password yet".  Maintaining the same behavior requires
      adding a separate boolean flag for that, which adds back some of the
      complexity we save by removing free()s.  Nonetheless, this nets out
      at a small reduction in overall code size, and considerably less code
      than we would have had if we'd added the missing NULL-return checks
      everywhere they were needed.
      
      In passing, clean up the API comment for simple_prompt() and get rid
      of a very-unnecessary malloc/free in its Windows code path.
      
      This is nominally a bug fix, but it does not seem worth back-patching,
      because the actual risk of an OOM failure in any of these places seems
      pretty tiny, and all of them are client-side not server-side anyway.
      
      This patch is by me, but it owes a great deal to Michael Paquier
      who identified the problem and drafted a patch for fixing it the
      other way.
      
      Discussion: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
      9daec77e
  9. Aug 29, 2016
    • Heikki Linnakangas's avatar
      Remove support for OpenSSL versions older than 0.9.8. · 9b7cd59a
      Heikki Linnakangas authored
      OpenSSL officially only supports 1.0.1 and newer. Some OS distributions
      still provide patches for 0.9.8, but anything older than that is not
      interesting anymore. Let's simplify things by removing compatibility code.
      
      Andreas Karlsson, with small changes by me.
      9b7cd59a
  10. Aug 27, 2016
    • Tom Lane's avatar
      Add macros to make AllocSetContextCreate() calls simpler and safer. · ea268cdc
      Tom Lane authored
      I found that half a dozen (nearly 5%) of our AllocSetContextCreate calls
      had typos in the context-sizing parameters.  While none of these led to
      especially significant problems, they did create minor inefficiencies,
      and it's now clear that expecting people to copy-and-paste those calls
      accurately is not a great idea.  Let's reduce the risk of future errors
      by introducing single macros that encapsulate the common use-cases.
      Three such macros are enough to cover all but two special-purpose contexts;
      those two calls can be left as-is, I think.
      
      While this patch doesn't in itself improve matters for third-party
      extensions, it doesn't break anything for them either, and they can
      gradually adopt the simplified notation over time.
      
      In passing, change TopMemoryContext to use the default allocation
      parameters.  Formerly it could only be extended 8K at a time.  That was
      probably reasonable when this code was written; but nowadays we create
      many more contexts than we did then, so that it's not unusual to have a
      couple hundred K in TopMemoryContext, even without considering various
      dubious code that sticks other things there.  There seems no good reason
      not to let it use growing blocks like most other contexts.
      
      Back-patch to 9.6, mostly because that's still close enough to HEAD that
      it's easy to do so, and keeping the branches in sync can be expected to
      avoid some future back-patching pain.  The bugs fixed by these changes
      don't seem to be significant enough to justify fixing them further back.
      
      Discussion: <21072.1472321324@sss.pgh.pa.us>
      ea268cdc
  11. Aug 26, 2016
    • Heikki Linnakangas's avatar
      Support OID system column in postgres_fdw. · ae025a15
      Heikki Linnakangas authored
      You can use ALTER FOREIGN TABLE SET WITH OIDS on a foreign table, but the
      oid column read out as zeros, because the postgres_fdw didn't know about
      it. Teach postgres_fdw how to fetch it.
      
      Etsuro Fujita, with an additional test case by me.
      
      Discussion: <56E90A76.5000503@lab.ntt.co.jp>
      ae025a15
  12. Aug 24, 2016
  13. Aug 18, 2016
  14. Aug 17, 2016
    • Tom Lane's avatar
      Fix -e option in contrib/intarray/bench/bench.pl. · 6657acc0
      Tom Lane authored
      As implemented, -e ran an EXPLAIN but then discarded the output, which
      certainly seems pointless.  Make it print to stdout instead.  It's been
      like that forever, so back-patch to all supported branches.
      
      Daniel Gustafsson, reviewed by Andreas Scherbaum
      
      Patch: <B97BDCB7-A3B3-4734-90B5-EDD586941629@yesql.se>
      6657acc0
    • Tom Lane's avatar
      Improve parsetree representation of special functions such as CURRENT_DATE. · 0bb51aa9
      Tom Lane authored
      We implement a dozen or so parameterless functions that the SQL standard
      defines special syntax for.  Up to now, that was done by converting them
      into more or less ad-hoc constructs such as "'now'::text::date".  That's
      messy for multiple reasons: it exposes what should be implementation
      details to users, and performance is worse than it needs to be in several
      cases.  To improve matters, invent a new expression node type
      SQLValueFunction that can represent any of these parameterless functions.
      
      Bump catversion because this changes stored parsetrees for rules.
      
      Discussion: <30058.1463091294@sss.pgh.pa.us>
      0bb51aa9
  15. Aug 14, 2016
    • Tom Lane's avatar
      Fix assorted bugs in contrib/bloom. · d6c9e05c
      Tom Lane authored
      In blinsert(), cope with the possibility that a page we pull from the
      notFullPage list is marked BLOOM_DELETED.  This could happen if VACUUM
      recently marked it deleted but hasn't (yet) updated the metapage.
      We can re-use such a page safely, but we *must* reinitialize it so that
      it's no longer marked deleted.
      
      Fix blvacuum() so that it updates the notFullPage list even if it's
      going to update it to empty.  The previous "optimization" of skipping
      the update seems pretty dubious, since it means that the next blinsert()
      will uselessly visit whatever pages we left in the list.
      
      Uniformly treat PageIsNew pages the same as deleted pages.  This should
      allow proper recovery if a crash occurs just after relation extension.
      
      Properly use vacuum_delay_point, not assorted ad-hoc CHECK_FOR_INTERRUPTS
      calls, in the blvacuum() main loop.
      
      Fix broken tuple-counting logic: blvacuum.c counted the number of live
      index tuples over again in each scan, leading to VACUUM VERBOSE reporting
      some multiple of the actual number of surviving index tuples after any
      vacuum that removed any tuples (since they'd be counted in blvacuum, maybe
      more than once, and then again in blvacuumcleanup, without ever zeroing the
      counter).  It's sufficient to count them in blvacuumcleanup.
      
      stats->estimated_count is a boolean, not a counter, and we don't want
      to set it true, so don't add tuple counts to it.
      
      Add a couple of Asserts that we don't overrun available space on a bloom
      page.  I don't think there's any bug there today, but the way the
      FreeBlockNumberArray size calculation is set up is scarily fragile, and
      BloomPageGetFreeSpace isn't much better.  The Asserts should help catch
      any future mistakes.
      
      Per investigation of a report from Jeff Janes.  I think the first item
      above may explain his report; the other changes were things I noticed
      while casting about for an explanation.
      
      Report: <CAMkU=1xEUuBphDwDmB1WjN4+td4kpnEniFaTBxnk1xzHCw8_OQ@mail.gmail.com>
      d6c9e05c
    • Tom Lane's avatar
      Add SQL-accessible functions for inspecting index AM properties. · ed0097e4
      Tom Lane authored
      Per discussion, we should provide such functions to replace the lost
      ability to discover AM properties by inspecting pg_am (cf commit
      65c5fcd3).  The added functionality is also meant to displace any code
      that was looking directly at pg_index.indoption, since we'd rather not
      believe that the bit meanings in that field are part of any client API
      contract.
      
      As future-proofing, define the SQL API to not assume that properties that
      are currently AM-wide or index-wide will remain so unless they logically
      must be; instead, expose them only when inquiring about a specific index
      or even specific index column.  Also provide the ability for an index
      AM to override the behavior.
      
      In passing, document pg_am.amtype, overlooked in commit 473b9328.
      
      Andrew Gierth, with kibitzing by me and others
      
      Discussion: <87mvl5on7n.fsf@news-spur.riddles.org.uk>
      ed0097e4
  16. Aug 11, 2016
  17. Aug 10, 2016
  18. Aug 07, 2016
    • Tom Lane's avatar
      Don't propagate a null subtransaction snapshot up to parent transaction. · bcbecbce
      Tom Lane authored
      This oversight could cause logical decoding to fail to decode an outer
      transaction containing changes, if a subtransaction had an XID but no
      actual changes.  Per bug #14279 from Marko Tiikkaja.  Patch by Marko
      based on analysis by Andrew Gierth.
      
      Discussion: <20160804191757.1430.39011@wrigleys.postgresql.org>
      bcbecbce
  19. Jul 28, 2016
    • Tom Lane's avatar
      Fix assorted fallout from IS [NOT] NULL patch. · 9492cf86
      Tom Lane authored
      Commits 4452000f et al established semantics for NullTest.argisrow that
      are a bit different from its initial conception: rather than being merely
      a cache of whether we've determined the input to have composite type,
      the flag now has the further meaning that we should apply field-by-field
      testing as per the standard's definition of IS [NOT] NULL.  If argisrow
      is false and yet the input has composite type, the construct instead has
      the semantics of IS [NOT] DISTINCT FROM NULL.  Update the comments in
      primnodes.h to clarify this, and fix ruleutils.c and deparse.c to print
      such cases correctly.  In the case of ruleutils.c, this merely results in
      cosmetic changes in EXPLAIN output, since the case can't currently arise
      in stored rules.  However, it represents a live bug for deparse.c, which
      would formerly have sent a remote query that had semantics different
      from the local behavior.  (From the user's standpoint, this means that
      testing a remote nested-composite column for null-ness could have had
      unexpected recursive behavior much like that fixed in 4452000f.)
      
      In a related but somewhat independent fix, make plancat.c set argisrow
      to false in all NullTest expressions constructed to represent "attnotnull"
      constructs.  Since attnotnull is actually enforced as a simple null-value
      check, this is a more accurate representation of the semantics; we were
      previously overpromising what it meant for composite columns, which might
      possibly lead to incorrect planner optimizations.  (It seems that what the
      SQL spec expects a NOT NULL constraint to mean is an IS NOT NULL test, so
      arguably we are violating the spec and should fix attnotnull to do the
      other thing.  If we ever do, this part should get reverted.)
      
      Back-patch, same as the previous commit.
      
      Discussion: <10682.1469566308@sss.pgh.pa.us>
      9492cf86
  20. Jul 26, 2016
    • Robert Haas's avatar
      Repair damage done by citext--1.1--1.2.sql. · fe5e3fce
      Robert Haas authored
      That script is incorrect in that it sets the combine function for
      max(citext) twice instead of setting the combine function for
      max(citext) once and the combine functon for min(citext) once.  The
      consequence is that if you install 1.0 or 1.1 and then update to 1.2,
      you end up with min(citext) not having a combine function, contrary to
      what was intended.  If you install 1.2 directly, you're OK.
      
      Fix things up by defining a new 1.3 version.  Upgrading from 1.2 to
      1.3 won't change anything for people who first installed the 1.2
      version, but people upgrading from 1.0 or 1.1 will get the right
      catalog contents once they reach 1.3.
      
      Report and patch by David Rowley, reviewed by Andreas Karlsson.
      fe5e3fce
    • Peter Eisentraut's avatar
      Message style improvements · 40fcfec8
      Peter Eisentraut authored
      40fcfec8
  21. Jul 25, 2016
  22. Jul 21, 2016
    • Tom Lane's avatar
      Make contrib regression tests safe for Danish locale. · d70d1191
      Tom Lane authored
      In btree_gin and citext, avoid some not-particularly-interesting
      dependencies on the sorting of 'aa'.  In tsearch2, use COLLATE "C" to
      remove an uninteresting dependency on locale sort order (and thereby
      allow removal of a variant expected-file).
      
      Also, in citext, avoid assuming that lower('I') = 'i'.  This isn't relevant
      to Danish but it does fail in Turkish.
      d70d1191
  23. Jul 18, 2016
    • Tom Lane's avatar
      Establish conventions about global object names used in regression tests. · 18555b13
      Tom Lane authored
      To ensure that "make installcheck" can be used safely against an existing
      installation, we need to be careful about what global object names
      (database, role, and tablespace names) we use; otherwise we might
      accidentally clobber important objects.  There's been a weak consensus that
      test databases should have names including "regression", and that test role
      names should start with "regress_", but we didn't have any particular rule
      about tablespace names; and neither of the other rules was followed with
      any consistency either.
      
      This commit moves us a long way towards having a hard-and-fast rule that
      regression test databases must have names including "regression", and that
      test role and tablespace names must start with "regress_".  It's not
      completely there because I did not touch some test cases in rolenames.sql
      that test creation of special role names like "session_user".  That will
      require some rethinking of exactly what we want to test, whereas the intent
      of this patch is just to hit all the cases in which the needed renamings
      are cosmetic.
      
      There is no enforcement mechanism in this patch either, but if we don't
      add one we can expect that the tests will soon be violating the convention
      again.  Again, that's not such a cosmetic change and it will require
      discussion.  (But I did use a quick-hack enforcement patch to find these
      cases.)
      
      Discussion: <16638.1468620817@sss.pgh.pa.us>
      18555b13
  24. Jul 17, 2016
    • Peter Eisentraut's avatar
      Use correct symbol for minimum int64 value · f36ca9af
      Peter Eisentraut authored
      The old code used SEQ_MINVALUE to get the smallest int64 value.  This
      was done as a convenience to avoid having to deal with INT64_IS_BUSTED,
      but that is obsolete now.  Also, it is incorrect because the smallest
      int64 value is actually SEQ_MINVALUE-1.  Fix by using PG_INT64_MIN.
      f36ca9af
  25. 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
  26. Jul 01, 2016
  27. 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
  28. Jun 24, 2016
  29. 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
Loading