1. 25 Jan, 2019 4 commits
    • Tom Lane's avatar
      Fix possibly-uninitialized-variable warning from commit 9556aa01. · 6119060d
      Tom Lane authored
      Heikki's compiler doesn't complain about end_ptr, apparently,
      but mine does.
      
      In passing, I failed to resist the temptation to remove the
      no-longer-used fldnum variable, and relocate chunk_len's
      declaration to a narrower scope.
      6119060d
    • Heikki Linnakangas's avatar
      Use single-byte Boyer-Moore-Horspool search even with multibyte encodings. · 9556aa01
      Heikki Linnakangas authored
      The old implementation first converted the input strings to arrays of
      wchars, and performed the conversion on those. However, the conversion is
      expensive, and for a large input string, consumes a lot of memory.
      Allocating the large arrays also meant that these functions could not be
      used on strings larger 1 GB / pg_encoding_max_length() (256 MB for UTF-8).
      
      Avoid the conversion, and instead use the single-byte algorithm even with
      multibyte encodings. That can get fooled, if there is a matching byte
      sequence in the middle of a multi-byte character, so to eliminate false
      positives like that, we verify any matches by walking the string character
      by character with pg_mblen(). Also, if the caller needs the position of
      the match, as a character-offset, we also need to walk the string to count
      the characters.
      
      Performance testing shows that walking the whole string with pg_mblen() is
      somewhat slower than converting the whole string to wchars. It's still
      often a win, though, because we don't need to do it if there is no match,
      and even when there is, we only need to walk up to the point where the
      match is, not the whole string. Even in the worst case, there would be
      room for optimization: Much of the CPU time in the current loop with
      pg_mblen() is function call overhead, and could be improved by inlining
      pg_mblen() and/or the encoding-specific mblen() functions. But I didn't
      attempt to do that as part of this patch.
      
      Most of the callers of text_position_setup/next functions were actually
      not interested in the position of the match, counted in characters. To
      cater for them, refactor the text_position_next() interface into two
      parts: searching for the next match (text_position_next()), and returning
      the current match's position as a pointer (text_position_get_match_ptr())
      or as a character offset (text_position_get_match_pos()). Getting the
      pointer to the match is a more convenient API for many callers, and with
      UTF-8, it allows skipping the character-walking step altogether, because
      UTF-8 can't have false matches even when treated like raw byte strings.
      
      Reviewed-by: John Naylor
      Discussion: https://www.postgresql.org/message-id/3173d989-bc1c-fc8a-3b69-f24246f73876%40iki.fi
      9556aa01
    • Heikki Linnakangas's avatar
      Fix comments that claimed that mblen() only looks at first byte. · a5be6e9a
      Heikki Linnakangas authored
      GB18030's mblen() function looks at the first and the second byte of the
      multibyte character, to determine its length. copy.c had made the
      assumption that mblen() only looks at the first byte, but it turns out to
      work out fine, because of the way the GB18030 encoding works. COPY will
      see a 4-byte encoded character as two 2-byte encoded characters, which is
      enough for COPY's purposes. It cannot mix those up with delimiter or
      escaping characters, because only single-byte ASCII characters are
      supported as delimiters or escape characters.
      
      Discussion: https://www.postgresql.org/message-id/7704d099-9643-2a55-fb0e-becd64400dcb%40iki.fi
      a5be6e9a
    • Peter Eisentraut's avatar
      Allow generalized expression syntax for partition bounds · 7c079d74
      Peter Eisentraut authored
      Previously, only literals were allowed.  This change allows general
      expressions, including functions calls, which are evaluated at the
      time the DDL command is executed.
      
      Besides offering some more functionality, it simplifies the parser
      structures and removes some inconsistencies in how the literals were
      handled.
      
      Author: Kyotaro Horiguchi, Tom Lane, Amit Langote
      Reviewed-by: default avatarPeter Eisentraut <peter.eisentraut@2ndquadrant.com>
      Discussion: https://www.postgresql.org/message-id/flat/9f88b5e0-6da2-5227-20d0-0d7012beaa1c@lab.ntt.co.jp/
      7c079d74
  2. 24 Jan, 2019 10 commits
    • Tom Lane's avatar
      Remove _configthreadlocale() calls in ecpg test suite. · e3565fd6
      Tom Lane authored
      This essentially reverts commits a772624b and 04fbe0e4, which
      added "_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)" calls to the
      thread-related ecpg test programs.  That was nothing but a hack,
      because we shouldn't expect that ecpg-using applications have
      done that for us; and now that we've inserted such calls into
      ecpglib, the tests should still pass without it.
      
      (If they don't, it would be good to know that.)
      
      HEAD only; there seems no big need to change this in the
      back branches.
      
      Discussion: https://postgr.es/m/22937.1548307384@sss.pgh.pa.us
      e3565fd6
    • Tom Lane's avatar
      Remove infinite-loop hazards in ecpg test suite. · d5a1fde3
      Tom Lane authored
      A report from Andrew Dunstan showed that an ecpglib breakage that
      causes repeated query failures could lead to infinite loops in some
      ecpg test scripts, because they contain "while(1)" loops with no
      exit condition other than successful test completion.  That might
      be all right for manual testing, but it seems entirely unacceptable
      for automated test environments such as our buildfarm.  We don't
      want buildfarm owners to have to intervene manually when a test
      goes wrong.
      
      To fix, just change all those while(1) loops to exit after at most
      100 iterations (which is more than any of them expect to iterate).
      This seems sufficient since we'd see discrepancies in the test output
      if any loop executed the wrong number of times.
      
      I tested this by dint of intentionally breaking ecpg_do_prologue
      to always fail, and verifying that the tests still got to completion.
      
      Back-patch to all supported branches, since the whole point of this
      exercise is to protect the buildfarm against future mistakes.
      
      Discussion: https://postgr.es/m/18693.1548302004@sss.pgh.pa.us
      d5a1fde3
    • Peter Eisentraut's avatar
      PL/pgSQL: Add statement ID to statement structures · bbd5c207
      Peter Eisentraut authored
      This can be used by a profiler as the index for an array of
      per-statement metrics.
      
      Author: Pavel Stehule <pavel.stehule@gmail.com>
      Reviewed-by: default avatarPeter Eisentraut <peter.eisentraut@2ndquadrant.com>
      Discussion: https://www.postgresql.org/message-id/flat/CAFj8pRDRCjN6rpM9ZccU7Ta_afsNX7mg9=n34F+r445Nt9v2tA@mail.gmail.com/
      bbd5c207
    • Peter Eisentraut's avatar
      Fix whitespace · bf2fb2e0
      Peter Eisentraut authored
      bf2fb2e0
    • Alvaro Herrera's avatar
      Fix droppability of constraints upon partition detach · efd9366d
      Alvaro Herrera authored
      We were failing to set conislocal correctly for constraints in
      partitions after partition detach, leading to those constraints becoming
      undroppable.  Fix by setting the flag correctly.  Existing databases
      might contain constraints with the conislocal wrongly set to false, for
      partitions that were detached; this situation should be fixable by
      applying an UPDATE on pg_constraint to set conislocal true.  This
      problem should otherwise be innocuous and should disappear across a
      dump/restore or pg_upgrade.
      
      Secondarily, when constraint drop was attempted in a partitioned table,
      ATExecDropConstraint would try to recurse to partitions after doing
      performDeletion() of the constraint in the partitioned table itself; but
      since the constraint in the partitions are dropped by the initial call
      of performDeletion() (because of following dependencies), the recursion
      step would fail since it would not find the constraint, causing the
      whole operation to fail.  Fix by preventing recursion.
      
      Reported-by: Amit Langote
      Diagnosed-by: Amit Langote
      Author: Amit Langote, Álvaro Herrera
      Discussion: https://postgr.es/m/f2b8ead5-4131-d5a8-8016-2ea0a31250af@lab.ntt.co.jp
      efd9366d
    • Tom Lane's avatar
      Fix portability problem in pgbench. · e6c3ba7f
      Tom Lane authored
      The pgbench regression test supposed that srandom() with a specific value
      would result in deterministic output from random(), as required by POSIX.
      It emerges however that OpenBSD is too smart to be constrained by mere
      standards, so their random() emits nondeterministic output anyway.
      While a workaround does exist, what seems like a better fix is to stop
      relying on the platform's srandom()/random() altogether, so that what
      you get from --random-seed=N is not merely deterministic but platform
      independent.  Hence, use a separate pg_jrand48() random sequence in
      place of random().
      
      Also adjust the regression test case that's supposed to detect
      nondeterminism so that it's more likely to detect it; the original
      choice of random_zipfian parameter tended to produce the same output
      all the time even if the underlying behavior wasn't deterministic.
      
      In passing, improve pgbench's docs about random_zipfian().
      
      Back-patch to v11 where this code was introduced.
      
      Fabien Coelho and Tom Lane
      
      Discussion: https://postgr.es/m/4615.1547792324@sss.pgh.pa.us
      e6c3ba7f
    • Alvaro Herrera's avatar
      Simplify coding to detach constraints when detaching partition · 19184fcc
      Alvaro Herrera authored
      The original coding was too baroque and led to an use-after-release
      mistake, noticed by buildfarm member prion.
      
      Discussion: https://postgr.es/m/21693.1548305934@sss.pgh.pa.us
      19184fcc
    • Etsuro Fujita's avatar
      postgres_fdw: Account for tlist eval costs in estimate_path_cost_size(). · fd1afdba
      Etsuro Fujita authored
      Previously, estimate_path_cost_size() didn't account for tlist eval
      costs, except when costing a foreign-grouping path using local
      statistics, but such costs should be accounted for when costing that path
      using remote estimates, because some of the tlist expressions might be
      evaluated locally.  Also, such costs should be accounted for in the case
      of a foreign-scan or foreign-join path, because the tlist might contain
      PlaceHolderVars, which postgres_fdw currently evaluates locally.
      
      This also fixes an oversight in my commit f8f6e446.
      
      Like that commit, apply this to HEAD only to avoid destabilizing existing
      plan choices.
      
      Author: Etsuro Fujita
      Discussion: https://postgr.es/m/5BFD3EAD.2060301%40lab.ntt.co.jp
      fd1afdba
    • Tom Lane's avatar
      Blind attempt to fix _configthreadlocale() failures on MinGW. · 2cf91ccb
      Tom Lane authored
      Apparently, some builds of MinGW contain a version of
      _configthreadlocale() that always returns -1, indicating failure.
      Rather than treating that as a curl-up-and-die condition, soldier on
      as though the function didn't exist.  This leaves us without thread
      safety on such MinGW versions, but we didn't have it anyway.
      
      Discussion: https://postgr.es/m/d06a16bc-52d6-9f0d-2379-21242d7dbe81@2ndQuadrant.com
      2cf91ccb
    • Alvaro Herrera's avatar
      Detach constraints when partitions are detached · ae366aa5
      Alvaro Herrera authored
      I (Álvaro) forgot to do this in eb7ed3f3, leading to undroppable
      constraints after partitions are detached.  Repair.
      
      Reported-by: Amit Langote
      Author: Amit Langote
      Discussion: https://postgr.es/m/c1c9b688-b886-84f7-4048-1e4ebe9b1d06@lab.ntt.co.jp
      ae366aa5
  3. 23 Jan, 2019 5 commits
  4. 22 Jan, 2019 8 commits
  5. 21 Jan, 2019 13 commits