1. 01 Aug, 2016 5 commits
    • Tom Lane's avatar
      Don't CHECK_FOR_INTERRUPTS between WaitLatch and ResetLatch. · 887feefe
      Tom Lane authored
      This coding pattern creates a race condition, because if an interesting
      interrupt happens after we've checked InterruptPending but before we reset
      our latch, the latch-setting done by the signal handler would get lost,
      and then we might block at WaitLatch in the next iteration without ever
      noticing the interrupt condition.  You can put the CHECK_FOR_INTERRUPTS
      before WaitLatch or after ResetLatch, but not between them.
      
      Aside from fixing the bugs, add some explanatory comments to latch.h
      to perhaps forestall the next person from making the same mistake.
      
      In HEAD, also replace gather_readnext's direct call of
      HandleParallelMessages with CHECK_FOR_INTERRUPTS.  It does not seem clean
      or useful for this one caller to bypass ProcessInterrupts and go straight
      to HandleParallelMessages; not least because that fails to consider the
      InterruptPending flag, resulting in useless work both here
      (if InterruptPending isn't set) and in the next CHECK_FOR_INTERRUPTS call
      (if it is).
      
      This thinko seems to have been introduced in the initial coding of
      storage/ipc/shm_mq.c (commit ec9037df), and then blindly copied into all
      the subsequent parallel-query support logic.  Back-patch relevant hunks
      to 9.4 to extirpate the error everywhere.
      
      Discussion: <1661.1469996911@sss.pgh.pa.us>
      887feefe
    • Fujii Masao's avatar
      Remove unused arguments from pg_replication_origin_xact_reset function. · dd5eb805
      Fujii Masao authored
      The document specifies that pg_replication_origin_xact_reset function
      doesn't have any argument variables. But previously it was actually
      defined so as to have two argument variables, though they were not
      used at all. That is, the pg_proc entry for that function was incorrect.
      This patch fixes the pg_proc entry and removes those two arguments
      from the function definition.
      
      No back-patch because this change needs a catalog version bump
      although the issue exists in 9.5 as well. Instead, a note about those
      unused argument variables will be added to 9.5 document later.
      
      Catalog version bumped due to the change of pg_proc.
      dd5eb805
    • Bruce Momjian's avatar
      878bd9ac
    • Michael Meskes's avatar
    • Fujii Masao's avatar
      Fix pg_basebackup so that it accepts 0 as a valid compression level. · 74d8c95b
      Fujii Masao authored
      The help message for pg_basebackup specifies that the numbers 0 through 9
      are accepted as valid values of -Z option. But, previously -Z 0 was rejected
      as an invalid compression level.
      
      Per discussion, it's better to make pg_basebackup treat 0 as valid
      compression level meaning no compression, like pg_dump.
      
      Back-patch to all supported versions.
      
      Reported-By: Jeff Janes
      Reviewed-By: Amit Kapila
      Discussion: CAMkU=1x+GwjSayc57v6w87ij6iRGFWt=hVfM0B64b1_bPVKRqg@mail.gmail.com
      74d8c95b
  2. 31 Jul, 2016 4 commits
    • Tom Lane's avatar
      Doc: remove claim that hash index creation depends on effective_cache_size. · 11653cd8
      Tom Lane authored
      This text was added by commit ff213239, and not long thereafter obsoleted
      by commit 4adc2f72 (which made the test depend on NBuffers instead); but
      nobody noticed the need for an update.  Commit 9563d5b5 adds some further
      dependency on maintenance_work_mem, but the existing verbiage seems to
      cover that with about as much precision as we really want here.  Let's
      just take it all out rather than leaving ourselves open to more errors of
      omission in future.  (That solution makes this change back-patchable, too.)
      
      Noted by Peter Geoghegan.
      
      Discussion: <CAM3SWZRVANbj9GA9j40fAwheQCZQtSwqTN1GBTVwRrRbmSf7cg@mail.gmail.com>
      11653cd8
    • Tom Lane's avatar
      Code review for tqueue.c: fix memory leaks, speed it up, other fixes. · a9ed875f
      Tom Lane authored
      When doing record typmod remapping, tqueue.c did fresh catalog lookups
      for each tuple it processed, which was pretty horrible performance-wise
      (it seemed to about halve the already none-too-quick speed of bulk reads
      in parallel mode).  Worse, it insisted on putting bits of that data into
      TopMemoryContext, from where it never freed them, causing a
      session-lifespan memory leak.  (I suppose this was coded with the idea
      that the sender process would quit after finishing the query ---
      but the receiver uses the same code.)
      
      Restructure to avoid repetitive catalog lookups and to keep that data
      in a query-lifespan context, in or below the context where the
      TQueueDestReceiver or TupleQueueReader itself lives.
      
      Fix some other bugs such as continuing to use a tupledesc after
      releasing our refcount on it.  Clean up cavalier datatype choices
      (typmods are int32, please, not int, and certainly not Oid).  Improve
      comments and error message wording.
      a9ed875f
    • Stephen Frost's avatar
      Correctly handle owned sequences with extensions · f9e439b1
      Stephen Frost authored
      With the refactoring of pg_dump to handle components, getOwnedSeqs needs
      to be a bit more intelligent regarding which components to dump when.
      Specifically, we can't simply use the owning table's components as the
      set of components to dump as the table might only be including certain
      components while all components of the sequence should be dumped, for
      example, when the table is a member of an extension while the sequence
      is not.
      
      Handle this by combining the set of components to be dumped for the
      sequence explicitly and those to be dumped for the table when setting
      the components to be dumped for the sequence.
      
      Also add a number of regression tests around this to, hopefully, catch
      any future changes which break the expected behavior.
      
      Discovered by: Philippe BEAUDOIN
      Reviewed by: Michael Paquier
      f9e439b1
    • Bruce Momjian's avatar
      doc: improve wording of Error Message Style Guide · 6335c80e
      Bruce Momjian authored
      Reported-by: Daniel Gustafsson
      
      Discussion: 48DB4EDA-96F8-4B2F-99C4-110900FC7540@yesql.se
      
      Author: Daniel Gustafsson
      6335c80e
  3. 30 Jul, 2016 2 commits
  4. 29 Jul, 2016 5 commits
    • Tom Lane's avatar
      Fix worst memory leaks in tqueue.c. · af330393
      Tom Lane authored
      TupleQueueReaderNext() leaks like a sieve if it has to do any tuple
      disassembly/reconstruction.  While we could try to clean up its allocations
      piecemeal, it seems like a better idea just to insist that it should be run
      in a short-lived memory context, so that any transient space goes away
      automatically.  I chose to have nodeGather.c switch into its existing
      per-tuple context before the call, rather than inventing a separate
      context inside tqueue.c.
      
      This is sufficient to stop all leakage in the simple case I exhibited
      earlier today (see link below), but it does not deal with leaks induced
      in more complex cases by tqueue.c's insistence on using TopMemoryContext
      for data that it's not actually trying hard to keep track of.  That issue
      is intertwined with another major source of inefficiency, namely failure
      to cache lookup results across calls, so it seems best to deal with it
      separately.
      
      In passing, improve some comments, and modify gather_readnext's method for
      deciding when it's visited all the readers so that it's more obviously
      correct.  (I'm not actually convinced that the previous code *is*
      correct in the case of a reader deletion; it certainly seems fragile.)
      
      Discussion: <32763.1469821037@sss.pgh.pa.us>
      af330393
    • Tom Lane's avatar
      Fix tqueue.c's range-remapping code. · bf4ae685
      Tom Lane authored
      It's depressingly clear that nobody ever tested this.
      bf4ae685
    • Tom Lane's avatar
      Fix pq_putmessage_noblock() to not block. · 80b346c2
      Tom Lane authored
      An evident copy-and-pasteo in commit 2bd9e412 broke the non-blocking
      aspect of pq_putmessage_noblock(), causing it to behave identically to
      pq_putmessage().  That function is nowadays used only in walsender.c,
      so that the net effect was to cause walsenders to hang up waiting for
      the receiver in situations where they should not.
      
      Kyotaro Horiguchi
      
      Patch: <20160728.185228.58375982.horiguchi.kyotaro@lab.ntt.co.jp>
      80b346c2
    • Robert Haas's avatar
      Eliminate a few more user-visible "cache lookup failed" errors. · 3153b1a5
      Robert Haas authored
      Michael Paquier
      3153b1a5
    • Peter Eisentraut's avatar
      5676da2d
  5. 28 Jul, 2016 8 commits
    • Tom Lane's avatar
      Guard against empty buffer in gets_fromFile()'s check for a newline. · ed0b228d
      Tom Lane authored
      Per the fgets() specification, it cannot return without reading some data
      unless it reports EOF or error.  So the code here assumed that the data
      buffer would necessarily be nonempty when we go to check for a newline
      having been read.  However, Agostino Sarubbo noticed that this could fail
      to be true if the first byte of the data is a NUL (\0).  The fgets() API
      doesn't really work for embedded NULs, which is something I don't feel
      any great need for us to worry about since we generally don't allow NULs
      in SQL strings anyway.  But we should not access off the end of our own
      buffer if the case occurs.  Normally this would just be a harmless read,
      but if you were unlucky the byte before the buffer would contain '\n'
      and we'd overwrite it with '\0', and if you were really unlucky that
      might be valuable data and psql would crash.
      
      Agostino reported this to pgsql-security, but after discussion we concluded
      that it isn't worth treating as a security bug; if you can control the
      input to psql you can do far more interesting things than just maybe-crash
      it.  Nonetheless, it is a bug, so back-patch to all supported versions.
      ed0b228d
    • Tom Lane's avatar
      Teach parser to transform "x IS [NOT] DISTINCT FROM NULL" to a NullTest. · 8d19d0e1
      Tom Lane authored
      Now that we've nailed down the principle that NullTest with !argisrow
      is fully equivalent to SQL's IS [NOT] DISTINCT FROM NULL, let's teach
      the parser about it.  This produces a slightly more compact parse tree
      and is much more amenable to optimization than a DistinctExpr, since
      the planner knows a good deal about NullTest and next to nothing about
      DistinctExpr.
      
      I'm not sure that there are all that many queries in the wild that could
      be improved by this, but at least one source of such cases is the patch
      just made to postgres_fdw to emit IS [NOT] DISTINCT FROM NULL when
      IS [NOT] NULL isn't semantically correct.
      
      No back-patch, since to the extent that this does affect planning results,
      it might be considered undesirable plan destabilization.
      8d19d0e1
    • Peter Eisentraut's avatar
      Message style improvements · ef5d4a3c
      Peter Eisentraut authored
      ef5d4a3c
    • Tom Lane's avatar
      Fix assorted fallout from IS [NOT] NULL patch. · 9492cf86
      Tom Lane authored
      Commits 4452000f et al established semantics for NullTest.argisrow that
      are a bit different from its initial conception: rather than being merely
      a cache of whether we've determined the input to have composite type,
      the flag now has the further meaning that we should apply field-by-field
      testing as per the standard's definition of IS [NOT] NULL.  If argisrow
      is false and yet the input has composite type, the construct instead has
      the semantics of IS [NOT] DISTINCT FROM NULL.  Update the comments in
      primnodes.h to clarify this, and fix ruleutils.c and deparse.c to print
      such cases correctly.  In the case of ruleutils.c, this merely results in
      cosmetic changes in EXPLAIN output, since the case can't currently arise
      in stored rules.  However, it represents a live bug for deparse.c, which
      would formerly have sent a remote query that had semantics different
      from the local behavior.  (From the user's standpoint, this means that
      testing a remote nested-composite column for null-ness could have had
      unexpected recursive behavior much like that fixed in 4452000f.)
      
      In a related but somewhat independent fix, make plancat.c set argisrow
      to false in all NullTest expressions constructed to represent "attnotnull"
      constructs.  Since attnotnull is actually enforced as a simple null-value
      check, this is a more accurate representation of the semantics; we were
      previously overpromising what it meant for composite columns, which might
      possibly lead to incorrect planner optimizations.  (It seems that what the
      SQL spec expects a NOT NULL constraint to mean is an IS NOT NULL test, so
      arguably we are violating the spec and should fix attnotnull to do the
      other thing.  If we ever do, this part should get reverted.)
      
      Back-patch, same as the previous commit.
      
      Discussion: <10682.1469566308@sss.pgh.pa.us>
      9492cf86
    • Tom Lane's avatar
      Improve documentation about CREATE TABLE ... LIKE. · 46b773d4
      Tom Lane authored
      The docs failed to explain that LIKE INCLUDING INDEXES would not preserve
      the names of indexes and associated constraints.  Also, it wasn't mentioned
      that EXCLUDE constraints would be copied by this option.  The latter
      oversight seems enough of a documentation bug to justify back-patching.
      
      In passing, do some minor copy-editing in the same area, and add an entry
      for LIKE under "Compatibility", since it's not exactly a faithful
      implementation of the standard's feature.
      
      Discussion: <20160728151154.AABE64016B@smtp.hushmail.com>
      46b773d4
    • Tom Lane's avatar
      Register atexit hook only once in pg_upgrade. · d9e74959
      Tom Lane authored
      start_postmaster() registered stop_postmaster_atexit as an atexit(3)
      callback each time through, although the obvious intention was to do
      so only once per program run.  The extra registrations were harmless,
      so long as we didn't exceed ATEXIT_MAX, but still it's a bug.
      
      Artur Zakirov, with bikeshedding by Kyotaro Horiguchi and me
      
      Discussion: <d279e817-02b5-caa6-215f-cfb05dce109a@postgrespro.ru>
      d9e74959
    • Fujii Masao's avatar
      Fix incorrect description of udt_privileges view in documentation. · de8c92e6
      Fujii Masao authored
      The description of udt_privileges view contained an incorrect copy-pasted word.
      
      Back-patch to 9.2 where udt_privileges view was added.
      
      Author: Alexander Law
      de8c92e6
    • Tom Lane's avatar
      tqueue.c's record-typmod hashtables need the HASH_BLOBS option. · e1a93dd6
      Tom Lane authored
      The keys are integers, not strings.  The code accidentally worked on
      little-endian machines, at least up to 256 distinct record types within
      a session, but failed utterly on big-endian.  This was unexpectedly
      exposed by a test case added by commit 4452000f, which apparently is the
      only parallelizable query in the regression suite that uses more than one
      anonymous record type.  Fortunately, buildfarm member mandrill is
      big-endian and is running with force_parallel_mode on, so it failed.
      e1a93dd6
  6. 27 Jul, 2016 3 commits
    • Tom Lane's avatar
      Fix cost_rescan() to account for multi-batch hashing correctly. · 69995c3b
      Tom Lane authored
      cost_rescan assumed that we don't need to rebuild the hash table when
      rescanning a hash join.  However, that's currently only true for
      single-batch joins; for a multi-batch join we must charge full freight.
      
      This probably has escaped notice because we'd be unlikely to put a hash
      join on the inside of a nestloop anyway.  Nonetheless, it's wrong.
      Fix in HEAD, but don't backpatch for fear of destabilizing plans in
      stable releases.
      69995c3b
    • Robert Haas's avatar
      Fix thinko in copyParamList. · b31875b1
      Robert Haas authored
      There's no point in consulting retval->paramMask; it's always NULL.
      Instead, we should consult from->paramMask.
      
      Reported by Andrew Gierth.
      b31875b1
    • Tom Lane's avatar
      Allow functions that return sets of tuples to return simple NULLs. · d8411a6c
      Tom Lane authored
      ExecMakeTableFunctionResult(), which is used in SELECT FROM function(...)
      cases, formerly treated a simple NULL output from a function that both
      returnsSet and returnsTuple as a violation of the SRF protocol.  What seems
      better is to treat a NULL output as equivalent to ROW(NULL,NULL,...).
      Without this, cases such as SELECT FROM unnest(...) on an array of
      composite are vulnerable to unexpected and not-very-helpful failures.
      Old code comments here suggested an alternative of just ignoring
      simple-NULL outputs, but that doesn't seem very principled.
      
      This change had been hung up for a long time due to uncertainty about
      how much we wanted to buy into the equivalence of simple NULL and
      ROW(NULL,NULL,...).  I think that's been mostly resolved by the discussion
      around bug #14235, so let's go ahead and do it.
      
      Per bug #7808 from Joe Van Dyk.  Although this is a pretty old report,
      fixing it smells a bit more like a new feature than a bug fix, and the
      lack of other similar complaints suggests that we shouldn't take much risk
      of destabilization by back-patching.  (Maybe that could be revisited once
      this patch has withstood some field usage.)
      
      Andrew Gierth and Tom Lane
      
      Report: <E1TurJE-0006Es-TK@wrigleys.postgresql.org>
      d8411a6c
  7. 26 Jul, 2016 6 commits
    • Robert Haas's avatar
      Change various deparsing functions to return NULL for invalid input. · 976b24fb
      Robert Haas authored
      Previously, some functions returned various fixed strings and others
      failed with a cache lookup error.  Per discussion, standardize on
      returning NULL.  Although user-exposed "cache lookup failed" error
      messages might normally qualify for bug-fix treatment, no back-patch;
      the risk of breaking user code which is accustomed to the current
      behavior seems too high.
      
      Michael Paquier
      976b24fb
    • Robert Haas's avatar
      Repair damage done by citext--1.1--1.2.sql. · fe5e3fce
      Robert Haas authored
      That script is incorrect in that it sets the combine function for
      max(citext) twice instead of setting the combine function for
      max(citext) once and the combine functon for min(citext) once.  The
      consequence is that if you install 1.0 or 1.1 and then update to 1.2,
      you end up with min(citext) not having a combine function, contrary to
      what was intended.  If you install 1.2 directly, you're OK.
      
      Fix things up by defining a new 1.3 version.  Upgrading from 1.2 to
      1.3 won't change anything for people who first installed the 1.2
      version, but people upgrading from 1.0 or 1.1 will get the right
      catalog contents once they reach 1.3.
      
      Report and patch by David Rowley, reviewed by Andreas Karlsson.
      fe5e3fce
    • Tom Lane's avatar
      Fix constant-folding of ROW(...) IS [NOT] NULL with composite fields. · 4452000f
      Tom Lane authored
      The SQL standard appears to specify that IS [NOT] NULL's tests of field
      nullness are non-recursive, ie, we shouldn't consider that a composite
      field with value ROW(NULL,NULL) is null for this purpose.
      ExecEvalNullTest got this right, but eval_const_expressions did not,
      leading to weird inconsistencies depending on whether the expression
      was such that the planner could apply constant folding.
      
      Also, adjust the docs to mention that IS [NOT] DISTINCT FROM NULL can be
      used as a substitute test if a simple null check is wanted for a rowtype
      argument.  That motivated reordering things so that IS [NOT] DISTINCT FROM
      is described before IS [NOT] NULL.  In HEAD, I went a bit further and added
      a table showing all the comparison-related predicates.
      
      Per bug #14235.  Back-patch to all supported branches, since it's certainly
      undesirable that constant-folding should change the semantics.
      
      Report and patch by Andrew Gierth; assorted wordsmithing and revised
      regression test cases by me.
      
      Report: <20160708024746.1410.57282@wrigleys.postgresql.org>
      4452000f
    • Fujii Masao's avatar
      Fix improper example of using psql() function in TAP tests documentation. · c1a95425
      Fujii Masao authored
      In an example of TAP test scripts, there is the test checking whether
      the result of the query is expected or not. But, in previous example,
      the exit code of psql instead of the query result was checked unexpectedly.
      
      Author: Ildar Musin
      c1a95425
    • Peter Eisentraut's avatar
      Fix typo · 43c2c404
      Peter Eisentraut authored
      43c2c404
    • Peter Eisentraut's avatar
      Message style improvements · 40fcfec8
      Peter Eisentraut authored
      40fcfec8
  8. 25 Jul, 2016 2 commits
    • Fujii Masao's avatar
      Fix typo in comment. · 1804d155
      Fujii Masao authored
      Author: Masahiko Sawada
      1804d155
    • Alvaro Herrera's avatar
      Give recovery tests more time to finish · 2a0f89cd
      Alvaro Herrera authored
      These tests are currently only running in buildfarm member hamster,
      which is purposefully very slow.  This suite has failed a couple of
      times recently because of timeouts, so increase the allowed number of
      iterations to avoid spurious failures.
      
      Author: Michaël Paquier
      2a0f89cd
  9. 24 Jul, 2016 2 commits
    • Noah Misch's avatar
      Make the AIX case of Makefile.shlib safe for parallel make. · e8564ef0
      Noah Misch authored
      Use our typical approach, from src/backend/parser.  Back-patch to 9.1
      (all supported versions).
      e8564ef0
    • Tom Lane's avatar
      Correctly set up aggregate FILTER expression in partial-aggregation plans. · 6d85bb1b
      Tom Lane authored
      The aggfilter expression should be removed from the parent (combining)
      Aggref, since it's not supposed to apply the filter, and indeed cannot
      because any Vars used in the filter would not be available after the
      lower-level aggregation step.  Per report from Jeff Janes.
      
      (This has been broken since the introduction of partial aggregation,
      I think.  The error became obvious after commit 59a3795c, when setrefs.c
      began processing the parent Aggref's fields normally and thus would detect
      such Vars.  The special-case coding previously used in setrefs.c skipped
      over the parent's aggfilter field without processing it.  That was broken
      in its own way because no other setrefs.c processing got applied either;
      though since the executor would not execute the filter expression, only
      initialize it, that oversight might not have had any visible symptoms at
      present.)
      
      Report: <CAMkU=1xfuPf2edAe4ZGXTmJpU7jxuKukKyvNtEXwu35B7dvejg@mail.gmail.com>
      6d85bb1b
  10. 22 Jul, 2016 2 commits
    • Tom Lane's avatar
      Fix regression tests to work in Welsh locale. · 9d7abca9
      Tom Lane authored
      Welsh (cy_GB) apparently sorts 'dd' after 'f', creating problems
      analogous to the odd sorting of 'aa' in Danish.  Adjust regression
      test case to not use data that provokes that.
      
      Jeff Janes
      
      Patch: <CAMkU=1zx-pqcfSApL2pYDQurPOCfcYU0wJorsmY1OrYPiXRbLw@mail.gmail.com>
      9d7abca9
    • Tom Lane's avatar
      Remove GetUserMappingId() and GetUserMappingById(). · 13bf801a
      Tom Lane authored
      These functions were added in commits fbe5a3fb and a104a017,
      but commit 45639a05 removed their only callers.  Put the related
      code in foreign.c back to the way it was in 9.5, to avoid pointless
      cross-version diffs.
      
      Etsuro Fujita
      
      Patch: <d674a3f1-6b63-519c-ef3f-f3188ed6a178@lab.ntt.co.jp>
      13bf801a
  11. 21 Jul, 2016 1 commit
    • Tom Lane's avatar
      Make contrib regression tests safe for Danish locale. · d70d1191
      Tom Lane authored
      In btree_gin and citext, avoid some not-particularly-interesting
      dependencies on the sorting of 'aa'.  In tsearch2, use COLLATE "C" to
      remove an uninteresting dependency on locale sort order (and thereby
      allow removal of a variant expected-file).
      
      Also, in citext, avoid assuming that lower('I') = 'i'.  This isn't relevant
      to Danish but it does fail in Turkish.
      d70d1191