1. 01 Apr, 2020 10 commits
    • Tom Lane's avatar
      Improve selectivity estimation for assorted match-style operators. · a8081860
      Tom Lane authored
      Quite a few matching operators such as JSONB's @> used "contsel" and
      "contjoinsel" as their selectivity estimators.  That was a bad idea,
      because (a) contsel is only a stub, yielding a fixed default estimate,
      and (b) that default is 0.001, meaning we estimate these operators as
      five times more selective than equality, which is surely pretty silly.
      
      There's a good model for improving this in ltree's ltreeparentsel():
      for any "var OP constant" query, we can try applying the operator
      to all of the column's MCV and histogram values, taking the latter
      as being a random sample of the non-MCV values.  That code is
      actually 100% generic, except for the question of exactly what
      default selectivity ought to be plugged in when we don't have stats.
      
      Hence, migrate the guts of ltreeparentsel() into the core code, provide
      wrappers "matchingsel" and "matchingjoinsel" with a more-appropriate
      default estimate, and use those for the non-geometric operators that
      formerly used contsel (mostly JSONB containment operators and tsquery
      matching).
      
      Also apply this code to some match-like operators in hstore, ltree, and
      pg_trgm, including the former users of ltreeparentsel as well as ones
      that improperly used contsel.  Since commit 911e7020 just created new
      versions of those extensions that we haven't released yet, we can sneak
      this change into those new versions instead of having to create an
      additional generation of update scripts.
      
      Patch by me, reviewed by Alexey Bashtanov
      
      Discussion: https://postgr.es/m/12237.1582833074@sss.pgh.pa.us
      a8081860
    • Peter Eisentraut's avatar
      Refactor code to look up local replication tuple · d8653f46
      Peter Eisentraut authored
      This unifies some duplicate code.
      
      Author: Amit Langote <amitlangote09@gmail.com>
      Discussion: https://www.postgresql.org/message-id/CA+HiwqFjYE5anArxvkjr37AQMd52L-LZtz9Ld2QrLQ3YfcYhTw@mail.gmail.com
      d8653f46
    • Peter Eisentraut's avatar
      Update SQL features count · 36962349
      Peter Eisentraut authored
      The previously listed total of 179 does not appear to be correct for
      SQL:2016 anymore.  (Previous SQL versions had slightly different
      feature sets, so it's plausible that it was once correct.)  The
      currently correct count is the number of rows in the respective tables
      in appendix F in SQL parts 2 and 11, minus 2 features that are listed
      twice.  Thus the correct count is currently 177.  This also matches
      the number of Core entries the built documentation currently shows, so
      it's internally consistent.
      36962349
    • Alexander Korotkov's avatar
      4d276ba9
    • Alexander Korotkov's avatar
      Correct CREATE INDEX documentation for opclass parameters · 3eabc623
      Alexander Korotkov authored
      Old versions of opclass parameters patch supported ability to specify DEFAULT
      as the opclass name in CREATE INDEX command.  This ability was removed in the
      final version, but 911e7020 still mentions that in the documentation.
      3eabc623
    • Alexander Korotkov's avatar
    • Michael Paquier's avatar
      Fix crash in psql when attempting to reuse old connection · 8d84dd00
      Michael Paquier authored
      In a psql session, if the connection to the server is abruptly cut, the
      referenced connection would become NULL as of CheckConnection().  This
      could cause a hard crash with psql if attempting to connect by reusing
      the past connection's data because of a null-pointer dereference with
      either PQhost() or PQdb().  This issue is fixed by making sure that no
      reuse of the past connection is done if it does not exist.
      
      Issue has been introduced by 6e5f8d48, so backpatch down to 12.
      
      Reported-by: Hugh Wang
      Author: Michael Paquier
      Reviewed-by: Álvaro Herrera, Tom Lane
      Discussion: https://postgr.es/m/16330-b34835d83619e25d@postgresql.org
      Backpatch-through: 12
      8d84dd00
    • Amit Kapila's avatar
      Fix coverity complaint about commit 40d964ec. · 2401d937
      Amit Kapila authored
      The coverity complained that dividing integer expressions and then
      converting the integer quotient to type "double" would lose fractional
      part.  Typecasting one of the arguments of expression with double should
      fix the report.
      
      Author: Mahendra Singh Thalor
      Reviewed-by: Amit Kapila
      Discussion: https://postgr.es/m/20200329224818.6phnhv7o2q2rfovf@alap3.anarazel.de
      2401d937
    • Bruce Momjian's avatar
      psql: do file completion for \gx · 08481eed
      Bruce Momjian authored
      This was missed when the feature was added.
      
      Reported-by: Vik Fearing
      
      Discussion: https://postgr.es/m/eca20529-0b06-b493-ee38-f071a75dcd5b@postgresfriends.org
      
      Backpatch-through: 10
      08481eed
    • Michael Paquier's avatar
      Add -c/--restore-target-wal to pg_rewind · a7e8ece4
      Michael Paquier authored
      pg_rewind needs to copy from the source cluster to the target cluster a
      set of relation blocks changed from the previous checkpoint where WAL
      forked up to the end of WAL on the target.  Building this list of
      relation blocks requires a range of WAL segments that may not be present
      anymore on the target's pg_wal, causing pg_rewind to fail.  It is
      possible to work around this issue by copying manually the WAL segments
      needed but this may lead to some extra and actually useless work.
      
      This commit introduces a new option allowing pg_rewind to use a
      restore_command while doing the rewind by grabbing the parameter value
      of restore_command from the target cluster configuration.  This allows
      the rewind operation to be more reliable, so as only the WAL segments
      needed by the rewind are restored from the archives.
      
      In order to be able to do that, a new routine is added to src/common/ to
      allow frontend tools to restore files from archives using an
      already-built restore command.  This version is more simple than the
      backend equivalent as there is no need to handle the non-recovery case.
      
      Author: Alexey Kondratov
      Reviewed-by: Andrey Borodin, Andres Freund, Alvaro Herrera, Alexander
      Korotkov, Michael Paquier
      Discussion: https://postgr.es/m/a3acff50-5a0d-9a2c-b3b2-ee36168955c1@postgrespro.ru
      a7e8ece4
  2. 31 Mar, 2020 24 commits
  3. 30 Mar, 2020 6 commits
    • Michael Paquier's avatar
      Revert "Skip redundant anti-wraparound vacuums" · dd9ac7d5
      Michael Paquier authored
      This reverts commit 2aa6e331, that added a fast path to skip
      anti-wraparound and non-aggressive autovacuum jobs (these have no sense
      as anti-wraparound implies aggressive).  With a cluster using a high
      amount of relations with a portion of them being heavily updated, this
      could cause autovacuum to lock down, with autovacuum workers attempting
      repeatedly those jobs on the same relations for the same database, that
      just kept being skipped.  This lock down can be solved with a manual
      VACUUM FREEZE.
      
      Justin King has reported one environment where the issue happened, and
      Julien Rouhaud and I have been able to reproduce it in a second
      environment.  With a very aggressive autovacuum_freeze_max_age,
      triggering those jobs with pgbench is a matter of minutes, and hitting
      the lock down is a lot harder (my local tests failed to do that).
      
      Note that anti-wraparound and non-aggressive jobs can only be triggered
      on a subset of shared catalogs:
      - pg_auth_members
      - pg_authid
      - pg_database
      - pg_replication_origin
      - pg_shseclabel
      - pg_subscription
      - pg_tablespace
      While the lock down was possible down to v12, the root cause of those
      jobs is a much older issue, which needs more analysis.
      
      Bonus thanks to Andres Freund for the discussion.
      
      Reported-by: Justin King
      Discussion: https://postgr.es/m/CAE39h22zPLrkH17GrkDgAYL3kbjvySYD1io+rtnAUFnaJJVS4g@mail.gmail.com
      Backpatch-through: 12
      dd9ac7d5
    • Peter Geoghegan's avatar
      Refactor nbtree high key truncation. · 7c2dbc69
      Peter Geoghegan authored
      Simplify _bt_truncate(), the routine that generates truncated leaf page
      high keys.  Remove a micro-optimization that avoided a second palloc0()
      call (this was used when a heap TID was needed in the final pivot tuple,
      though only when the index happened to not be an INCLUDE index).
      
      Removing this dubious micro-optimization allows _bt_truncate() to use
      the index_truncate_tuple() indextuple.c utility routine in all cases.
      This was already the common case.
      
      This commit is a HEAD-only follow up to bugfix commit 4b42a899.
      7c2dbc69
    • Andres Freund's avatar
      Deduplicate PageIsNew() check in lazy_scan_heap(). · d4b34f60
      Andres Freund authored
      The recheck isn't needed anymore, as RelationGetBufferForTuple() now
      extends the relation with RBM_ZERO_AND_LOCK. Previously we needed to
      handle the fact that relation extension extended the relation and then
      separately acquired a lock on the page - while expecting that the page
      is empty.
      
      Reported-By: Ranier Vilela
      Discussion: https://postgr.es/m/CAEudQArA_=J0D5T258xsCY6Xtf6wiH4b=QDPDgVS+WZUN10WDw@mail.gmail.com
      d4b34f60
    • Alexander Korotkov's avatar
      Fix missing SP-GiST support in 911e7020 · 364bdd0b
      Alexander Korotkov authored
      911e7020 misses setting of amoptsprocnum for SP-GiST.  This commit fixes
      that.
      364bdd0b
    • Alexander Korotkov's avatar
      Remove rudiments of supporting procnum == 0 from 911e7020 · 851b14b0
      Alexander Korotkov authored
      Early versions of opclass options patch uses zero support procedure as opclass
      options procedure.  This commit removes rudiments of it, which were committed
      in 911e7020.  Also, it implements correct handling of amoptsprocnum == 0.
      851b14b0
    • Peter Geoghegan's avatar
      Consistently truncate non-key suffix columns. · 4b42a899
      Peter Geoghegan authored
      INCLUDE indexes failed to have their non-key attributes physically
      truncated away in certain rare cases.  This led to physically larger
      pivot tuples that contained useless non-key attribute values.  The
      impact on users should be negligible, but this is still clearly a
      regression (Postgres 11 supports INCLUDE indexes, and yet was not
      affected).
      
      The bug appeared in commit dd299df8, which introduced "true" suffix
      truncation of key attributes.
      
      Discussion: https://postgr.es/m/CAH2-Wz=E8pkV9ivRSFHtv812H5ckf8s1-yhx61_WrJbKccGcrQ@mail.gmail.com
      Backpatch: 12-, where "true" suffix truncation was introduced.
      4b42a899