1. 16 Jul, 2019 3 commits
  2. 15 Jul, 2019 6 commits
    • Thomas Munro's avatar
      Provide pgbench --show-script to dump built-in scripts. · 5823677a
      Thomas Munro authored
      Author: Fabien Coelho
      Reviewed-by: Ibrar Ahmed
      Discussion: https://postgr.es/m/alpine.DEB.2.21.1904081737390.5867%40lancre
      5823677a
    • Thomas Munro's avatar
      Report the time taken by pgbench initialization steps. · ce8f9467
      Thomas Munro authored
      Author: Fabien Coelho
      Reviewed-by: Ibrar Ahmed
      Discussion: https://postgr.es/m/alpine.DEB.2.21.1904061810510.3678%40lancre
      ce8f9467
    • Peter Geoghegan's avatar
      Correct nbtsplitloc.c comment. · bfdbac2a
      Peter Geoghegan authored
      The logic just added by commit e3899ffd falls back on a 50:50 page split
      in the event of a new item that's just to the right of our provisional
      "many duplicates" split point.  Fix a comment that incorrectly claimed
      that the new item had to be just to the left of our provisional split
      point.
      
      Backpatch: 12-, just like commit e3899ffd.
      bfdbac2a
    • Peter Geoghegan's avatar
      Fix pathological nbtree split point choice issue. · e3899ffd
      Peter Geoghegan authored
      Specific ever-decreasing insertion patterns could cause successive
      unbalanced nbtree page splits.  Problem cases involve a large group of
      duplicates to the left, and ever-decreasing insertions to the right.
      
      To fix, detect the situation by considering the newitem offset before
      performing a split using nbtsplitloc.c's "many duplicates" strategy.  If
      the new item was inserted just to the right of our provisional "many
      duplicates" split point, infer ever-decreasing insertions and fall back
      on a 50:50 (space delta optimal) split.  This seems to barely affect
      cases that already had acceptable space utilization.
      
      An alternative fix also seems possible.  Instead of changing
      nbtsplitloc.c split choice logic, we could instead teach _bt_truncate()
      to generate a new value for new high keys by interpolating from the
      lastleft and firstright key values.  That would certainly be a more
      elegant fix, but it isn't suitable for backpatching.
      
      Discussion: https://postgr.es/m/CAH2-WznCNvhZpxa__GqAa1fgQ9uYdVc=_apArkW2nc-K3O7_NA@mail.gmail.com
      Backpatch: 12-, where the nbtree page split enhancements were introduced.
      e3899ffd
    • Tom Lane's avatar
      Represent Lists as expansible arrays, not chains of cons-cells. · 1cff1b95
      Tom Lane authored
      Originally, Postgres Lists were a more or less exact reimplementation of
      Lisp lists, which consist of chains of separately-allocated cons cells,
      each having a value and a next-cell link.  We'd hacked that once before
      (commit d0b4399d) to add a separate List header, but the data was still
      in cons cells.  That makes some operations -- notably list_nth() -- O(N),
      and it's bulky because of the next-cell pointers and per-cell palloc
      overhead, and it's very cache-unfriendly if the cons cells end up
      scattered around rather than being adjacent.
      
      In this rewrite, we still have List headers, but the data is in a
      resizable array of values, with no next-cell links.  Now we need at
      most two palloc's per List, and often only one, since we can allocate
      some values in the same palloc call as the List header.  (Of course,
      extending an existing List may require repalloc's to enlarge the array.
      But this involves just O(log N) allocations not O(N).)
      
      Of course this is not without downsides.  The key difficulty is that
      addition or deletion of a list entry may now cause other entries to
      move, which it did not before.
      
      For example, that breaks foreach() and sister macros, which historically
      used a pointer to the current cons-cell as loop state.  We can repair
      those macros transparently by making their actual loop state be an
      integer list index; the exposed "ListCell *" pointer is no longer state
      carried across loop iterations, but is just a derived value.  (In
      practice, modern compilers can optimize things back to having just one
      loop state value, at least for simple cases with inline loop bodies.)
      In principle, this is a semantics change for cases where the loop body
      inserts or deletes list entries ahead of the current loop index; but
      I found no such cases in the Postgres code.
      
      The change is not at all transparent for code that doesn't use foreach()
      but chases lists "by hand" using lnext().  The largest share of such
      code in the backend is in loops that were maintaining "prev" and "next"
      variables in addition to the current-cell pointer, in order to delete
      list cells efficiently using list_delete_cell().  However, we no longer
      need a previous-cell pointer to delete a list cell efficiently.  Keeping
      a next-cell pointer doesn't work, as explained above, but we can improve
      matters by changing such code to use a regular foreach() loop and then
      using the new macro foreach_delete_current() to delete the current cell.
      (This macro knows how to update the associated foreach loop's state so
      that no cells will be missed in the traversal.)
      
      There remains a nontrivial risk of code assuming that a ListCell *
      pointer will remain good over an operation that could now move the list
      contents.  To help catch such errors, list.c can be compiled with a new
      define symbol DEBUG_LIST_MEMORY_USAGE that forcibly moves list contents
      whenever that could possibly happen.  This makes list operations
      significantly more expensive so it's not normally turned on (though it
      is on by default if USE_VALGRIND is on).
      
      There are two notable API differences from the previous code:
      
      * lnext() now requires the List's header pointer in addition to the
      current cell's address.
      
      * list_delete_cell() no longer requires a previous-cell argument.
      
      These changes are somewhat unfortunate, but on the other hand code using
      either function needs inspection to see if it is assuming anything
      it shouldn't, so it's not all bad.
      
      Programmers should be aware of these significant performance changes:
      
      * list_nth() and related functions are now O(1); so there's no
      major access-speed difference between a list and an array.
      
      * Inserting or deleting a list element now takes time proportional to
      the distance to the end of the list, due to moving the array elements.
      (However, it typically *doesn't* require palloc or pfree, so except in
      long lists it's probably still faster than before.)  Notably, lcons()
      used to be about the same cost as lappend(), but that's no longer true
      if the list is long.  Code that uses lcons() and list_delete_first()
      to maintain a stack might usefully be rewritten to push and pop at the
      end of the list rather than the beginning.
      
      * There are now list_insert_nth...() and list_delete_nth...() functions
      that add or remove a list cell identified by index.  These have the
      data-movement penalty explained above, but there's no search penalty.
      
      * list_concat() and variants now copy the second list's data into
      storage belonging to the first list, so there is no longer any
      sharing of cells between the input lists.  The second argument is
      now declared "const List *" to reflect that it isn't changed.
      
      This patch just does the minimum needed to get the new implementation
      in place and fix bugs exposed by the regression tests.  As suggested
      by the foregoing, there's a fair amount of followup work remaining to
      do.
      
      Also, the ENABLE_LIST_COMPAT macros are finally removed in this
      commit.  Code using those should have been gone a dozen years ago.
      
      Patch by me; thanks to David Rowley, Jesper Pedersen, and others
      for review.
      
      Discussion: https://postgr.es/m/11587.1550975080@sss.pgh.pa.us
      1cff1b95
    • Thomas Munro's avatar
      Provide XLogRecGetFullXid(). · 67b9b3ca
      Thomas Munro authored
      In order to be able to work with FullTransactionId values during replay
      without increasing the size of the WAL, infer the epoch.  In general we
      can't do that safely, but during replay we can because we know that
      nextFullXid can't advance concurrently.
      
      Prevent frontend code from seeing this new function, due to the above
      restriction.  Perhaps in future it will be possible to extract the value
      entirely from independent WAL records, and then this restriction can be
      lifted.
      
      Author: Thomas Munro, based on earlier code from Andres Freund
      Discussion: https://postgr.es/m/CA%2BhUKG%2BmLmuDjMi6o1dxkKvGRL56Y2Rz%2BiXAcrZV03G9ZuFQ8Q%40mail.gmail.com
      67b9b3ca
  3. 14 Jul, 2019 7 commits
  4. 13 Jul, 2019 7 commits
  5. 12 Jul, 2019 3 commits
    • Thomas Munro's avatar
      Warn if wal_level is too low when creating a publication. · b31fbe85
      Thomas Munro authored
      Provide a hint to users that they need to increase wal_level before
      subscriptions can work.
      
      Author: Lucas Viecelli, with some adjustments by Thomas Munro
      Reviewed-by: Tom Lane
      Discussion: https://postgr.es/m/CAPjy-57rn5Y9g4e5u--eSOP-7P4QrE9uOZmT2ZcUebF8qxsYhg%40mail.gmail.com
      b31fbe85
    • Tom Lane's avatar
      Fix get_actual_variable_range() to cope with broken HOT chains. · d3751adc
      Tom Lane authored
      Commit 3ca930fc modified get_actual_variable_range() to use a new
      "SnapshotNonVacuumable" snapshot type for selecting tuples that it
      would consider valid.  However, because that snapshot type can accept
      recently-dead tuples, this caused a bug when using a recently-created
      index: we might accept a recently-dead tuple that is an early member
      of a broken HOT chain and does not actually match the index entry.
      Then, the data extracted from the heap tuple would not necessarily be
      an endpoint value of the column; it could even be NULL, leading to
      get_actual_variable_range() itself reporting "found unexpected null
      value in index".  Even without an error, this could lead to poor
      plan choices due to an erroneous notion of the endpoint value.
      
      We can improve matters by changing the code to use the index-only
      scan technique (which didn't exist when get_actual_variable_range was
      originally written).  If any of the tuples in a HOT chain are live
      enough to satisfy SnapshotNonVacuumable, we take the data from the
      index entry, ignoring what is in the heap.  This fixes the problem
      without changing the live-vs-dead-tuple behavior from what was
      intended by commit 3ca930fc.
      
      A side benefit is that for static tables we might not have to touch
      the heap at all (when the extremal value is in an all-visible page).
      In addition, we can save some overhead by not having to create a
      complete ExecutorState, and we don't need to run FormIndexDatum,
      avoiding more cycles as well as the possibility of failure for
      indexes on expressions.  (I'm not sure that this code would ever
      be used to determine the extreme value of an expression, in the
      current state of the planner; but it's definitely possible that
      lower-order columns of the selected index could be expressions.
      So one could construct perhaps-artificial examples in which the
      old code unexpectedly failed due to trying to compute an
      expression's value for a now-dead row.)
      
      Per report from Manuel Rigger.  Back-patch to v11 where commit
      3ca930fc came in.
      
      Discussion: https://postgr.es/m/CA+u7OA7W4NWEhCvftdV6_8bbm2vgypi5nuxfnSEJQqVKFSUoMg@mail.gmail.com
      d3751adc
    • David Rowley's avatar
      Fix RANGE partition pruning with multiple boolean partition keys · cfde2349
      David Rowley authored
      match_clause_to_partition_key incorrectly would return
      PARTCLAUSE_UNSUPPORTED if a bool qual could not be matched to the current
      partition key.  This was a problem, as it causes the calling function to
      discard the qual and not try to match it to any other partition key.  If
      there was another partition key which did match this qual, then the qual
      would not be checked again and we could fail to prune some partitions.
      
      The worst this could do was to cause partitions not to be pruned when they
      could have been, so there was no danger of incorrect query results here.
      
      Fix this by changing match_boolean_partition_clause to have it return a
      PartClauseMatchStatus rather than a boolean value.  This allows it to
      communicate if the qual is unsupported or if it just does not match this
      particular partition key, previously these two cases were treated the
      same.  Now, if match_clause_to_partition_key is unable to match the qual
      to any other qual type then we can simply return the value from the
      match_boolean_partition_clause call so that the calling function properly
      treats the qual as either unmatched or unsupported.
      
      Reported-by: Rares Salcudean
      Reviewed-by: Amit Langote
      Backpatch-through: 11 where partition pruning was introduced
      Discussion: https://postgr.es/m/CAHp_FN2xwEznH6oyS0hNTuUUZKp5PvegcVv=Co6nBXJ+mC7Y5w@mail.gmail.com
      cfde2349
  6. 11 Jul, 2019 1 commit
  7. 10 Jul, 2019 7 commits
  8. 09 Jul, 2019 5 commits
  9. 08 Jul, 2019 1 commit