1. 19 Nov, 2018 6 commits
    • Alvaro Herrera's avatar
      Disallow COPY FREEZE on partitioned tables · 5c9a5513
      Alvaro Herrera authored
      This didn't actually work: COPY would fail to flush the right files, and
      instead would try to flush a non-existing file, causing the whole
      transaction to fail.
      
      Cope by raising an error as soon as the command is sent instead, to
      avoid a nasty later surprise.  Of course, it would be much better to
      make it work, but we don't have a patch for that yet, and we don't know
      if we'll want to backpatch one when we do.
      
      Reported-by: Tomas Vondra
      Author: David Rowley
      Reviewed-by: Amit Langote, Steve Singer, Tomas Vondra
      5c9a5513
    • Peter Eisentraut's avatar
      fc47e99a
    • Thomas Munro's avatar
      PANIC on fsync() failure. · 9ccdd7f6
      Thomas Munro authored
      On some operating systems, it doesn't make sense to retry fsync(),
      because dirty data cached by the kernel may have been dropped on
      write-back failure.  In that case the only remaining copy of the
      data is in the WAL.  A subsequent fsync() could appear to succeed,
      but not have flushed the data.  That means that a future checkpoint
      could apparently complete successfully but have lost data.
      
      Therefore, violently prevent any future checkpoint attempts by
      panicking on the first fsync() failure.  Note that we already
      did the same for WAL data; this change extends that behavior to
      non-temporary data files.
      
      Provide a GUC data_sync_retry to control this new behavior, for
      users of operating systems that don't eject dirty data, and possibly
      forensic/testing uses.  If it is set to on and the write-back error
      was transient, a later checkpoint might genuinely succeed (on a
      system that does not throw away buffers on failure); if the error is
      permanent, later checkpoints will continue to fail.  The GUC defaults
      to off, meaning that we panic.
      
      Back-patch to all supported releases.
      
      There is still a narrow window for error-loss on some operating
      systems: if the file is closed and later reopened and a write-back
      error occurs in the intervening time, but the inode has the bad
      luck to be evicted due to memory pressure before we reopen, we could
      miss the error.  A later patch will address that with a scheme
      for keeping files with dirty data open at all times, but we judge
      that to be too complicated to back-patch.
      
      Author: Craig Ringer, with some adjustments by Thomas Munro
      Reported-by: Craig Ringer
      Reviewed-by: Robert Haas, Thomas Munro, Andres Freund
      Discussion: https://postgr.es/m/20180427222842.in2e4mibx45zdth5%40alap3.anarazel.de
      9ccdd7f6
    • Thomas Munro's avatar
      Don't forget about failed fsync() requests. · 1556cb2f
      Thomas Munro authored
      If fsync() fails, md.c must keep the request in its bitmap, so that
      future attempts will try again.
      
      Back-patch to all supported releases.
      
      Author: Thomas Munro
      Reviewed-by: Amit Kapila
      Reported-by: Andrew Gierth
      Discussion: https://postgr.es/m/87y3i1ia4w.fsf%40news-spur.riddles.org.uk
      1556cb2f
    • Michael Paquier's avatar
      Rework documentation of pg_promote · 74171f8c
      Michael Paquier authored
      This clarifies the behavior of how the "wait" flag works, which is
      something that the previous version of the documentation failed to do.
      
      Author: Ian Barwick
      Discussion: https://postgr.es/m/cbd38450-2295-10a1-1f73-591a692ae0b0@2ndquadrant.com
      74171f8c
    • Michael Paquier's avatar
      Remove unnecessary memcpy when reading WAL record fitting on page · 285bd0ac
      Michael Paquier authored
      When reading a WAL record, its contents are copied into an intermediate
      buffer.  However, doing so is not necessary if the record fits fully
      into the current page, saving one memcpy for each such record.  The
      allocation handling of the intermediate buffer is also now done only
      when a record crosses a page boundary, shaving some extra cycles when
      reading a WAL record.
      
      Author: Andrey Lepikhov
      Reviewed-by: Kyotaro Horiguchi, Heikki Linnakangas
      Discussion: https://postgr.es/m/c2ea54dd-a1d3-80eb-ddbf-7e6f258e615e@postgrespro.ru
      285bd0ac
  2. 18 Nov, 2018 3 commits
  3. 17 Nov, 2018 5 commits
    • Tomas Vondra's avatar
      Add valgrind suppressions for wcsrtombs optimizations · d3bbc4b9
      Tomas Vondra authored
      wcsrtombs (called through wchar2char from common functions like lower,
      upper, etc.) uses various optimizations that may look like access to
      uninitialized data, triggering valgrind reports.
      
      For example AVX2 instructions load data in 256-bit chunks, and  gconv
      does something similar with 32-bit chunks.  This is faster than accessing
      the bytes one by one, and the uninitialized part of the buffer is not
      actually used. So suppress the bogus reports.
      
      The exact stack depends on possible optimizations - it might be AVX, SSE
      (as in the report by Aleksander Alekseev) or something else. Hence the
      last frame is wildcarded, to deal with this.
      
      Backpatch all the way back to 9.4.
      
      Author: Tomas Vondra
      Discussion: https://www.postgresql.org/message-id/flat/90ac0452-e907-e7a4-b3c8-15bd33780e62%402ndquadrant.com
      Discussion: https://www.postgresql.org/message-id/20180220150838.GD18315@e733.localdomain
      d3bbc4b9
    • Tom Lane's avatar
      Avoid defining SIGTTIN/SIGTTOU on Windows. · 37afc079
      Tom Lane authored
      Setting them to SIG_IGN seems unlikely to have any beneficial effect
      on that platform, and given the signal numbering collision with SIGABRT,
      it could easily have bad effects.
      
      Given the lack of field complaints that can be traced to this, I don't
      presently feel a need to back-patch.
      
      Discussion: https://postgr.es/m/5627.1542477392@sss.pgh.pa.us
      37afc079
    • Tom Lane's avatar
      Leave SIGTTIN/SIGTTOU signal handling alone in postmaster child processes. · 125f551c
      Tom Lane authored
      For reasons lost in the mists of time, most postmaster child processes
      reset SIGTTIN/SIGTTOU signal handling to SIG_DFL, with the major exception
      that backend sessions do not.  It seems like a pretty bad idea for any
      postmaster children to do that: if stderr is connected to the terminal,
      and the user has put the postmaster in background, any log output would
      result in the child process freezing up.  Hence, switch them all to
      doing what backends do, ie, nothing.  This allows them to inherit the
      postmaster's SIG_IGN setting.  On the other hand, manually-launched
      processes such as standalone backends will have default processing,
      which seems fine.
      
      In passing, also remove useless resets of SIGCONT and SIGWINCH signal
      processing.  Perhaps the postmaster once changed those to something
      besides SIG_DFL, but it doesn't now, so these are just wasted (and
      confusing) syscalls.
      
      Basically, this propagates the changes made in commit 8e2998d8 from
      backends to other postmaster children.  Probably the only reason these
      calls now exist elsewhere is that I missed changing pgstat.c along with
      postgres.c at the time.
      
      Given the lack of field complaints that can be traced to this, I don't
      presently feel a need to back-patch.
      
      Discussion: https://postgr.es/m/5627.1542477392@sss.pgh.pa.us
      125f551c
    • Andres Freund's avatar
    • Andres Freund's avatar
      Make TupleTableSlots extensible, finish split of existing slot type. · 4da597ed
      Andres Freund authored
      This commit completes the work prepared in 1a0586de, splitting the
      old TupleTableSlot implementation (which could store buffer, heap,
      minimal and virtual slots) into four different slot types.  As
      described in the aforementioned commit, this is done with the goal of
      making tuple table slots extensible, to allow for pluggable table
      access methods.
      
      To achieve runtime extensibility for TupleTableSlots, operations on
      slots that can differ between types of slots are performed using the
      TupleTableSlotOps struct provided at slot creation time.  That
      includes information from the size of TupleTableSlot struct to be
      allocated, initialization, deforming etc.  See the struct's definition
      for more detailed information about callbacks TupleTableSlotOps.
      
      I decided to rename TTSOpsBufferTuple to TTSOpsBufferHeapTuple and
      ExecCopySlotTuple to ExecCopySlotHeapTuple, as that seems more
      consistent with other naming introduced in recent patches.
      
      There's plenty optimization potential in the slot implementation, but
      according to benchmarking the state after this commit has similar
      performance characteristics to before this set of changes, which seems
      sufficient.
      
      There's a few changes in execReplication.c that currently need to poke
      through the slot abstraction, that'll be repaired once the pluggable
      storage patchset provides the necessary infrastructure.
      
      Author: Andres Freund and  Ashutosh Bapat, with changes by Amit Khandekar
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      4da597ed
  4. 16 Nov, 2018 10 commits
    • Alvaro Herrera's avatar
      Avoid re-typedef'ing PartitionTupleRouting · 0201d79a
      Alvaro Herrera authored
      Apparently, gcc on macOS (?) doesn't like it.
      
      Per buildfarm.
      0201d79a
    • Alvaro Herrera's avatar
      pgbench: introduce a RandomState struct · 40923191
      Alvaro Herrera authored
      This becomes useful when used to retry a transaction after a
      serialization error or deadlock abort.  (We don't yet have that feature,
      but this is preparation for it.)
      
      While at it, use separate random state for thread administratrivia such
      as deciding which script to run, how long to delay for throttling, or
      whether to log a message when sampling; this not only makes these tasks
      independent of each other, but makes the actual thread run
      deterministic.
      
      Author: Marina Polyakova
      Reviewed-by: Fabien Coelho
      Discussion: https://postgr.es/m/72a0d590d6ba06f242d75c2e641820ec@postgrespro.ru
      40923191
    • Andres Freund's avatar
      Inline hot path of slot_getsomeattrs(). · a7aa608e
      Andres Freund authored
      This yields a minor speedup, which roughly balances the loss from the
      upcoming introduction of callbacks to do some operations on slots.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      a7aa608e
    • Alvaro Herrera's avatar
      Redesign initialization of partition routing structures · 3f2393ed
      Alvaro Herrera authored
      This speeds up write operations (INSERT, UPDATE, DELETE, COPY, as well
      as the future MERGE) on partitioned tables.
      
      This changes the setup for tuple routing so that it does far less work
      during the initial setup and pushes more work out to when partitions
      receive tuples.  PartitionDispatchData structs for sub-partitioned
      tables are only created when a tuple gets routed through it.  The
      possibly large arrays in the PartitionTupleRouting struct have largely
      been removed.  The partitions[] array remains but now never contains any
      NULL gaps.  Previously the NULLs had to be skipped during
      ExecCleanupTupleRouting(), which could add a large overhead to the
      cleanup when the number of partitions was large.  The partitions[] array
      is allocated small to start with and only enlarged when we route tuples
      to enough partitions that it runs out of space. This allows us to keep
      simple single-row partition INSERTs running quickly.  Redesign
      
      The arrays in PartitionTupleRouting which stored the tuple translation maps
      have now been removed.  These have been moved out into a
      PartitionRoutingInfo struct which is an additional field in ResultRelInfo.
      
      The find_all_inheritors() call still remains by far the slowest part of
      ExecSetupPartitionTupleRouting(). This commit just removes the other slow
      parts.
      
      In passing also rename the tuple translation maps from being ParentToChild
      and ChildToParent to being RootToPartition and PartitionToRoot. The old
      names mislead you into thinking that a partition of some sub-partitioned
      table would translate to the rowtype of the sub-partitioned table rather
      than the root partitioned table.
      
      Authors: David Rowley and Amit Langote, heavily revised by Álvaro Herrera
      Testing help from Jesper Pedersen and Kato Sho.
      Discussion: https://postgr.es/m/CAKJS1f_1RJyFquuCKRFHTdcXqoPX-PYqAd7nz=GVBwvGh4a6xA@mail.gmail.com
      3f2393ed
    • Andres Freund's avatar
      Fix slot type assumptions for nodeGather[Merge]. · a387a3df
      Andres Freund authored
      The assumption made in 1a0586de was wrong, as evidenced by
      buildfarm failure on locust, which runs with
      force_parallel_mode=regress.  The tuples accessed in either nodes are
      in the outer slot, and we can't trivially rely on the slot type being
      known because the leader might execute the subsidiary node directly,
      or via the tuple queue on a worker. In the latter case the tuple will
      always be a heaptuple slot, but in the former, it'll be whatever the
      subsidiary node returns.
      a387a3df
    • Andres Freund's avatar
      Add dummy field to currently empty struct TupleTableSlotOps. · f92cd739
      Andres Freund authored
      Per MSVC complaint on buildfarm member dory.
      f92cd739
    • Andres Freund's avatar
      Don't generate tuple deforming functions for virtual slots. · 7ef04e4d
      Andres Freund authored
      Virtual tuple table slots never need tuple deforming. Therefore, if we
      know at expression compilation time, that a certain slot will always
      be virtual, there's no need to create a tuple deforming routine for
      it.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      7ef04e4d
    • Andres Freund's avatar
      Verify that expected slot types match returned slot types. · 15d8f831
      Andres Freund authored
      This is important so JIT compilation knows what kind of tuple slot the
      deforming routine can expect. There's also optimization potential for
      expression initialization without JIT compilation. It e.g. seems
      plausible to elide EEOP_*_FETCHSOME ops entirely when dealing with
      virtual slots.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      15d8f831
    • Andres Freund's avatar
      Compute information about EEOP_*_FETCHSOME at expression init time. · 675af5c0
      Andres Freund authored
      Previously this information was computed when JIT compiling an
      expression.  But the information is useful for assertions in the
      non-JIT case too (for assertions), therefore it makes sense to move
      it.
      
      This will, in a followup commit, allow to treat different slot types
      differently. E.g. for virtual slots there's no need to generate a JIT
      function to deform the slot.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      675af5c0
    • Andres Freund's avatar
      Introduce notion of different types of slots (without implementing them). · 1a0586de
      Andres Freund authored
      Upcoming work intends to allow pluggable ways to introduce new ways of
      storing table data. Accessing those table access methods from the
      executor requires TupleTableSlots to be carry tuples in the native
      format of such storage methods; otherwise there'll be a significant
      conversion overhead.
      
      Different access methods will require different data to store tuples
      efficiently (just like virtual, minimal, heap already require fields
      in TupleTableSlot). To allow that without requiring additional pointer
      indirections, we want to have different structs (embedding
      TupleTableSlot) for different types of slots.  Thus different types of
      slots are needed, which requires adapting creators of slots.
      
      The slot that most efficiently can represent a type of tuple in an
      executor node will often depend on the type of slot a child node
      uses. Therefore we need to track the type of slot is returned by
      nodes, so parent slots can create slots based on that.
      
      Relatedly, JIT compilation of tuple deforming needs to know which type
      of slot a certain expression refers to, so it can create an
      appropriate deforming function for the type of tuple in the slot.
      
      But not all nodes will only return one type of slot, e.g. an append
      node will potentially return different types of slots for each of its
      subplans.
      
      Therefore add function that allows to query the type of a node's
      result slot, and whether it'll always be the same type (whether it's
      fixed). This can be queried using ExecGetResultSlotOps().
      
      The scan, result, inner, outer type of slots are automatically
      inferred from ExecInitScanTupleSlot(), ExecInitResultSlot(),
      left/right subtrees respectively. If that's not correct for a node,
      that can be overwritten using new fields in PlanState.
      
      This commit does not introduce the actually abstracted implementation
      of different kind of TupleTableSlots, that will be left for a followup
      commit.  The different types of slots introduced will, for now, still
      use the same backing implementation.
      
      While this already partially invalidates the big comment in
      tuptable.h, it seems to make more sense to update it later, when the
      different TupleTableSlot implementations actually exist.
      
      Author: Ashutosh Bapat and Andres Freund, with changes by Amit Khandekar
      Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
      1a0586de
  5. 15 Nov, 2018 12 commits
  6. 14 Nov, 2018 4 commits