1. 20 Dec, 2017 1 commit
  2. 19 Dec, 2017 5 commits
  3. 18 Dec, 2017 6 commits
    • Andres Freund's avatar
      Add shared tuplestores. · ab9e0e71
      Andres Freund authored
      SharedTuplestore allows multiple participants to write into it and
      then read the tuples back from it in parallel.  Each reader receives
      partial results.
      
      For now it always uses disk files, but other buffering policies and
      other kinds of scans (ie each reader receives complete results) may be
      useful in future.
      
      The upcoming parallel hash join feature will use this facility.
      
      Author: Thomas Munro
      Reviewed-By: Peter Geoghegan, Andres Freund, Robert Haas
      Discussion: https://postgr.es/m/CAEepm=2W=cOkiZxcg6qiFQP-dHUe09aqTrEMM7yJDrHMhDv_RA@mail.gmail.com
      ab9e0e71
    • Peter Eisentraut's avatar
      Move SCRAM-related name definitions to scram-common.h · 25d53269
      Peter Eisentraut authored
      Mechanism names for SCRAM and channel binding names have been included
      in scram.h by the libpq frontend code, and this header references a set
      of routines which are only used by the backend.  scram-common.h is on
      the contrary usable by both the backend and libpq, so getting those
      names from there seems more reasonable.
      
      Author: Michael Paquier <michael.paquier@gmail.com>
      25d53269
    • Peter Eisentraut's avatar
      doc: Fix figures in example description · 53cba77b
      Peter Eisentraut authored
      oversight in 244c8b46Reported-by: default avatarBlaz Merela <blaz@merela.org>
      53cba77b
    • Fujii Masao's avatar
      Fix bug in cancellation of non-exclusive backup to avoid assertion failure. · 56a95ee5
      Fujii Masao authored
      Previously an assertion failure occurred when pg_stop_backup() for
      non-exclusive backup was aborted while it's waiting for WAL files to
      be archived. This assertion failure happened in do_pg_abort_backup()
      which was called when a non-exclusive backup was canceled.
      do_pg_abort_backup() assumes that there is at least one non-exclusive
      backup running when it's called. But pg_stop_backup() can be canceled
      even after it marks the end of non-exclusive backup (e.g.,
      during waiting for WAL archiving). This broke the assumption that
      do_pg_abort_backup() relies on, and which caused an assertion failure.
      
      This commit changes do_pg_abort_backup() so that it does nothing
      when non-exclusive backup has been already marked as completed.
      That is, the asssumption is also changed, and do_pg_abort_backup()
      now can handle even the case where it's called when there is
      no running backup.
      
      Backpatch to 9.6 where SQL-callable non-exclusive backup was added.
      
      Author: Masahiko Sawada and Michael Paquier
      Reviewed-By: Robert Haas and Fujii Masao
      Discussion: https://www.postgresql.org/message-id/CAD21AoD2L1Fu2c==gnVASMyFAAaq3y-AQ2uEVj-zTCGFFjvmDg@mail.gmail.com
      56a95ee5
    • Robert Haas's avatar
      Fix crashes on plans with multiple Gather (Merge) nodes. · fd7c0fa7
      Robert Haas authored
      es_query_dsa turns out to be broken by design, because it supposes
      that there is only one DSA for the whole query, whereas there is
      actually one per Gather (Merge) node.  For now, work around that
      problem by setting and clearing the pointer around the sections of
      code that might need it.  It's probably a better idea to get rid of
      es_query_dsa altogether in favor of having each node keep track
      individually of which DSA is relevant, but that seems like more than
      we would want to back-patch.
      
      Thomas Munro, reviewed and tested by Andreas Seltenreich, Amit
      Kapila, and by me.
      
      Discussion: http://postgr.es/m/CAEepm=1U6as=brnVvMNixEV2tpi8NuyQoTmO8Qef0-VV+=7MDA@mail.gmail.com
      fd7c0fa7
    • Magnus Hagander's avatar
      Fix typo on comment · 7731c320
      Magnus Hagander authored
      Author: David Rowley
      7731c320
  4. 17 Dec, 2017 2 commits
  5. 16 Dec, 2017 3 commits
  6. 15 Dec, 2017 2 commits
    • Andres Freund's avatar
      Perform a lot more sanity checks when freezing tuples. · 699bf7d0
      Andres Freund authored
      The previous commit has shown that the sanity checks around freezing
      aren't strong enough. Strengthening them seems especially important
      because the existance of the bug has caused corruption that we don't
      want to make even worse during future vacuum cycles.
      
      The errors are emitted with ereport rather than elog, despite being
      "should never happen" messages, so a proper error code is emitted. To
      avoid superflous translations, mark messages as internal.
      
      Author: Andres Freund and Alvaro Herrera
      Reviewed-By: Alvaro Herrera, Michael Paquier
      Discussion: https://postgr.es/m/20171102112019.33wb7g5wp4zpjelu@alap3.anarazel.de
      Backpatch: 9.3-
      699bf7d0
    • Andres Freund's avatar
      Fix pruning of locked and updated tuples. · 9c2f0a6c
      Andres Freund authored
      Previously it was possible that a tuple was not pruned during vacuum,
      even though its update xmax (i.e. the updating xid in a multixact with
      both key share lockers and an updater) was below the cutoff horizon.
      
      As the freezing code assumed, rightly so, that that's not supposed to
      happen, xmax would be preserved (as a member of a new multixact or
      xmax directly). That causes two problems: For one the tuple is below
      the xmin horizon, which can cause problems if the clog is truncated or
      once there's an xid wraparound. The bigger problem is that that will
      break HOT chains, which in turn can lead two to breakages: First,
      failing index lookups, which in turn can e.g lead to constraints being
      violated. Second, future hot prunes / vacuums can end up making
      invisible tuples visible again. There's other harmful scenarios.
      
      Fix the problem by recognizing that tuples can be DEAD instead of
      RECENTLY_DEAD, even if the multixactid has alive members, if the
      update_xid is below the xmin horizon. That's safe because newer
      versions of the tuple will contain the locking xids.
      
      A followup commit will harden the code somewhat against future similar
      bugs and already corrupted data.
      
      Author: Andres Freund, with changes by Alvaro Herrera
      Reported-By: Daniel Wood
      Analyzed-By: Andres Freund, Alvaro Herrera, Robert Haas, Peter
         Geoghegan, Daniel Wood, Yi Wen Wong, Michael Paquier
      Reviewed-By: Alvaro Herrera, Robert Haas, Michael Paquier
      Discussion:
          https://postgr.es/m/E5711E62-8FDF-4DCA-A888-C200BF6B5742@amazon.com
          https://postgr.es/m/20171102112019.33wb7g5wp4zpjelu@alap3.anarazel.de
      Backpatch: 9.3-
      9c2f0a6c
  7. 14 Dec, 2017 4 commits
  8. 13 Dec, 2017 15 commits
    • Andres Freund's avatar
      Allow executor nodes to change their ExecProcNode function. · 538d114f
      Andres Freund authored
      In order for executor nodes to be able to change their ExecProcNode function
      after ExecInitNode() has finished, provide ExecSetExecProcNode().  This allows
      any wrappers functions that only execProcnode.c knows about to be reinstalled.
      The motivation for wanting to change ExecProcNode after ExecInitNode() has
      finished is that it is not known until later whether parallel query is
      available, so if a parallel variant is to be installed then ExecInitNode()
      is too soon to decide.
      
      Author: Thomas Munro
      Reviewed-By: Andres Freund
      Discussion: https://postgr.es/m/CAEepm=09rr65VN+cAV5FgyM_z=D77Xy8Fuc9CDDDYbq3pQUezg@mail.gmail.com
      538d114f
    • Andres Freund's avatar
      Add pg_attribute_always_inline. · dbb3d6f0
      Andres Freund authored
      Sometimes it is useful to be able to insist that the compiler inline a
      function that its normal cost analysis would not normally choose to inline.
      This can be useful for instantiating different variants of a function that
      remove branches of code by constant folding.
      
      Author: Thomas Munro
      Reviewed-By: Andres Freund
      Discussion: https://postgr.es/m/CAEepm=09rr65VN+cAV5FgyM_z=D77Xy8Fuc9CDDDYbq3pQUezg@mail.gmail.com
      dbb3d6f0
    • Andres Freund's avatar
      Add defenses against pre-crash files to BufFileOpenShared(). · 923e8dee
      Andres Freund authored
      Crash restarts currently don't clean up temporary files, as a debugging aid.
      If a left-over file happens to have the same name as a segment file we're
      trying to create, we'll just truncate and reuse it, but there is a problem:
      BufFileOpenShared() determines how many segment files exist by trying to open
      .0, .1, .2, ... until it finds no more files.  It might be confused by a junk
      file that has the next segment number.  To defend against that, make sure we
      always create a gap after the end file by unlinking the following name if it
      exists.  Also make it an error to try to open a BufFile that doesn't exist
      (has no segment 0), so as not to encourage the development of client code
      that depends on an interface that we can't reliably provide.
      
      Author: Thomas Munro
      Reviewed-By: Andres Freund
      Discussion: https://postgr.es/m/CAEepm%3D2jhCbC_GFQJaaDhWxLB4EXtT3vVd5czuRNaqF5CWSTog%40mail.gmail.com
      923e8dee
    • Robert Haas's avatar
      Fix parallel index scan hang with deleted or half-dead pages. · 884a6084
      Robert Haas authored
      The previous coding forgot to release the scan before seizing
      it again, leading to a lockup.
      
      Report by Patrick Hemmer.  Diagnosis by Thomas Munro.  Patch by
      Amit Kapila.
      
      Discussion: http://postgr.es/m/CAEepm=2xZUcOGP9V0O_G0=2P2wwXwPrkF=upWTCJSisUxMnuSg@mail.gmail.com
      884a6084
    • Robert Haas's avatar
      Revert "Fix accumulation of parallel worker instrumentation." · 1d6fb35a
      Robert Haas authored
      This reverts commit 2c09a5c1.  Per
      further discussion, that doesn't seem to be the best possible fix.
      
      Discussion: http://postgr.es/m/CAA4eK1LW2aFKzY3=vwvc=t-juzPPVWP2uT1bpx_MeyEqnM+p8g@mail.gmail.com
      1d6fb35a
    • Tom Lane's avatar
      Rethink MemoryContext creation to improve performance. · 9fa6f00b
      Tom Lane authored
      This patch makes a number of interrelated changes to reduce the overhead
      involved in creating/deleting memory contexts.  The key ideas are:
      
      * Include the AllocSetContext header of an aset.c context in its first
      malloc request, rather than allocating it separately in TopMemoryContext.
      This means that we now always create an initial or "keeper" block in an
      aset, even if it never receives any allocation requests.
      
      * Create freelists in which we can save and recycle recently-destroyed
      asets (this idea is due to Robert Haas).
      
      * In the common case where the name of a context is a constant string,
      just store a pointer to it in the context header, rather than copying
      the string.
      
      The first change eliminates a palloc/pfree cycle per context, and
      also avoids bloat in TopMemoryContext, at the price that creating
      a context now involves a malloc/free cycle even if the context never
      receives any allocations.  That would be a loser for some common
      usage patterns, but recycling short-lived contexts via the freelist
      eliminates that pain.
      
      Avoiding copying constant strings not only saves strlen() and strcpy()
      overhead, but is an essential part of the freelist optimization because
      it makes the context header size constant.  Currently we make no
      attempt to use the freelist for contexts with non-constant names.
      (Perhaps someday we'll need to think harder about that, but in current
      usage, most contexts with custom names are long-lived anyway.)
      
      The freelist management in this initial commit is pretty simplistic,
      and we might want to refine it later --- but in common workloads that
      will never matter because the freelists will never get full anyway.
      
      To create a context with a non-constant name, one is now required to
      call AllocSetContextCreateExtended and specify the MEMCONTEXT_COPY_NAME
      option.  AllocSetContextCreate becomes a wrapper macro, and it includes
      a test that will complain about non-string-literal context name
      parameters on gcc and similar compilers.
      
      An unfortunate side effect of making AllocSetContextCreate a macro is
      that one is now *required* to use the size parameter abstraction macros
      (ALLOCSET_DEFAULT_SIZES and friends) with it; the pre-9.6 habit of
      writing out individual size parameters no longer works unless you
      switch to AllocSetContextCreateExtended.
      
      Internally to the memory-context-related modules, the context creation
      APIs are simplified, removing the rather baroque original design whereby
      a context-type module called mcxt.c which then called back into the
      context-type module.  That saved a bit of code duplication, but not much,
      and it prevented context-type modules from exercising control over the
      allocation of context headers.
      
      In passing, I converted the test-and-elog validation of aset size
      parameters into Asserts to save a few more cycles.  The original thought
      was that callers might compute size parameters on the fly, but in practice
      nobody does that, so it's useless to expend cycles on checking those
      numbers in production builds.
      
      Also, mark the memory context method-pointer structs "const",
      just for cleanliness.
      
      Discussion: https://postgr.es/m/2264.1512870796@sss.pgh.pa.us
      9fa6f00b
    • Peter Eisentraut's avatar
      Start a separate test suite for plpgsql · 632b03da
      Peter Eisentraut authored
      The plpgsql.sql test file in the main regression tests is now by far the
      largest after numeric_big, making editing and managing the test cases
      very cumbersome.  The other PLs have their own test suites split up into
      smaller files by topic.  It would be nice to have that for plpgsql as
      well.  So, to get that started, set up test infrastructure in
      src/pl/plpgsql/src/ and split out the recently added procedure test
      cases into a new file there.  That file now mirrors the test cases added
      to the other PLs, making managing those matching tests a bit easier too.
      
      msvc build system changes with help from Michael Paquier
      632b03da
    • Peter Eisentraut's avatar
      Fix crash when using CALL on an aggregate · 3d887422
      Peter Eisentraut authored
      Author: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
      Reported-by: default avatarRushabh Lathia <rushabh.lathia@gmail.com>
      3d887422
    • Andres Freund's avatar
      Add float.h include to int8.c, for isnan(). · 8e211f53
      Andres Freund authored
      port.h redirects isnan() to _isnan() on windows, which in turn is
      provided by float.h rather than math.h. Therefore include the latter
      as well.
      
      Per buildfarm.
      8e211f53
    • Andres Freund's avatar
      Consistently use PG_INT(16|32|64)_(MIN|MAX). · f512a6e1
      Andres Freund authored
      Per buildfarm animal woodlouse.
      f512a6e1
    • Peter Eisentraut's avatar
      PL/Python: Fix potential NULL pointer dereference · 4c6744ed
      Peter Eisentraut authored
      After d0aa965c, one error path in
      PLy_spi_execute_fetch_result() could result in the variable "result"
      being dereferenced after being set to NULL.  Rearrange the code a bit to
      fix that.
      
      Also add another SPI_freetuptable() call so that that is cleared in all
      error paths.
      
      discovered by John Naylor <jcnaylor@gmail.com> via scan-build
      
      ideas and review by Tom Lane
      4c6744ed
    • Andres Freund's avatar
      Make PGAC_C_BUILTIN_OP_OVERFLOW link instead of just compiling. · 85abb5b2
      Andres Freund authored
      Otherwise the detection can spuriously detect symbol as available,
      because the compiler may just emits reference to non-existant symbol.
      85abb5b2
    • Andres Freund's avatar
      Use new overflow aware integer operations. · 101c7ee3
      Andres Freund authored
      A previous commit added inline functions that provide fast(er) and
      correct overflow checks for signed integer math. Use them in a
      significant portion of backend code.  There's more to touch in both
      backend and frontend code, but these were the easily identifiable
      cases.
      
      The old overflow checks are noticeable in integer heavy workloads.
      
      A secondary benefit is that getting rid of overflow checks that rely
      on signed integer overflow wrapping around, will allow us to get rid
      of -fwrapv in the future. Which in turn slows down other code.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20171024103954.ztmatprlglz3rwke@alap3.anarazel.de
      101c7ee3
    • Andres Freund's avatar
      Provide overflow safe integer math inline functions. · 4d6ad312
      Andres Freund authored
      It's not easy to get signed integer overflow checks correct and
      fast. Therefore abstract the necessary infrastructure into a common
      header providing addition, subtraction and multiplication for 16, 32,
      64 bit signed integers.
      
      The new macros aren't yet used, but a followup commit will convert
      several open coded overflow checks.
      
      Author: Andres Freund, with some code stolen from Greg Stark
      Reviewed-By: Robert Haas
      Discussion: https://postgr.es/m/20171024103954.ztmatprlglz3rwke@alap3.anarazel.de
      4d6ad312
    • Robert Haas's avatar
      Remove obsolete comment. · 95b52351
      Robert Haas authored
      Commit 8b304b8b removed replacement
      selection, but left behind this comment text.  The optimization to
      which the comment refers is not relevant without replacement
      selection, because if we had so few tuples as to require only one
      tape, we would have just completed the sort in memory.
      
      Peter Geoghegan
      
      Discussion: http://postgr.es/m/CAH2-WznqupLA8CMjp+vqzoe0yXu0DYYbQSNZxmgN76tLnAOZ_w@mail.gmail.com
      95b52351
  9. 12 Dec, 2017 2 commits