1. 30 Nov, 2016 5 commits
    • Heikki Linnakangas's avatar
      Rewrite the perl scripts to produce our Unicode conversion tables. · 1de9cc0d
      Heikki Linnakangas authored
      Generate EUC_CN mappings from gb-18030-2000.xml, because GB2312.TXT is no
      longer available.
      
      Get UHC from windows-949-2000.xml, it's more up-to-date.
      
      Plus tons more small changes. With these changes, the perl scripts
      faithfully produce the *.map files we have in the repository, from the
      external source files.
      
      In the passing, fix the Makefile to also download CP932.TXT and CP950.TXT.
      
      Based on patches by Kyotaro Horiguchi, reviewed by Daniel Gustafsson.
      
      Discussion: https://postgr.es/m/08e7892a-d55c-eefe-76e6-7910bc8dd1f3@iki.fi
      1de9cc0d
    • Heikki Linnakangas's avatar
      Remove leading zeros, for consistency with other map files. · 6c303223
      Heikki Linnakangas authored
      The common style is to pad to 4 digits.
      
      Running the current perl scripts to generate these map files would override
      this change, but the next commit will rewrite the perl scripts to produce
      this style. I'm doing this as a separate commit, to make it more clear what
      non-cosmetic changes the next commit makes to the map files.
      
      Discussion: https://postgr.es/m/08e7892a-d55c-eefe-76e6-7910bc8dd1f3@iki.fi
      6c303223
    • Heikki Linnakangas's avatar
      Remove code points < 0x80 from character conversion tables. · 2c09c93c
      Heikki Linnakangas authored
      PostgreSQL treats characters with < 0x80 leading byte  as plain ASCII, and
      they are not even passed to the conversion routines. There is no point in
      having them in the conversion tables.
      
      Everything in the tables were direct ASCII-ASCII mappings, except for two:
      * SHIFT_JIS_2004 code point 0x5C (backslash in ASCII) was mapped to Unicode
        YEN SIGN character.
      * Unicode 0x5C (backslash again) was mapped to "REVERSE SOLIDUS" in
        SHIFT_JIS_2004
      
      These mappings never had any effect, so there's no functional change from
      removing them.
      
      Discussion: https://postgr.es/m/08e7892a-d55c-eefe-76e6-7910bc8dd1f3@iki.fi
      2c09c93c
    • Heikki Linnakangas's avatar
      Remove dead stuff from pgcrypto. · b2cc748b
      Heikki Linnakangas authored
      pgp-pubkey-DISABLED test has been unused since 2006, when support for
      built-in bignum math was added (commit 1abf76e8). pgp-encrypt-DISABLED has
      been unused forever, AFAICS.
      
      Also remove a couple of unused error codes.
      b2cc748b
    • Tom Lane's avatar
      Fix bogus handling of JOIN_UNIQUE_OUTER/INNER cases for parallel joins. · 41e2b84c
      Tom Lane authored
      consider_parallel_nestloop passed the wrong jointype down to its
      subroutines for JOIN_UNIQUE_INNER cases (it should pass JOIN_INNER), and it
      thought that it could pass paths other than innerrel->cheapest_total_path
      to create_unique_path, which create_unique_path is not on board with.
      These bugs would lead to assertion failures or other errors, suggesting
      that this code path hasn't been tested much.
      
      hash_inner_and_outer's code for parallel join effectively treated both
      JOIN_UNIQUE_OUTER and JOIN_UNIQUE_INNER the same as JOIN_INNER (for
      different reasons :-(), leading to incorrect plans that treated a semijoin
      as if it were a plain join.
      
      Michael Day submitted a test case demonstrating that hash_inner_and_outer
      failed for JOIN_UNIQUE_OUTER, and I found the other cases through code
      review.
      
      Report: https://postgr.es/m/D0E8A029-D1AC-42E8-979A-5DE4A77E4413@rcmail.com
      41e2b84c
  2. 29 Nov, 2016 10 commits
  3. 28 Nov, 2016 3 commits
    • Alvaro Herrera's avatar
      Fix get_relation_info name typo'ed in a comment · eb681416
      Alvaro Herrera authored
      Plus add a missing comment about this in get_relation_info itself.
      
      Author: Amit Langote
      Discussion: https://postgr.es/m/e46c0569-0449-afa0-e2fe-f3776e4b3fd5@lab.ntt.co.jp
      eb681416
    • Tom Lane's avatar
      Fix busted tab-completion pattern for ALTER TABLE t ALTER c DROP ... · 404e6675
      Tom Lane authored
      Evidently a thinko in commit 9b181b03.
      
      Kyotaro Horiguchi
      404e6675
    • Tom Lane's avatar
      Code review for early drop of orphaned temp relations in autovacuum. · dafa0848
      Tom Lane authored
      Commit a734fd5d exposed some race conditions that existed previously
      in the autovac code, but were basically harmless because autovac would
      not try to delete orphaned relations immediately.  Specifically, the test
      for orphaned-ness was made on a pg_class tuple that might be dead by now,
      allowing autovac to try to remove a table that the owning backend had just
      finished deleting.  This resulted in a hard crash due to inadequate caution
      about accessing the table's catalog entries without any lock.  We must take
      a relation lock and then recheck whether the table is still present and
      still looks deletable before we do anything.
      
      Also, it seemed to me that deleting multiple tables per transaction, and
      trying to continue after errors, represented unjustifiable complexity.
      We do not expect this code path to be taken often in the field, nor even
      during testing, which means that prioritizing performance over correctness
      is a bad tradeoff.  Rip all that out in favor of just starting a new
      transaction after each successful temp table deletion.  If we're unlucky
      enough to get an error, which shouldn't happen anyway now that we're being
      more cautious, let the autovacuum worker fail as it normally would.
      
      In passing, improve the order of operations in the initial scan loop.
      Now that we don't care about whether a temp table is a wraparound hazard,
      there's no need to perform extract_autovac_opts, get_pgstat_tabentry_relid,
      or relation_needs_vacanalyze for temp tables.
      
      Also, if GetTempNamespaceBackendId returns InvalidBackendId (indicating
      it doesn't recognize the schema as temp), treat that as meaning it's NOT
      an orphaned temp table, not that it IS one, which is what happened before
      because BackendIdGetProc necessarily failed.  The case really shouldn't
      come up for a table that has RELPERSISTENCE_TEMP, but the consequences
      if it did seem undesirable.  (This might represent a back-patchable bug
      fix; not sure if it's worth the trouble.)
      
      Discussion: https://postgr.es/m/21299.1480272347@sss.pgh.pa.us
      dafa0848
  4. 27 Nov, 2016 1 commit
  5. 26 Nov, 2016 2 commits
    • Tom Lane's avatar
      Fix test about ignoring extension dependencies during extension scripts. · 182db070
      Tom Lane authored
      Commit 08dd23ce introduced an exception to the rule that extension member
      objects can only be dropped as part of dropping the whole extension,
      intending to allow such drops while running the extension's own creation or
      update scripts.  However, the exception was only applied at the outermost
      recursion level, because it was modeled on a pre-existing check to ignore
      dependencies on objects listed in pendingObjects.  Bug #14434 from Philippe
      Beaudoin shows that this is inadequate: in some cases we can reach an
      extension member object by recursion from another one.  (The bug concerns
      the serial-sequence case; I'm not sure if there are other cases, but there
      might well be.)
      
      To fix, revert 08dd23ce's changes to findDependentObjects() and instead
      apply the creating_extension exception regardless of stack level.
      
      Having seen this example, I'm a bit suspicious that the pendingObjects
      logic is also wrong and such cases should likewise be allowed at any
      recursion level.  However, changing that would interact in subtle ways
      with the recursion logic (at least it would need to be moved to after the
      recursing-from check).  Given that the code's been like that a long time,
      I'll refrain from touching it without a clear example showing it's wrong.
      
      Back-patch to all active branches.  In HEAD and 9.6, where suitable
      test infrastructure exists, add a regression test case based on the
      bug report.
      
      Report: <20161125151448.6529.33039@wrigleys.postgresql.org>
      Discussion: <13224.1480177514@sss.pgh.pa.us>
      182db070
    • Robert Haas's avatar
      Mark IsPostmasterEnvironment and IsBackgroundWorker as PGDLLIMPORT. · 27327059
      Robert Haas authored
      Per request from Craig Ringer.
      27327059
  6. 25 Nov, 2016 4 commits
    • Tom Lane's avatar
      Bring some clarity to the defaults for the xxx_flush_after parameters. · dbdfd114
      Tom Lane authored
      Instead of confusingly stating platform-dependent defaults for these
      parameters in the comments in postgresql.conf.sample (with the main
      entry being a lie on Linux), teach initdb to install the correct
      platform-dependent value in postgresql.conf, similarly to the way
      we handle other platform-dependent defaults.  This won't do anything
      for existing 9.6 installations, but since it's effectively only a
      documentation improvement, that seems OK.
      
      Since this requires initdb to have access to the default values,
      move the #define's for those to pg_config_manual.h; the original
      placement in bufmgr.h is unworkable because that file can't be
      included by frontend programs.
      
      Adjust the default value for wal_writer_flush_after so that it is 1MB
      regardless of XLOG_BLCKSZ, conforming to what is stated in both the
      SGML docs and postgresql.conf.  (We could alternatively make it scale
      with XLOG_BLCKSZ, but I'm not sure I see the point.)
      
      Copy-edit related SGML documentation.
      
      Fabien Coelho and Tom Lane, per a gripe from Tomas Vondra.
      
      Discussion: <30ebc6e3-8358-09cf-44a8-578252938424@2ndquadrant.com>
      dbdfd114
    • Tom Lane's avatar
      Mark a query's topmost Paths parallel-unsafe if they will have initPlans. · ab77a5a4
      Tom Lane authored
      Andreas Seltenreich found another case where we were being too optimistic
      about allowing a plan to be considered parallelizable despite it containing
      initPlans.  It seems like the real issue here is that if we know we are
      going to tack initPlans onto the topmost Plan node for a subquery, we
      had better mark that subquery's result Paths as not-parallel-safe.  That
      fixes this problem and allows reversion of a kluge (added in commit
      7b67a0a4 and extended in f24cf960) to not trust the parallel_safe flag
      at top level.
      
      Discussion: <874m2w4k5d.fsf@ex.ansel.ydns.eu>
      ab77a5a4
    • Tom Lane's avatar
      Check for pending trigger events on far end when dropping an FK constraint. · 4e026b32
      Tom Lane authored
      When dropping a foreign key constraint with ALTER TABLE DROP CONSTRAINT,
      we refuse the drop if there are any pending trigger events on the named
      table; this ensures that we won't remove the pg_trigger row that will be
      consulted by those events.  But we should make the same check for the
      referenced relation, else we might remove a due-to-be-referenced pg_trigger
      row for that relation too, resulting in "could not find trigger NNN" or
      "relation NNN has no triggers" errors at commit.  Per bug #14431 from
      Benjie Gillam.  Back-patch to all supported branches.
      
      Report: <20161124114911.6530.31200@wrigleys.postgresql.org>
      4e026b32
    • Magnus Hagander's avatar
      Fix typo in comment · 8afb8110
      Magnus Hagander authored
      Thomas Munro
      8afb8110
  7. 24 Nov, 2016 2 commits
  8. 23 Nov, 2016 3 commits
    • Tom Lane's avatar
      Avoid masking a function parameter name with a local variable name. · 6fa391be
      Tom Lane authored
      No actual bug here, but it might confuse readers, so change the name
      of the local variable.
      
      Ashutosh Bapat
      6fa391be
    • Tom Lane's avatar
      Make sure ALTER TABLE preserves index tablespaces. · bd673e8e
      Tom Lane authored
      When rebuilding an existing index, ALTER TABLE correctly kept the
      physical file in the same tablespace, but it messed up the pg_class
      entry if the index had been in the database's default tablespace
      and "default_tablespace" was set to some non-default tablespace.
      This led to an inaccessible index.
      
      Fix by fixing pg_get_indexdef_string() to always include a tablespace
      clause, whether or not the index is in the default tablespace.  The
      previous behavior was installed in commit 537e92e4, and I think it just
      wasn't thought through very clearly; certainly the possible effect of
      default_tablespace wasn't considered.  There's some risk in changing the
      behavior of this function, but there are no other call sites in the core
      code.  Even if it's being used by some third party extension, it's fairly
      hard to envision a usage that is okay with a tablespace clause being
      appended some of the time but can't handle it being appended all the time.
      
      Back-patch to all supported versions.
      
      Code fix by me, investigation and test cases by Michael Paquier.
      
      Discussion: <1479294998857-5930602.post@n3.nabble.com>
      bd673e8e
    • Robert Haas's avatar
      Remove barrier.h · e343dfa4
      Robert Haas authored
      A new thing also called a "barrier" is proposed, but whether we decide
      to take that patch or not, this file seems to have outlived its
      usefulness.
      
      Thomas Munro
      e343dfa4
  9. 22 Nov, 2016 7 commits
    • Tom Lane's avatar
      Doc: improve documentation about composite-value usage. · e1320266
      Tom Lane authored
      Create a section specifically for the syntactic rules around whole-row
      variable usage, such as expansion of "foo.*".  This was previously
      documented only haphazardly, with some critical info buried in
      unexpected places like xfunc-sql-composite-functions.  Per repeated
      questions in different mailing lists.
      
      Discussion: <16288.1479610770@sss.pgh.pa.us>
      e1320266
    • Robert Haas's avatar
      Code review for commit 274bb2b3. · 9a1d0af4
      Robert Haas authored
      Avoid memory leak in conninfo_uri_parse_options.  Use the current host
      rather than the comma-separated list of host names when the host name
      is needed for GSS, SSPI, or SSL authentication.  Document the way
      connect_timeout interacts with multiple host specifications.
      
      Takayuki Tsunakawa
      9a1d0af4
    • Tom Lane's avatar
      Improve handling of "UPDATE ... SET (column_list) = row_constructor". · 906bfcad
      Tom Lane authored
      Previously, the right-hand side of a multiple-column assignment, if it
      wasn't a sub-SELECT, had to be a simple parenthesized expression list,
      because gram.y was responsible for "bursting" the construct into
      independent column assignments.  This had the minor defect that you
      couldn't write ROW (though you should be able to, since the standard says
      this is a row constructor), and the rather larger defect that unlike other
      uses of row constructors, we would not expand a "foo.*" item into multiple
      columns.
      
      Fix that by changing the RHS to be just "a_expr" in the grammar, leaving
      it to transformMultiAssignRef to separate the elements of a RowExpr;
      which it will do only after performing standard transformation of the
      RowExpr, so that "foo.*" behaves as expected.
      
      The key reason we didn't do that before was the hard-wired handling of
      DEFAULT tokens (SetToDefault nodes).  This patch deals with that issue by
      allowing DEFAULT in any a_expr and having parse analysis throw an error
      if SetToDefault is found in an unexpected place.  That's an improvement
      anyway since the error can be more specific than just "syntax error".
      
      The SQL standard suggests that the RHS could be any a_expr yielding a
      suitable row value.  This patch doesn't really move the goal posts in that
      respect --- you're still limited to RowExpr or a sub-SELECT --- but it does
      fix the grammar restriction, so it provides some tangible progress towards
      a full implementation.  And the limitation is now documented by an explicit
      error message rather than an unhelpful "syntax error".
      
      Discussion: <8542.1479742008@sss.pgh.pa.us>
      906bfcad
    • Robert Haas's avatar
      Support condition variables. · e8ac886c
      Robert Haas authored
      Condition variables provide a flexible way to sleep until a
      cooperating process causes an arbitrary condition to become true.  In
      simple cases, this can be accomplished with a WaitLatch/ResetLatch
      loop; the cooperating process can call SetLatch after performing work
      that might cause the condition to be satisfied, and the waiting
      process can recheck the condition each time.  However, if the process
      performing the work doesn't have an easy way to identify which
      processes might be waiting, this doesn't work, because it can't
      identify which latches to set.  Condition variables solve that problem
      by internally maintaining a list of waiters; a process that may have
      caused some waiter's condition to be satisfied must "signal" or
      "broadcast" on the condition variable.
      
      Robert Haas and Thomas Munro
      e8ac886c
    • Tom Lane's avatar
      Doc: add a section in Part II concerning RETURNING. · 1c7861e8
      Tom Lane authored
      There are assorted references to RETURNING in Part II, but nothing
      that would qualify as an explanation of the feature, which seems
      like an oversight considering how useful it is.  Add something.
      
      Noted while looking for a place to point a cross-reference to ...
      1c7861e8
    • Tom Lane's avatar
      Make contrib/test_decoding regression tests safe for CZ locale. · e2a0ee69
      Tom Lane authored
      A little COLLATE "C" goes a long way.
      
      Pavel Stehule, per suggestion from Craig Ringer
      
      Discussion: <CAFj8pRA8nJZcozgxN=RMSqMmKuHVOkcGAAKPKdFeiMWGDSUDLA@mail.gmail.com>
      e2a0ee69
    • Tom Lane's avatar
      Fix uninitialized variable. · ae92a9a3
      Tom Lane authored
      Oversight in a734fd5d.
      
      Michael Paquier
      ae92a9a3
  10. 21 Nov, 2016 3 commits
    • Tom Lane's avatar
      Fix PGLC_localeconv() to handle errors better. · a4930e7c
      Tom Lane authored
      The code was intentionally not very careful about leaking strdup'd
      strings in case of an error.  That was forgivable probably, but it
      also failed to notice strdup() failures, which could lead to subsequent
      null-pointer-dereference crashes, since many callers unsurprisingly
      didn't check for null pointers in the struct lconv fields.  An even
      worse problem is that it could throw error while we were setlocale'd
      to a non-C locale, causing unwanted behavior in subsequent libc calls.
      
      Rewrite to ensure that we cannot throw elog(ERROR) until after we've
      restored the previous locale settings, or at least attempted to.
      (I'm sorely tempted to make restore failure be a FATAL error, but
      will refrain for the moment.)  Having done that, it's not much more
      work to ensure that we clean up strdup'd storage on the way out, too.
      
      This code is substantially the same in all supported branches, so
      back-patch all the way.
      
      Michael Paquier and Tom Lane
      
      Discussion: <CAB7nPqRMbGqa_mesopcn4MPyTs34eqtVEK7ELYxvvV=oqS00YA@mail.gmail.com>
      a4930e7c
    • Tom Lane's avatar
      Fix optimization for skipping searches for parallel-query hazards. · 4324ade9
      Tom Lane authored
      Fix thinko in commit da1c9163: even if the original query was free of
      parallel hazards, we might introduce such a hazard by adding PARAM_EXEC
      Param nodes.  Adjust is_parallel_safe() so that it will scan the given
      expression whenever any such nodes have been created.  Per report from
      Andreas Seltenreich.
      
      Discussion: <878tse6yvf.fsf@credativ.de>
      4324ade9
    • Robert Haas's avatar
      autovacuum: Drop orphan temp tables more quickly but with more caution. · a734fd5d
      Robert Haas authored
      Previously, we only dropped an orphan temp table when it became old
      enough to threaten wraparound; instead, doing it immediately.  The
      only value of waiting is that someone might be able to examine the
      contents of the orphan temp table for forensic purposes, but it's
      pretty difficult to actually do that and few users will wish to do so.
      On the flip side, not performing the drop immediately generates log
      spam and bloats pg_class.
      
      In addition, per a report from Grigory Smolkin, if a temporary schema
      contains a very large number of temporary tables, a backend attempting
      to clear the temporary schema might fail due to lock table exhaustion.
      It's helpful for autovacuum to clean up after such cases, and we don't
      want it to wait for wraparound to threaten before doing so.  To
      prevent autovacuum from failing in the same manner as a backend trying
      to drop an entire temp schema, remove orphan temp tables in batches of
      50, committing after each batch, so that we don't accumulate an
      unbounded number of locks.  If a drop fails, retry other orphan tables
      that need to be dropped up to 10 times before giving up.  With this
      system, if a backend does fail to clean a temporary schema due to
      lock table exhaustion, autovacuum should hopefully put things right
      the next time it processes the database.
      
      Discussion: CAB7nPqSbYT6dRwsXVgiKmBdL_ARemfDZMPA+RPeC_ge0GK70hA@mail.gmail.com
      
      Michael Paquier, with a bunch of comment changes by me.
      a734fd5d