1. 01 Aug, 2018 1 commit
    • Peter Eisentraut's avatar
      Allow multi-inserts during COPY into a partitioned table · 0d5f05cd
      Peter Eisentraut authored
      CopyFrom allows multi-inserts to be used for non-partitioned tables, but
      this was disabled for partitioned tables.  The reason for this appeared
      to be that the tuple may not belong to the same partition as the
      previous tuple did.  Not allowing multi-inserts here greatly slowed down
      imports into partitioned tables.  These could take twice as long as a
      copy to an equivalent non-partitioned table.  It seems wise to do
      something about this, so this change allows the multi-inserts by
      flushing the so-far inserted tuples to the partition when the next tuple
      does not belong to the same partition, or when the buffer fills.  This
      improves performance when the next tuple in the stream commonly belongs
      to the same partition as the previous tuple.
      
      In cases where the target partition changes on every tuple, using
      multi-inserts slightly slows the performance.  To get around this we
      track the average size of the batches that have been inserted and
      adaptively enable or disable multi-inserts based on the size of the
      batch.  Some testing was done and the regression only seems to exist
      when the average size of the insert batch is close to 1, so let's just
      enable multi-inserts when the average size is at least 1.3.  More
      performance testing might reveal a better number for, this, but since
      the slowdown was only 1-2% it does not seem critical enough to spend too
      much time calculating it.  In any case it may depend on other factors
      rather than just the size of the batch.
      
      Allowing multi-inserts for partitions required a bit of work around the
      per-tuple memory contexts as we must flush the tuples when the next
      tuple does not belong the same partition.  In which case there is no
      good time to reset the per-tuple context, as we've already built the new
      tuple by this time.  In order to work around this we maintain two
      per-tuple contexts and just switch between them every time the partition
      changes and reset the old one.  This does mean that the first of each
      batch of tuples is not allocated in the same memory context as the
      others, but that does not matter since we only reset the context once
      the previous batch has been inserted.
      
      Author: David Rowley <david.rowley@2ndquadrant.com>
      Reviewed-by: default avatarMelanie Plageman <melanieplageman@gmail.com>
      0d5f05cd
  2. 31 Jul, 2018 6 commits
  3. 30 Jul, 2018 9 commits
  4. 29 Jul, 2018 8 commits
  5. 28 Jul, 2018 5 commits
  6. 27 Jul, 2018 5 commits
  7. 26 Jul, 2018 2 commits
    • Tom Lane's avatar
      Provide plpgsql tests for cases involving record field changes. · 9f77ad26
      Tom Lane authored
      We suppressed one of these test cases in commit feb1cc55 because
      it was failing to produce the expected results on CLOBBER_CACHE_ALWAYS
      buildfarm members.  But now we need another test with similar behavior,
      so let's set up a test file that is expected to vary between regular and
      CLOBBER_CACHE_ALWAYS cases, and provide variant expected files.
      
      Someday we should fix plpgsql's failure for change-of-field-type, and
      then the discrepancy will go away and we can fold these tests back
      into plpgsql_record.sql.  But today is not that day.
      
      Discussion: https://postgr.es/m/87wotkfju1.fsf@news-spur.riddles.org.uk
      9f77ad26
    • Tom Lane's avatar
      Avoid crash in eval_const_expressions if a Param's type changes. · 662d12ae
      Tom Lane authored
      Since commit 6719b238 it's been possible for the values of plpgsql
      record field variables to be exposed to the planner as Params.
      (Before that, plpgsql never supplied values for such variables during
      planning, so that the problematic code wasn't reached.)  Other places
      that touch potentially-type-mutable Params either cope gracefully or
      do runtime-test-and-ereport checks that the type is what they expect.
      But eval_const_expressions() just had an Assert, meaning that it either
      failed the assertion or risked crashes due to using an incompatible
      value.
      
      In this case, rather than throwing an ereport immediately, we can just
      not perform a const-substitution in case of a mismatch.  This seems
      important for the same reason that the Param fetch was speculative:
      we might not actually reach this part of the expression at runtime.
      
      Test case will follow in a separate commit.
      
      Patch by me, pursuant to bug report from Andrew Gierth.
      Back-patch to v11 where the previous commit appeared.
      
      Discussion: https://postgr.es/m/87wotkfju1.fsf@news-spur.riddles.org.uk
      662d12ae
  8. 25 Jul, 2018 2 commits
  9. 24 Jul, 2018 2 commits
    • Tomas Vondra's avatar
      Add strict_multi_assignment and too_many_rows plpgsql checks · 167075be
      Tomas Vondra authored
      Until now shadowed_variables was the only plpgsql check supported by
      plpgsql.extra_warnings and plpgsql.extra_errors.  This patch introduces
      two new checks - strict_multi_assignment and too_many_rows.  Unlike
      shadowed_variables, these new checks are enforced at run-time.
      
      strict_multi_assignment checks that commands allowing multi-assignment
      (for example SELECT INTO) have the same number of sources and targets.
      too_many_rows checks that queries with an INTO clause return one row
      exactly.
      
      These checks are aimed at cases that are technically valid and allowed,
      but are often a sign of a bug.  Therefore those checks are expected to
      be enabled primarily in development and testing environments.
      
      Author: Pavel Stehule
      Reviewed-by: Stephen Frost, Tomas Vondra
      Discussion: https://www.postgresql.org/message-id/flat/CAFj8pRA2kKRDKpUNwLY0GeG1OqOp+tLS2yQA1V41gzuSz-hCng@mail.gmail.com
      167075be
    • Thomas Munro's avatar
      Pad semaphores to avoid false sharing. · 2d306759
      Thomas Munro authored
      In a USE_UNNAMED_SEMAPHORES build, the default on Linux and FreeBSD
      since commit ecb0d20a, we have an array of sem_t objects.  This
      turned out to reduce performance compared to the previous default
      USE_SYSV_SEMAPHORES on an 8 socket system.  Testing showed that the
      lost performance could be regained by padding the array elements so
      that they have their own cache lines.  This matches what we do for
      similar hot arrays (see LWLockPadded, WALInsertLockPadded).
      
      Back-patch to 10, where unnamed semaphores were adopted as the default
      semaphore interface on those operating systems.
      
      Author: Thomas Munro
      Reviewed-by: Andres Freund
      Reported-by: Mithun Cy
      Tested-by: Mithun Cy, Tom Lane, Thomas Munro
      Discussion: https://postgr.es/m/CAD__OugYDM3O%2BdyZnnZSbJprSfsGFJcQ1R%3De59T3hcLmDug4_w%40mail.gmail.com
      2d306759