1. 02 Mar, 2021 8 commits
    • Alvaro Herrera's avatar
      Use native path separators to pg_ctl in initdb · 75dbfe4c
      Alvaro Herrera authored
      On Windows, CMD.EXE allegedly does not run a command that uses forward slashes,
      so let's convert the path to use backslashes instead.
      
      Backpatch to 10.
      
      Author: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
      Reviewed-by: default avatarJuan José Santamaría Flecha <juanjo.santamaria@gmail.com>
      Discussion: https://postgr.es/m/CAMm1aWaNDuaPYFYMAqDeJrZmPtNvLcJRS++CcZWY8LT6KcoBZw@mail.gmail.com
      75dbfe4c
    • Tom Lane's avatar
      Suppress unnecessary regex subre nodes in a couple more cases. · 4604f83f
      Tom Lane authored
      This extends the changes made in commit cebc1d34, teaching
      parseqatom() to generate fewer or cheaper subre nodes in some edge
      cases.  The case of interest here is a quantified atom that is "messy"
      only because it has greediness opposite to what preceded it (whereas
      captures and backrefs are intrinsically messy).  In this case we don't
      need an iteration node, since we don't care where the sub-matches of
      the quantifier are; and we might also not need a second concatenation
      node.  This seems of only marginal real-world use according to my
      testing, but I wanted to get it in before wrapping up this series of
      regex performance fixes.
      
      Discussion: https://postgr.es/m/1340281.1613018383@sss.pgh.pa.us
      4604f83f
    • Tom Lane's avatar
      Improve performance of regular expression back-references. · 0c3405cf
      Tom Lane authored
      In some cases, at the time that we're doing an NFA-based precheck
      of whether a backref subexpression can match at a particular place
      in the string, we already know which substring the referenced
      subexpression matched.  If so, we might as well forget about the NFA
      and just compare the substring; this is faster and it gives an exact
      rather than approximate answer.
      
      In general, this optimization can help while we are prechecking within
      the second child expression of a concat node, while the capture was
      within the first child expression; then the substring was saved during
      cdissect() of the first child and will be available to NFA checks done
      while cdissect() recurses into the second child.  It can help quite a
      lot if the tree looks like
      
                    concat
                   /      \
            capture        concat
                          /      \
           expensive stuff        backref
      
      as we will be able to avoid recursively dissecting the "expensive
      stuff" before discovering that the backref isn't satisfied with a
      particular midpoint that the lower concat node is testing.  This
      doesn't help if the concat tree is left-deep, as the capture node
      won't get set soon enough (and it's hard to fix that without changing
      the engine's match behavior).  Fortunately, right-deep concat trees
      are the common case.
      
      Patch by me, reviewed by Joel Jacobson
      
      Discussion: https://postgr.es/m/661609.1614560029@sss.pgh.pa.us
      0c3405cf
    • Tom Lane's avatar
      Fix semantics of regular expression back-references. · 4aea704a
      Tom Lane authored
      POSIX defines the behavior of back-references thus:
      
          The back-reference expression '\n' shall match the same (possibly
          empty) string of characters as was matched by a subexpression
          enclosed between "\(" and "\)" preceding the '\n'.
      
      As far as I can see, the back-reference is supposed to consider only
      the data characters matched by the referenced subexpression.  However,
      because our engine copies the NFA constructed from the referenced
      subexpression, it effectively enforces any constraints therein, too.
      As an example, '(^.)\1' ought to match 'xx', or any other string
      starting with two occurrences of the same character; but in our code
      it does not, and indeed can't match anything, because the '^' anchor
      constraint is included in the backref's copied NFA.  If POSIX intended
      that, you'd think they'd mention it.  Perl for one doesn't act that
      way, so it's hard to conclude that this isn't a bug.
      
      Fix by modifying the backref's NFA immediately after it's copied from
      the reference, replacing all constraint arcs by EMPTY arcs so that the
      constraints are treated as automatically satisfied.  This still allows
      us to enforce matching rules that depend only on the data characters;
      for example, in '(^\d+).*\1' the NFA matching step will still know
      that the backref can only match strings of digits.
      
      Perhaps surprisingly, this change does not affect the results of any
      of a rather large corpus of real-world regexes.  Nonetheless, I would
      not consider back-patching it, since it's a clear compatibility break.
      
      Patch by me, reviewed by Joel Jacobson
      
      Discussion: https://postgr.es/m/661609.1614560029@sss.pgh.pa.us
      4aea704a
    • Michael Paquier's avatar
      Fix duplicated test case in TAP tests of reindexdb · c5530d84
      Michael Paquier authored
      The same test for REINDEX (VERBOSE) was done twice, while it is clear
      that the second test should use --concurrently.  Issue introduced in
      5dc92b84, for what looks like a copy-paste mistake.
      
      Reviewed-by: Mark Dilger
      Discussion: https://postgr.es/m/A7AE97EA-F4B0-4CAB-8FFF-3FECD31F9D63@enterprisedb.com
      Backpatch-through: 12
      c5530d84
    • Michael Paquier's avatar
      Simplify code to switch pg_class.relrowsecurity in tablecmds.c · fabde52f
      Michael Paquier authored
      The same code pattern was repeated twice to enable or disable ROW LEVEL
      SECURITY with an ALTER TABLE command.  This makes the code slightly
      cleaner.
      
      Author: Justin Pryzby
      Reviewed-by: Zhihong Yu
      Discussion: https://postgr.es/m/20210228211854.GC20769@telsasoft.com
      fabde52f
    • Michael Paquier's avatar
      doc: Improve description of data checksums · bd1b8d0e
      Michael Paquier authored
      This partially reverts bcf2667b that got incorrectly merged, and this
      improves the wording of the documentation that existed before that.
      
      Per discussion with Justin Pryzby.
      
      Discussion: https://postgr.es/m/20210301004647.GF20769@telsasoft.com
      bd1b8d0e
    • Michael Paquier's avatar
      doc: Mention archive_command failure handling on signals · 8c1b6a18
      Michael Paquier authored
      The behavior is similar to restore_command, which was already documented
      for the restore part, but not the archive part.
      
      Author: Benoit Lobréau
      Reviewed-by: Julien Rouhaud
      Discussion: https://postgr.es/m/CAPE8EZ7akCzc1hWohA4AcbmKtHh9rcWAB5MStOeZD2+9jC+hLQ@mail.gmail.com
      8c1b6a18
  2. 01 Mar, 2021 12 commits
  3. 28 Feb, 2021 3 commits
  4. 27 Feb, 2021 6 commits
  5. 26 Feb, 2021 6 commits
    • Tom Lane's avatar
      Doc: further clarify libpq's description of connection string URIs. · 4e90052c
      Tom Lane authored
      Break the synopsis into named parts to make it less confusing.
      Make more than zero effort at applying SGML markup.  Do a bit
      of copy-editing of nearby text.
      
      The synopsis revision is by Alvaro Herrera and Paul Förster,
      the rest is my fault.  Back-patch to v10 where multi-host
      connection strings appeared.
      
      Discussion: https://postgr.es/m/6E752D6B-487C-463E-B6E2-C32E7FB007EA@gmail.com
      4e90052c
    • Tom Lane's avatar
      Improve memory management in regex compiler. · 0fc1af17
      Tom Lane authored
      The previous logic here created a separate pool of arcs for each
      state, so that the out-arcs of each state were physically stored
      within it.  Perhaps this choice was driven by trying to not include
      a "from" pointer within each arc; but Spencer gave up on that idea
      long ago, and it's hard to see what the value is now.  The approach
      turns out to be fairly disastrous in terms of memory consumption,
      though.  In the first place, NFAs built by this engine seem to have
      about 4 arcs per state on average, with a majority having only one
      or two out-arcs.  So pre-allocating 10 out-arcs for each state is
      already cause for a factor of two or more bloat.  Worse, the NFA
      optimization phase moves arcs around with abandon.  In a large NFA,
      some of the states will have hundreds of out-arcs, so towards the
      end of the optimization phase we have a significant number of states
      whose arc pools have room for hundreds of arcs each, even though only
      a few of those arcs are in use.  We have seen real-world regexes in
      which this effect bloats the memory requirement by 25X or even more.
      
      Hence, get rid of the per-state arc pools in favor of a single arc
      pool for the whole NFA, with variable-sized allocation batches
      instead of always asking for 10 at a time.  While we're at it,
      let's batch the allocations of state structs too, to further reduce
      the malloc traffic.
      
      This incidentally allows moveouts() to be optimized in a similar
      way to moveins(): when moving an arc to another state, it's now
      valid to just re-link the same arc struct into a different outchain,
      where before the code invariants required us to make a physically
      new arc and then free the old one.
      
      These changes reduce the regex compiler's typical space consumption
      for average-size regexes by about a factor of two, and much more for
      large or complicated regexes.  In a large test set of real-world
      regexes, we formerly had half a dozen cases that failed with "regular
      expression too complex" due to exceeding the REG_MAX_COMPILE_SPACE
      limit (about 150MB); we would have had to raise that limit to
      something close to 400MB to make them work with the old code.  Now,
      none of those cases need more than 13MB to compile.  Furthermore,
      the test set is about 10% faster overall due to less malloc traffic.
      
      Discussion: https://postgr.es/m/168861.1614298592@sss.pgh.pa.us
      0fc1af17
    • Peter Eisentraut's avatar
      Extend a test case a little · b3a9e989
      Peter Eisentraut authored
      This will possibly help a subsequent patch by making sure the notice
      messages are distinct so that it's clear that they come out in the
      right order.
      
      Author: Fabien COELHO <coelho@cri.ensmp.fr>
      Discussion: https://www.postgresql.org/message-id/alpine.DEB.2.21.1904240654120.3407%40lancre
      b3a9e989
    • Michael Paquier's avatar
      doc: Improve {archive,restore}_command for compressed logs · 329784e1
      Michael Paquier authored
      The commands mentioned in the docs with gzip and gunzip did not prefix
      the archives with ".gz" and used inconsistent paths for the archives,
      which can be confusing.
      
      Reported-by: Philipp Gramzow
      Reviewed-by: Fujii Masao
      Discussion: https://postgr.es/m/161397938841.15451.13129264141285167267@wrigleys.postgresql.org
      329784e1
    • Thomas Munro's avatar
      Revert "pg_collation_actual_version() -> pg_collation_current_version()." · 8556267b
      Thomas Munro authored
      This reverts commit 9cf184cc.  Name
      change less well received than anticipated.
      
      Discussion: https://postgr.es/m/afcfb97e-88a1-a540-db95-6c573b93bc2b%40eisentraut.org
      8556267b
    • Tom Lane's avatar
      Fix list-manipulation bug in WITH RECURSIVE processing. · 80ca8464
      Tom Lane authored
      makeDependencyGraphWalker and checkWellFormedRecursionWalker
      thought they could hold onto a pointer to a list's first
      cons cell while the list was modified by recursive calls.
      That was okay when the cons cell was actually separately
      palloc'd ... but since commit 1cff1b95, it's quite unsafe,
      leading to core dumps or incorrect complaints of faulty
      WITH nesting.
      
      In the field this'd require at least a seven-deep WITH nest
      to cause an issue, but enabling DEBUG_LIST_MEMORY_USAGE
      allows the bug to be seen with lesser nesting depths.
      
      Per bug #16801 from Alexander Lakhin.  Back-patch to v13.
      
      Michael Paquier and Tom Lane
      
      Discussion: https://postgr.es/m/16801-393c7922143eaa4d@postgresql.org
      80ca8464
  6. 25 Feb, 2021 5 commits
    • Peter Geoghegan's avatar
      VACUUM VERBOSE: Count "newly deleted" index pages. · 23763618
      Peter Geoghegan authored
      Teach VACUUM VERBOSE to report on pages deleted by the _current_ VACUUM
      operation -- these are newly deleted pages.  VACUUM VERBOSE continues to
      report on the total number of deleted pages in the entire index (no
      change there).  The former is a subset of the latter.
      
      The distinction between each category of deleted index page only arises
      with index AMs where page deletion is supported and is decoupled from
      page recycling for performance reasons.
      
      This is follow-up work to commit e5d8a999, which made nbtree store
      64-bit XIDs (not 32-bit XIDs) in pages at the point at which they're
      deleted.  Note that the btm_last_cleanup_num_delpages metapage field
      added by that commit usually gets set to pages_newly_deleted.  The
      exceptions (the scenarios in which they're not equal) all seem to be
      tricky cases for the implementation (of page deletion and recycling) in
      general.
      
      Author: Peter Geoghegan <pg@bowt.ie>
      Discussion: https://postgr.es/m/CAH2-WznpdHvujGUwYZ8sihX%3Dd5u-tRYhi-F4wnV2uN2zHpMUXw%40mail.gmail.com
      23763618
    • Tom Lane's avatar
      Doc: remove src/backend/regex/re_syntax.n. · 301ed881
      Tom Lane authored
      We aren't publishing this file as documentation, and it's been
      much more haphazardly maintained than the real docs in func.sgml,
      so let's just drop it.  I think the only reason I included it in
      commit 7bcc6d98 was that the Berkeley-era sources had had a man
      page in this directory.
      
      Discussion: https://postgr.es/m/4099447.1614186542@sss.pgh.pa.us
      301ed881
    • Tom Lane's avatar
      Change regex \D and \W shorthands to always match newlines. · 7dc13a0f
      Tom Lane authored
      Newline is certainly not a digit, nor a word character, so it is
      sensible that it should match these complemented character classes.
      Previously, \D and \W acted that way by default, but in
      newline-sensitive mode ('n' or 'p' flag) they did not match newlines.
      
      This behavior was previously forced because explicit complemented
      character classes don't match newlines in newline-sensitive mode;
      but as of the previous commit that implementation constraint no
      longer exists.  It seems useful to change this because the primary
      real-world use for newline-sensitive mode seems to be to match the
      default behavior of other regex engines such as Perl and Javascript
      ... and their default behavior is that these match newlines.
      
      The old behavior can be kept by writing an explicit complemented
      character class, i.e. [^[:digit:]] or [^[:word:]].  (This means
      that \D and \W are not exactly equivalent to those strings, but
      they weren't anyway.)
      
      Discussion: https://postgr.es/m/3220564.1613859619@sss.pgh.pa.us
      7dc13a0f
    • Tom Lane's avatar
      Allow complemented character class escapes within regex brackets. · 2a0af7fe
      Tom Lane authored
      The complement-class escapes \D, \S, \W are now allowed within
      bracket expressions.  There is no semantic difficulty with doing
      that, but the rather hokey macro-expansion-based implementation
      previously used here couldn't cope.
      
      Also, invent "word" as an allowed character class name, thus "\w"
      is now equivalent to "[[:word:]]" outside brackets, or "[:word:]"
      within brackets.  POSIX allows such implementation-specific
      extensions, and the same name is used in e.g. bash.
      
      One surprising compatibility issue this raises is that constructs
      such as "[\w-_]" are now disallowed, as our documentation has always
      said they should be: character classes can't be endpoints of a range.
      Previously, because \w was just a macro for "[:alnum:]_", such a
      construct was read as "[[:alnum:]_-_]", so it was accepted so long as
      the character after "-" was numerically greater than or equal to "_".
      
      Some implementation cleanup along the way:
      
      * Remove the lexnest() hack, and in consequence clean up wordchrs()
      to not interact with the lexer.
      
      * Fix colorcomplement() to not be O(N^2) in the number of colors
      involved.
      
      * Get rid of useless-as-far-as-I-can-see calls of element()
      on single-character character element names in brackpart().
      element() always maps these to the character itself, and things
      would be quite broken if it didn't --- should "[a]" match something
      different than "a" does?  Besides, the shortcut path in brackpart()
      wasn't doing this anyway, making it even more inconsistent.
      
      Discussion: https://postgr.es/m/2845172.1613674385@sss.pgh.pa.us
      Discussion: https://postgr.es/m/3220564.1613859619@sss.pgh.pa.us
      2a0af7fe
    • Fujii Masao's avatar
      Improve tab-completion for TRUNCATE. · 6b40d9bd
      Fujii Masao authored
      Author: Kota Miyake
      Reviewed-by: Muhammad Usama
      Discussion: https://postgr.es/m/f5d30053d00dcafda3280c9e267ecb0f@oss.nttdata.com
      6b40d9bd