1. 14 Apr, 2020 8 commits
  2. 13 Apr, 2020 8 commits
    • Alvaro Herrera's avatar
      Silence Perl warning · e56d717d
      Alvaro Herrera authored
      Now that warnings are enabled across the board, this code that tries to
      print an undef variable emits one.  Silently printing the empty string
      achieves the previous behavior.
      
      Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
      Reviewed-by: default avatarAndrew Dunstan <andrew.dunstan@2ndquadrant.com>
      Discussion: https://postgr.es/m/E1jO1VT-0008Qk-TM@gemulon.postgresql.org
      e56d717d
    • Peter Geoghegan's avatar
      Harmonize nbtree page split point code. · bc3087b6
      Peter Geoghegan authored
      An nbtree split point can be thought of as a point between two adjoining
      tuples from an imaginary version of the page being split that includes
      the incoming/new item (in addition to the items that really are on the
      page).  These adjoining tuples are called the lastleft and firstright
      tuples.
      
      The variables that represent split points contained a field called
      firstright, which is an offset number of the first data item from the
      original page that goes on the new right page.  The corresponding tuple
      from origpage was usually the same thing as the actual firstright tuple,
      but not always: the firstright tuple is sometimes the new/incoming item
      instead.  This situation seems unnecessarily confusing.
      
      Make things clearer by renaming the origpage offset returned by
      _bt_findsplitloc() to "firstrightoff".  We now have a firstright tuple
      and a firstrightoff offset number which are comparable to the
      newitem/lastleft tuples and the newitemoff/lastleftoff offset numbers
      respectively.  Also make sure that we are consistent about how we
      describe nbtree page split point state.
      
      Push the responsibility for dealing with pg_upgrade'd !heapkeyspace
      indexes down to lower level code, relieving _bt_split() from dealing
      with it directly.  This means that we always have a palloc'd left page
      high key on the leaf level, no matter what.  This enables simplifying
      some of the code (and code comments) within _bt_split().
      
      Finally, restructure the page split code to make it clearer why suffix
      truncation (which only takes place during leaf page splits) is
      completely different to the first data item truncation that takes place
      during internal page splits.  Tuples are marked as having fewer
      attributes stored in both cases, and the firstright tuple is truncated
      in both cases, so it's easy to imagine somebody missing the distinction.
      bc3087b6
    • Andrew Dunstan's avatar
      Use perl's $/ more idiomatically · 8f00d84a
      Andrew Dunstan authored
      This replaces a few occurrences of ugly code with a more clean and
      idiomatic usage. The problem was highlighted by perlcritic, but we're
      not enforcing the policy that led to the discovery.
      
      Discussion: https://postgr.es/m/20200412074245.GB623763@rfd.leadboat.com
      8f00d84a
    • Andrew Dunstan's avatar
      Use perl warnings pragma consistently · 7be5d8df
      Andrew Dunstan authored
      We've had a mixture of the warnings pragma, the -w switch on the shebang
      line, and no warnings at all. This patch removes the -w swicth and add
      the warnings pragma to all perl sources missing it. It raises the
      severity of the TestingAndDebugging::RequireUseWarnings  perlcritic
      policy to level 5, so that we catch any future violations.
      
      Discussion: https://postgr.es/m/20200412074245.GB623763@rfd.leadboat.com
      7be5d8df
    • Andrew Dunstan's avatar
      Print policy name in perlcritic messages · 8930e43e
      Andrew Dunstan authored
      This makes it easier to do a web search for details of the policy that's
      been violated, as well as displaying the name that might be needed for a
      policy override.
      
      Various perlcritic settings changes are being discussed, but this one
      should be uncontroversial.
      8930e43e
    • Robert Haas's avatar
      7a6b017b
    • Amit Kapila's avatar
      Cosmetic fixups for WAL usage work. · ef08ca11
      Amit Kapila authored
      Reported-by: Justin Pryzby and Euler Taveira
      Author: Justin Pryzby and Julien Rouhaud
      Reviewed-by: Amit Kapila
      Discussion: https://postgr.es/m/CAB-hujrP8ZfUkvL5OYETipQwA=e3n7oqHFU=4ZLxWS_Cza3kQQ@mail.gmail.com
      ef08ca11
    • Peter Eisentraut's avatar
      Improve error messages after LoadLibrary() · 0c620a58
      Peter Eisentraut authored
      Move the file name to a format parameter to ease translatability.  Add
      error code where missing.  Make the wording consistent.
      0c620a58
  3. 12 Apr, 2020 4 commits
    • Tom Lane's avatar
      Doc: introduce new layout for tables of functions and operators. · e894c618
      Tom Lane authored
      We've long fought with the draconian space limitations of our
      traditional table layout for describing SQL functions and operators.
      This commit introduces a new approach, though so far I've only applied
      it to a few of those tables.  The new way makes use of DocBook's support
      for different layouts in different rows of a table, and allows the
      descriptions and examples for a function or operator to run to several
      lines without as much ugliness and wasted space as before.
      
      The core layout concept is now
      
           Name              Signature
                            Description
                       Example     Example Result
      
      so that a function or operator really has three table rows not one,
      but we group them to look like one row by having the name column
      have only one entry for all three rows.  (Actually, there could be
      four or more rows if you wanted to have more than one example, which
      is another thing that was painful before but works easily now.)
      This is handled by a "morerows" annotation on the name entry, which
      isn't perfect (notably, the toolchain is not smart enough to avoid
      breaking these row groups across PDF pages) but there seems no better
      solution in DocBook.  The name column is normally fairly narrow,
      allowing plenty of space for the other column(s), and not wasting too
      much space when one of the other components runs to multiple lines.
      
      The varying row layout is managed by defining named "spans" and then
      tagging entries with a "spanname" of "name", "sig", "desc", "example",
      or "exresult".  This provides a bit of semantic annotation to go with
      the formatting improvement, which seems like a good thing.  (It seems
      that we have to re-define these spans afresh for each table, which is
      annoying, but it's not any worse than the duplication involved in
      the table headers.  At least that gives us an opportunity to vary the
      relative column widths per-table, which is handy since function tables
      sometimes need much wider name columns than operator tables.)
      
      Signature entries should be written in the style
          <function>fname</function>(<type>typename</type> ...)
          <returnvalue>typename</returnvalue>
      The <returnvalue> tag produces a right arrow before the result type
      name.  (I'll document that convention in a user-visible place later.)
      
      While this provides significantly more horizontal space than before
      for examples, it's still true that PDF output is a lot narrower than
      typical webpage viewing windows, so some examples need to be broken
      in places where there is no whitespace.  I've added &zwsp; markers in
      suitable places to allow the tables to render warning-free in PDF.
      
      I've so far converted only the date/time operator, date/time function,
      and enum function tables in sections 9.9 and 9.10; these were chosen
      to provide a reasonable sample of the formatting problems that need
      to be solved.  Assuming that this looks good on the website and doesn't
      provoke howls of anguish, I'll work on the other similar tables in the
      near future.
      
      There's a moderate amount of new editorial content in this patch along
      with the raw formatting changes; for instance I had to write text
      descriptions for operators that lacked them.  I failed to resist the
      temptation to improve some other descriptions and examples, too.
      
      Patch by me, with thanks to Alexander Lakhin for assistance with
      figuring out some formatting issues.
      
      Discussion: https://postgr.es/m/9326.1581457869@sss.pgh.pa.us
      e894c618
    • Tom Lane's avatar
      Doc: introduce and document "&zwsp;" for allowing optional line breaks. · 88d934f0
      Tom Lane authored
      We already had a couple of places using zero-width spaces for formatting
      hackery, and we're going to need more if we ever want the PDF manuals to
      look decent.  But please let's not write hard-coded Unicode escapes.
      We can avoid that by using a custom entity, which also provides a place
      to put a teeny bit of documentation about what it is and how to use it.
      
      I'd previously posted a patch using "&break;" for this, but on reflection
      that would be horrible to grep for.  Instead let's use "&zwsp;", based
      on the name of the Unicode symbol ("zero width space").
      
      Discussion: https://postgr.es/m/9326.1581457869@sss.pgh.pa.us
      88d934f0
    • Robert Haas's avatar
      Rename pg_validatebackup to pg_verifybackup. · dbc60c55
      Robert Haas authored
      Also, use "verify" rather than "validate" to refer to the process
      being undertaken here. Per discussion, that is a more appropriate
      term.
      
      Discussion: https://www.postgresql.org/message-id/172c9d9b-1d0a-1b94-1456-376b1e017322@2ndquadrant.com
      Discussion: http://postgr.es/m/CA+TgmobLgMh6p8FmLbj_rv9Uhd7tPrLnAyLgGd2SoSj=qD-bVg@mail.gmail.com
      dbc60c55
    • Peter Geoghegan's avatar
      Doc: Fix contrib/amcheck tip. · 26640c40
      Peter Geoghegan authored
      Fixes an oversight in commit 20fbb711.
      26640c40
  4. 11 Apr, 2020 9 commits
    • Tom Lane's avatar
      Suppress -Wimplicit-fallthrough warning in new LIMIT WITH TIES code. · 35cb574a
      Tom Lane authored
      The placement of the fall-through comment in this code appears not to
      work to suppress the warning in recent gcc.  Move it to the bottom of
      the case group, and add an assertion that we didn't get there through
      some other code path.  Also improve wording of nearby comments.
      
      Julien Rouhaud, comment hacking by me
      
      Discussion: https://postgr.es/m/CAOBaU_aLdPGU5wCpaowNLF-Q8328iR7mj1yJAhMOVsdLwY+sdg@mail.gmail.com
      35cb574a
    • Noah Misch's avatar
      Optimize RelationFindReplTupleSeq() for CLOBBER_CACHE_ALWAYS. · 328c7099
      Noah Misch authored
      Specifically, remember lookup_type_cache() results instead of retrieving
      them once per comparison.  Under CLOBBER_CACHE_ALWAYS, this reduced
      src/test/subscription/t/001_rep_changes.pl elapsed time by an order of
      magnitude, which reduced check-world elapsed time by 9%.
      
      Discussion: https://postgr.es/m/20200406085420.GC162712@rfd.leadboat.com
      328c7099
    • Noah Misch's avatar
      When WalSndCaughtUp, sleep only in WalSndWaitForWal(). · 42168581
      Noah Misch authored
      Before sleeping, WalSndWaitForWal() sends a keepalive if MyWalSnd->write
      < sentPtr.  That is important in logical replication.  When the latest
      physical LSN yields no logical replication messages (a common case),
      that keepalive elicits a reply, and processing the reply updates
      pg_stat_replication.replay_lsn.  WalSndLoop() lacks that; when
      WalSndLoop() slept, replay_lsn advancement could stall until
      wal_receiver_status_interval elapsed.  This sometimes stalled
      src/test/subscription/t/001_rep_changes.pl for up to 10s.
      
      Discussion: https://postgr.es/m/20200406063649.GA3738151@rfd.leadboat.com
      42168581
    • Tom Lane's avatar
      Make EXPLAIN report maximum hashtable usage across multiple rescans. · 969f9d0b
      Tom Lane authored
      Before discarding the old hash table in ExecReScanHashJoin, capture
      its statistics, ensuring that we report the maximum hashtable size
      across repeated rescans of the hash input relation.  We can repurpose
      the existing code for reporting hashtable size in parallel workers
      to help with this, making the patch pretty small.  This also ensures
      that if rescans happen within parallel workers, we get the correct
      maximums across all instances.
      
      Konstantin Knizhnik and Tom Lane, per diagnosis by Thomas Munro
      of a trouble report from Alvaro Herrera.
      
      Discussion: https://postgr.es/m/20200323165059.GA24950@alvherre.pgsql
      969f9d0b
    • Tom Lane's avatar
      Clear dangling pointer to avoid bogus EXPLAIN printout in a corner case. · 5c27bce7
      Tom Lane authored
      ExecReScanHashJoin will destroy the join's hash table if it expects
      that the inner relation will produce different rows on rescan.
      Up to now it's not bothered to clear the additional pointer to that
      hash table that exists in the child HashState node.  However, it's
      possible for the query to terminate without building a fresh hash
      table (this happens if the outer relation is found to be empty
      during the final rescan).  So we can end with a dangling pointer
      to a deleted hash table.  That was harmless originally, but since
      9.0 EXPLAIN ANALYZE has used that pointer to print hash table
      statistics.  In debug builds this reproducibly results in garbage
      statistics.  In non-debug builds there's frequently no ill effects,
      but in principle one could get wrong EXPLAIN ANALYZE output, or
      perhaps even a crash if free() has released the hashtable memory
      back to the OS.
      
      To fix, just make sure we clear the additional pointer when destroying
      the hash table.  In problematic cases, EXPLAIN ANALYZE will then print
      no hashtable statistics (reverting to its pre-9.0 behavior).  This isn't
      ideal, but since the problem manifests only in unusual corner cases,
      it's hard to justify taking any risks to do better in the back
      branches.  A follow-on patch will improve matters in HEAD.
      
      Konstantin Knizhnik and Tom Lane, per diagnosis by Thomas Munro
      of a trouble report from Alvaro Herrera.
      
      Discussion: https://postgr.es/m/20200323165059.GA24950@alvherre.pgsql
      5c27bce7
    • Peter Eisentraut's avatar
      Fix RELCACHE_FORCE_RELEASE issue · 12fb189b
      Peter Eisentraut authored
      Introduced by 83fd4532.  To fix, the
      tuple descriptors need to be copied into the current memory context.
      
      Discussion: https://www.postgresql.org/message-id/04d78603-edae-9243-9dde-fe3037176a7d@2ndquadrant.com
      12fb189b
    • Peter Eisentraut's avatar
      Fix relcache reference leak · 5a1d0c99
      Peter Eisentraut authored
      Introduced by 83fd4532
      5a1d0c99
    • Andrew Gierth's avatar
      doc: restore intentional typo · 8a47b775
      Andrew Gierth authored
      Commit ac862376 "fixed" a typo in an example of what would happen in
      the event of a typo. Restore the original typo and add a comment about
      its intentionality. Backpatch to 12 where the error was introduced.
      
      Per report from irc user Nicolás Alvarez.
      8a47b775
    • Peter Geoghegan's avatar
      Add contrib/amcheck debug message. · 20fbb711
      Peter Geoghegan authored
      Add a DEBUG1 message indicating that verification of the index structure
      is underway.  Also reduce the severity level of the existing "tree
      level" debug message to DEBUG1.  It should never have been made DEBUG2.
      Any B-Tree index with more than a couple of levels will generally also
      have so many pages that the per-page DEBUG2 messages will become
      completely unmanageable.
      
      In passing, add a new "Tip" to the docs that advises users that run into
      corruption that the debug messages might provide useful additional
      context.
      20fbb711
  5. 10 Apr, 2020 4 commits
  6. 09 Apr, 2020 7 commits
    • Tom Lane's avatar
      Further stabilize results of 019_replslot_limit.pl. · e083fa34
      Tom Lane authored
      Depending on specific values of restart_lsn or pg_current_wal_lsn()
      is obviously unsafe.  The previous coding tried to dodge this issue
      by rounding off, but that's not good enough, as shown by multiple
      buildfarm members.  Nuke all the uses of these values except for
      null-ness checks, pending some credible argument why we should think
      something else could be usefully stable.
      
      Kyotaro Horiguchi, further modified by me
      
      Discussion: https://postgr.es/m/E1jM1Sa-0003mS-99@gemulon.postgresql.org
      e083fa34
    • Tom Lane's avatar
      Further cleanup of ts_headline code. · 2e0e409e
      Tom Lane authored
      Suppress a probably-meaningless uninitialized-variable warning
      (induced by my previous patch, I'm sorry to say).
      
      Improve mark_hl_fragments()'s test for overlapping cover strings:
      it failed to consider the possibility that the current string is
      strictly within another one.  That's unlikely given the preceding
      splitting into MaxWords fragments, but I don't think it's impossible.
      
      Discussion: https://postgr.es/m/16345-2e0cf5cddbdcd3b4@postgresql.org
      2e0e409e
    • Tom Lane's avatar
      Doc: improve documentation about ts_headline() function. · a4d4f591
      Tom Lane authored
      Now that I've had my nose in that code, I thought the docs about
      it left something to be desired.
      a4d4f591
    • Tom Lane's avatar
      Fix default text search parser's ts_headline code for phrase queries. · c9b0c678
      Tom Lane authored
      This code could produce very poor results when asked to highlight a
      string based on a query using phrase-match operators.  The root cause
      is that hlCover(), which is supposed to find a minimal substring that
      matches the query, was written assuming that word position is not
      significant.  I'm only 95% convinced that its algorithm was correct even
      for plain AND/OR queries; but it definitely fails completely for phrase
      matches, causing it to possibly not identify a cover string at all.
      
      Hence, rewrite hlCover() with a less-tense algorithm that just tries
      all the possible substrings, earlier and shorter ones first.  (This is
      not as bad as it sounds performance-wise, because all of the string
      matching has been done already: the repeated tsquery match checks
      boil down to pointer comparisons.)
      
      Unfortunately, since that approach produces more candidate cover
      strings than before, it also exposes that there were bugs in the
      heuristics in mark_hl_words() for selecting a best cover string.
      Fixes there include:
      * Do not apply the ShortWord filter to words that appear in the query.
      * Remove a misguided optimization for quickly rejecting a cover.
      * Fix order-of-operation bug that could cause computation of a
      wrong figure of merit (poslen) when shortening a cover.
      * Change the preference rule so that candidate headlines that do not
      include their whole cover string (after MaxWords trimming) are lowest
      priority, since they may not actually satisfy the user's query.
      
      This results in some changes in existing regression test cases,
      but they all seem reasonable.  Note in particular that the tests
      involving strings like "1 2 3" were previously being affected by
      the ShortWord filter, masking the normal matching behavior.
      
      Per bug #16345 from Augustinas Jokubauskas; the new test cases are
      based on that example.  Back-patch to 9.6 where phrase search was
      added to tsquery.
      
      Discussion: https://postgr.es/m/16345-2e0cf5cddbdcd3b4@postgresql.org
      c9b0c678
    • Tom Lane's avatar
      Cosmetic improvements for default text search parser's ts_headline code. · b10f8bb9
      Tom Lane authored
      This code was woefully unreadable and under-commented.  Try to improve
      matters by adding comments, using some macros to make complicated
      if-tests more readable, using boolean type where appropriate, etc.
      There are a couple of tiny coding improvements too, but this commit
      includes (I hope) no behavioral change.
      
      Nonetheless, back-patch as far as 9.6, because a followup bug-fixing
      commit depends on this.
      
      Discussion: https://postgr.es/m/16345-2e0cf5cddbdcd3b4@postgresql.org
      b10f8bb9
    • Peter Eisentraut's avatar
      Fix CREATE TABLE LIKE INCLUDING GENERATED column order issue · e92e4a2b
      Peter Eisentraut authored
      CREATE TABLE LIKE INCLUDING GENERATED would fail if a generated column
      referred to a column with a higher attribute number.  This is because
      the column mapping mechanism created the mapping incrementally as
      columns are added.  This was sufficient for previous uses of that
      mechanism (omitting dropped columns), and it also happened to work if
      generated columns only referred to columns with lower attribute
      numbers, but here it failed.
      
      This fix is to build the attribute mapping in a separate loop before
      processing the columns in detail.
      
      Bug: #16342
      Reported-by: default avatarEthan Waldo <ewaldo@healthetechs.com>
      Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
      e92e4a2b
    • Fujii Masao's avatar
      Fix typo in pg_validatebackup documentation. · c4f82a77
      Fujii Masao authored
      Author: Fujii Masao
      Reviewed-by: Robert Haas
      Discussion: https://postgr.es/m/78f76a3d-1a28-a97d-0394-5c96985dd1c0@oss.nttdata.com
      c4f82a77