1. 01 Apr, 2019 5 commits
    • Noah Misch's avatar
      Update HINT for pre-existing shared memory block. · 5a907404
      Noah Misch authored
      One should almost always terminate an old process, not use a manual
      removal tool like ipcrm.  Removal of the ipcclean script eleven years
      ago (39627b1a) and its non-replacement
      corroborate that manual shm removal is now a niche goal.  Back-patch to
      9.4 (all supported versions).
      
      Reviewed by Daniel Gustafsson and Kyotaro HORIGUCHI.
      
      Discussion: https://postgr.es/m/20180812064815.GB2301738@rfd.leadboat.com
      5a907404
    • Andres Freund's avatar
      tableam: bitmap table scan. · bfbcad47
      Andres Freund authored
      This moves bitmap heap scan support to below an optional tableam
      callback. It's optional as the whole concept of bitmap heapscans is
      fairly block specific.
      
      This basically moves the work previously done in bitgetpage() into the
      new scan_bitmap_next_block callback, and the direct poking into the
      buffer done in BitmapHeapNext() into the new scan_bitmap_next_tuple()
      callback.
      
      The abstraction is currently somewhat leaky because
      nodeBitmapHeapscan.c's prefetching and visibilitymap based logic
      remains - it's likely that we'll later have to move more into the
      AM. But it's not trivial to do so without introducing a significant
      amount of code duplication between the AMs, so that's a project for
      later.
      
      Note that now nodeBitmapHeapscan.c and the associated node types are a
      bit misnamed. But it's not clear whether renaming wouldn't be a cure
      worse than the disease. Either way, that'd be best done in a separate
      commit.
      
      Author: Andres Freund
      Reviewed-By: Robert Haas (in an older version)
      Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
      bfbcad47
    • Andres Freund's avatar
      tableam: sample scan. · 73c954d2
      Andres Freund authored
      This moves sample scan support to below tableam. It's not optional as
      there is, in contrast to e.g. bitmap heap scans, no alternative way to
      perform tablesample queries. If an AM can't deal with the block based
      API, it will have to throw an ERROR.
      
      The tableam callbacks for this are block based, but given the current
      TsmRoutine interface, that seems to be required.
      
      The new interface doesn't require TsmRoutines to perform visibility
      checks anymore - that requires the TsmRoutine to know details about
      the AM, which we want to avoid.  To continue to allow taking the
      returned number of tuples account SampleScanState now has a donetuples
      field (which previously e.g. existed in SystemRowsSamplerData), which
      is only incremented after the visibility check succeeds.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
      73c954d2
    • Andres Freund's avatar
      tableam: Formatting and other minor cleanups. · 4bb50236
      Andres Freund authored
      The superflous heapam_xlog.h includes were reported by Peter
      Geoghegan.
      4bb50236
    • Peter Geoghegan's avatar
      Fix nbtree high key "continuescan" row compare bug. · 76a39f22
      Peter Geoghegan authored
      Commit 29b64d1d mishandled skipping over truncated high key attributes
      during row comparisons.  The row comparison key matching loop would loop
      forever when a truncated attribute was encountered for a row compare
      subkey.  Fix by following the example of other code in the loop: advance
      the current subkey, or break out of the loop when the last subkey is
      reached.
      
      Add test coverage for the relevant _bt_check_rowcompare() code path.
      The new test case is somewhat tied to nbtree implementation details,
      which isn't ideal, but seems unavoidable.
      76a39f22
  2. 31 Mar, 2019 7 commits
  3. 30 Mar, 2019 7 commits
    • Tom Lane's avatar
      Speed up planning when partitions can be pruned at plan time. · 428b260f
      Tom Lane authored
      Previously, the planner created RangeTblEntry and RelOptInfo structs
      for every partition of a partitioned table, even though many of them
      might later be deemed uninteresting thanks to partition pruning logic.
      This incurred significant overhead when there are many partitions.
      Arrange to postpone creation of these data structures until after
      we've processed the query enough to identify restriction quals for
      the partitioned table, and then apply partition pruning before not
      after creation of each partition's data structures.  In this way
      we need not open the partition relations at all for partitions that
      the planner has no real interest in.
      
      For queries that can be proven at plan time to access only a small
      number of partitions, this patch improves the practical maximum
      number of partitions from under 100 to perhaps a few thousand.
      
      Amit Langote, reviewed at various times by Dilip Kumar, Jesper Pedersen,
      Yoshikazu Imai, and David Rowley
      
      Discussion: https://postgr.es/m/9d7c5112-cb99-6a47-d3be-cf1ee6862a1d@lab.ntt.co.jp
      428b260f
    • Tomas Vondra's avatar
      Fix compiler warnings in multivariate MCV code · ad3107b9
      Tomas Vondra authored
      Compiler warnings were observed on gcc 3.4.6 (on gaur).
      
      The assert is unnecessary, as the indexes are uint16 and so always >= 0.
      
      Reported-by: Tom Lane
      ad3107b9
    • Tomas Vondra's avatar
      Additional fixes of memory alignment in pg_mcv_list code · ea4e1c0e
      Tomas Vondra authored
      Commit d85e0f36 tried to fix memory alignment issues in serialization
      and deserialization of pg_mcv_list values, but it was a few bricks shy.
      The arrays of uint16 indexes in serialized items was not aligned, and
      the both the values and isnull flags were using the same pointer.
      
      Per investigation by Tom Lane on gaur.
      ea4e1c0e
    • Tom Lane's avatar
      Avoid crash in partitionwise join planning under GEQO. · 7ad6498f
      Tom Lane authored
      While trying to plan a partitionwise join, we may be faced with cases
      where one or both input partitions for a particular segment of the join
      have been pruned away.  In HEAD and v11, this is problematic because
      earlier processing didn't bother to make a pruned RelOptInfo fully
      valid.  With an upcoming patch to make partition pruning more efficient,
      this'll be even more problematic because said RelOptInfo won't exist at
      all.
      
      The existing code attempts to deal with this by retroactively making the
      RelOptInfo fully valid, but that causes crashes under GEQO because join
      planning is done in a short-lived memory context.  In v11 we could
      probably have fixed this by switching to the planner's main context
      while fixing up the RelOptInfo, but that idea doesn't scale well to the
      upcoming patch.  It would be better not to mess with the base-relation
      data structures during join planning, anyway --- that's just a recipe
      for order-of-operations bugs.
      
      In many cases, though, we don't actually need the child RelOptInfo,
      because if the input is certainly empty then the join segment's result
      is certainly empty, so we can skip making a join plan altogether.  (The
      existing code ultimately arrives at the same conclusion, but only after
      doing a lot more work.)  This approach works except when the pruned-away
      partition is on the nullable side of a LEFT, ANTI, or FULL join, and the
      other side isn't pruned.  But in those cases the existing code leaves a
      lot to be desired anyway --- the correct output is just the result of
      the unpruned side of the join, but we were emitting a useless outer join
      against a dummy Result.  Pending somebody writing code to handle that
      more nicely, let's just abandon the partitionwise-join optimization in
      such cases.
      
      When the modified code skips making a join plan, it doesn't make a
      join RelOptInfo either; this requires some upper-level code to
      cope with nulls in part_rels[] arrays.  We would have had to have
      that anyway after the upcoming patch.
      
      Back-patch to v11 since the crash is demonstrable there.
      
      Discussion: https://postgr.es/m/8305.1553884377@sss.pgh.pa.us
      7ad6498f
    • Peter Eisentraut's avatar
      doc: Fix typo · ef6576f5
      Peter Eisentraut authored
      Author: Justin Pryzby <pryzby@telsasoft.com>
      ef6576f5
    • Peter Eisentraut's avatar
      Generated columns · fc22b662
      Peter Eisentraut authored
      This is an SQL-standard feature that allows creating columns that are
      computed from expressions rather than assigned, similar to a view or
      materialized view but on a column basis.
      
      This implements one kind of generated column: stored (computed on
      write).  Another kind, virtual (computed on read), is planned for the
      future, and some room is left for it.
      Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
      Reviewed-by: default avatarPavel Stehule <pavel.stehule@gmail.com>
      Discussion: https://www.postgresql.org/message-id/flat/b151f851-4019-bdb1-699e-ebab07d2f40a@2ndquadrant.com
      fc22b662
    • Peter Eisentraut's avatar
      Small code simplification for REINDEX CONCURRENTLY · 6b8b5364
      Peter Eisentraut authored
      This was left over from an earlier code structure.
      6b8b5364
  4. 29 Mar, 2019 13 commits
  5. 28 Mar, 2019 7 commits
    • Thomas Munro's avatar
      Fix typo. · 7e69323b
      Thomas Munro authored
      Author: Masahiko Sawada
      7e69323b
    • Andres Freund's avatar
      Fix a few comment copy & pastos. · 46bcd2af
      Andres Freund authored
      46bcd2af
    • Tomas Vondra's avatar
      Fix deserialization of pg_mcv_list values · 62bf0fb3
      Tomas Vondra authored
      There were multiple issues in deserialization of pg_mcv_list values.
      
      Firstly, the data is loaded from syscache, but the deserialization was
      performed after ReleaseSysCache(), at which point the data might have
      already disappeared.  Fixed by moving the calls in statext_mcv_load,
      and using the same NULL-handling code as existing stats.
      
      Secondly, the deserialized representation used pointers into the
      serialized representation.  But that is also unsafe, because the data
      may disappear at any time.  Fixed by reworking and simplifying the
      deserialization code to always copy all the data.
      
      And thirdly, when deserializing values for types passed by value, the
      code simply did memcpy(d,s,typlen) which however does not work on
      bigendian machines.  Fixed by using fetch_att/store_att_byval.
      62bf0fb3
    • Peter Eisentraut's avatar
      doc: Fix typo · f3afbbda
      Peter Eisentraut authored
      f3afbbda
    • Thomas Munro's avatar
      Use FullTransactionId for the transaction stack. · ad308058
      Thomas Munro authored
      Provide GetTopFullTransactionId() and GetCurrentFullTransactionId().
      The intended users of these interfaces are access methods that use
      xids for visibility checks but don't want to have to go back and
      "freeze" existing references some time later before the 32 bit xid
      counter wraps around.
      
      Use a new struct to serialize the transaction state for parallel
      query, because FullTransactionId doesn't fit into the previous
      serialization scheme very well.
      
      Author: Thomas Munro
      Reviewed-by: Heikki Linnakangas
      Discussion: https://postgr.es/m/CAA4eK1%2BMv%2Bmb0HFfWM9Srtc6MVe160WFurXV68iAFMcagRZ0dQ%40mail.gmail.com
      ad308058
    • Thomas Munro's avatar
      Add basic infrastructure for 64 bit transaction IDs. · 2fc7af5e
      Thomas Munro authored
      Instead of inferring epoch progress from xids and checkpoints,
      introduce a 64 bit FullTransactionId type and use it to track xid
      generation.  This fixes an unlikely bug where the epoch is reported
      incorrectly if the range of active xids wraps around more than once
      between checkpoints.
      
      The only user-visible effect of this commit is to correct the epoch
      used by txid_current() and txid_status(), also visible with
      pg_controldata, in those rare circumstances.  It also creates some
      basic infrastructure so that later patches can use 64 bit
      transaction IDs in more places.
      
      The new type is a struct that we pass by value, as a form of strong
      typedef.  This prevents the sort of accidental confusion between
      TransactionId and FullTransactionId that would be possible if we
      were to use a plain old uint64.
      
      Author: Thomas Munro
      Reported-by: Amit Kapila
      Reviewed-by: Andres Freund, Tom Lane, Heikki Linnakangas
      Discussion: https://postgr.es/m/CAA4eK1%2BMv%2Bmb0HFfWM9Srtc6MVe160WFurXV68iAFMcagRZ0dQ%40mail.gmail.com
      2fc7af5e
    • Andres Freund's avatar
      tableam: Support for an index build's initial table scan(s). · 2a96909a
      Andres Freund authored
      To support building indexes over tables of different AMs, the scans to
      do so need to be routed through the table AM.  While moving a fair
      amount of code, nearly all the changes are just moving code to below a
      callback.
      
      Currently the range based interface wouldn't make much sense for non
      block based table AMs. But that seems aceptable for now.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
      2a96909a
  6. 27 Mar, 2019 1 commit