Skip to content
Snippets Groups Projects
  1. Nov 12, 2013
  2. Nov 11, 2013
    • Tom Lane's avatar
      Fix failure with whole-row reference to a subquery. · 449d5acd
      Tom Lane authored
      Simple oversight in commit 1cb108ef ---
      recursively examining a subquery output column is only sane if the
      original Var refers to a single output column.  Found by Kevin Grittner.
      449d5acd
    • Magnus Hagander's avatar
      Don't abort pg_basebackup when receiving empty WAL block · c6ec8793
      Magnus Hagander authored
      This can happen exactly at the switch of a logical WAL file
      (segment number ending in FE), when running pg_basebackup connected
      to a standby server, and would cause the backup to abort with
      the error message "streaming header too small".
      
      There is nothing wrong with an empty message, it's just unnecessary,
      and the rest of the code can handle the case of an empty message,
      so this patch just removes the error condition when the size is
      exactly zero.
      c6ec8793
  3. Nov 08, 2013
    • Heikki Linnakangas's avatar
      Fix race condition in GIN posting tree page deletion. · 9a45a655
      Heikki Linnakangas authored
      If a page is deleted, and reused for something else, just as a search is
      following a rightlink to it from its left sibling, the search would continue
      scanning whatever the new contents of the page are. That could lead to
      incorrect query results, or even something more curious if the page is
      reused for a different kind of a page.
      
      To fix, modify the search algorithm to lock the next page before releasing
      the previous one, and refrain from deleting pages from the leftmost branch
      of the tree.
      
      Add a new Concurrency section to the README, explaining why this works.
      There is a lot more one could say about concurrency in GIN, but that's for
      another patch.
      
      Backpatch to all supported versions.
      9a45a655
    • Tom Lane's avatar
      Make contain_volatile_functions/contain_mutable_functions look into SubLinks. · f7171c7e
      Tom Lane authored
      This change prevents us from doing inappropriate subquery flattening in
      cases such as dangerous functions hidden inside a sub-SELECT in the
      targetlist of another sub-SELECT.  That could result in unexpected behavior
      due to multiple evaluations of a volatile function, as in a recent
      complaint from Etienne Dube.  It's been questionable from the very
      beginning whether these functions should look into subqueries (as noted in
      their comments), and this case seems to provide proof that they should.
      
      Because the new code only descends into SubLinks, not SubPlans or
      InitPlans, the change only affects the planner's behavior during
      prepjointree processing and not later on --- for example, you can still get
      it to use a volatile function in an indexqual if you wrap the function in
      (SELECT ...).  That's a historical behavior, for sure, but it's reasonable
      given that the executor's evaluation rules for subplans don't depend on
      whether there are volatile functions inside them.  In any case, we need to
      constrain the behavioral change as narrowly as we can to make this
      reasonable to back-patch.
      f7171c7e
    • Tom Lane's avatar
      Fix subtly-wrong volatility checking in BeginCopyFrom(). · 733e49ec
      Tom Lane authored
      contain_volatile_functions() is best applied to the output of
      expression_planner(), not its input, so that insertion of function
      default arguments and constant-folding have been done.  (See comments
      at CheckMutability, for instance.)  It's perhaps unlikely that anyone
      will notice a difference in practice, but still we should do it properly.
      
      In passing, change variable type from Node* to Expr* to reduce the net
      number of casts needed.
      
      Noted while perusing uses of contain_volatile_functions().
      733e49ec
  4. Nov 07, 2013
    • Tom Lane's avatar
      Be more robust when strerror() doesn't give a useful result. · 64f5962f
      Tom Lane authored
      Back-patch commits 8e68816c and
      8dace66e into the stable branches.
      Buildfarm testing revealed no great portability surprises, and it
      seems useful to have this robustness improvement in all branches.
      64f5962f
    • Tom Lane's avatar
      Prevent display of dropped columns in row constraint violation messages. · 8bd5a6af
      Tom Lane authored
      ExecBuildSlotValueDescription() printed "null" for each dropped column in
      a row being complained of by ExecConstraints().  This has some sanity in
      terms of the underlying implementation, but is of course pretty surprising
      to users.  To fix, we must pass the target relation's descriptor to
      ExecBuildSlotValueDescription(), because the slot descriptor it had been
      using doesn't get labeled with attisdropped markers.
      
      Per bug #8408 from Maxim Boguk.  Back-patch to 9.2 where the feature of
      printing row values in NOT NULL and CHECK constraint violation messages
      was introduced.
      
      Michael Paquier and Tom Lane
      8bd5a6af
    • Tom Lane's avatar
      Fix generation of MergeAppend plans for optimized min/max on expressions. · aa8a2c3a
      Tom Lane authored
      Before jamming a desired targetlist into a plan node, one really ought to
      make sure the plan node can handle projections, and insert a buffering
      Result plan node if not.  planagg.c forgot to do this, which is a hangover
      from the days when it only dealt with IndexScan plan types.  MergeAppend
      doesn't project though, not to mention that it gets unhappy if you remove
      its possibly-resjunk sort columns.  The code accidentally failed to fail
      for cases in which the min/max argument was a simple Var, because the new
      targetlist would be equivalent to the original "flat" tlist anyway.
      For any more complex case, it's been broken since 9.1 where we introduced
      the ability to optimize min/max using MergeAppend, as reported by Raphael
      Bauduin.  Fix by duplicating the logic from grouping_planner that decides
      whether we need a Result node.
      
      In 9.2 and 9.1, this requires back-porting the tlist_same_exprs() function
      introduced in commit 4387cf95, else we'd
      uselessly add a Result node in cases that worked before.  It's rather
      tempting to back-patch that whole commit so that we can avoid extra Result
      nodes in mainline cases too; but I'll refrain, since that code hasn't
      really seen all that much field testing yet.
      aa8a2c3a
  5. Nov 06, 2013
    • Tom Lane's avatar
      Support default arguments and named-argument notation for window functions. · 74aea2af
      Tom Lane authored
      These things didn't work because the planner omitted to do the necessary
      preprocessing of a WindowFunc's argument list.  Add the few dozen lines
      of code needed to handle that.
      
      Although this sounds like a feature addition, it's really a bug fix because
      the default-argument case was likely to crash previously, due to lack of
      checking of the number of supplied arguments in the built-in window
      functions.  It's not a security issue because there's no way for a
      non-superuser to create a window function definition with defaults that
      refers to a built-in C function, but nonetheless people might be annoyed
      that it crashes rather than producing a useful error message.  So
      back-patch as far as the patch applies easily, which turns out to be 9.2.
      I'll put a band-aid in earlier versions as a separate patch.
      
      (Note that these features still don't work for aggregates, and fixing that
      case will be harder since we represent aggregate arg lists as target lists
      not bare expression lists.  There's no crash risk though because CREATE
      AGGREGATE doesn't accept defaults, and we reject named-argument notation
      when parsing an aggregate call.)
      74aea2af
    • Tom Lane's avatar
      Improve the error message given for modifying a window with frame clause. · 599942cf
      Tom Lane authored
      For rather inscrutable reasons, SQL:2008 disallows copying-and-modifying a
      window definition that has any explicit framing clause.  The error message
      we gave for this only made sense if the referencing window definition
      itself contains an explicit framing clause, which it might well not.
      Moreover, in the context of an OVER clause it's not exactly obvious that
      "OVER (windowname)" implies copy-and-modify while "OVER windowname" does
      not.  This has led to multiple complaints, eg bug #5199 from Iliya
      Krapchatov.  Change to a hopefully more intelligible error message, and
      in the case where we have just "OVER (windowname)", add a HINT suggesting
      that omitting the parentheses will fix it.  Also improve the related
      documentation.  Back-patch to all supported branches.
      599942cf
  6. Nov 03, 2013
    • Tom Lane's avatar
      Prevent memory leaks from accumulating across printtup() calls. · 85de1262
      Tom Lane authored
      Historically, printtup() has assumed that it could prevent memory leakage
      by pfree'ing the string result of each output function and manually
      managing detoasting of toasted values.  This amounts to assuming that
      datatype output functions never leak any memory internally; an assumption
      we've already decided to be bogus elsewhere, for example in COPY OUT.
      range_out in particular is known to leak multiple kilobytes per call, as
      noted in bug #8573 from Godfried Vanluffelen.  While we could go in and fix
      that leak, it wouldn't be very notationally convenient, and in any case
      there have been and undoubtedly will again be other leaks in other output
      functions.  So what seems like the best solution is to run the output
      functions in a temporary memory context that can be reset after each row,
      as we're doing in COPY OUT.  Some quick experimentation suggests this is
      actually a tad faster than the retail pfree's anyway.
      
      This patch fixes all the variants of printtup, except for debugtup()
      which is used in standalone mode.  It doesn't seem worth worrying
      about query-lifespan leaks in standalone mode, and fixing that case
      would be a bit tedious since debugtup() doesn't currently have any
      startup or shutdown functions.
      
      While at it, remove manual detoast management from several other
      output-function call sites that had copied it from printtup().  This
      doesn't make a lot of difference right now, but in view of recent
      discussions about supporting "non-flattened" Datums, we're going to
      want that code gone eventually anyway.
      
      Back-patch to 9.2 where range_out was introduced.  We might eventually
      decide to back-patch this further, but in the absence of known major
      leaks in older output functions, I'll refrain for now.
      85de1262
    • Michael Meskes's avatar
  7. Nov 02, 2013
    • Tom Lane's avatar
      Retry after buffer locking failure during SPGiST index creation. · a1c3d54f
      Tom Lane authored
      The original coding thought this case was impossible, but it can happen
      if the bgwriter or checkpointer processes decide to write out an index
      page while creation is still proceeding, leading to a bogus "unexpected
      spgdoinsert() failure" error.  Problem reported by Jonathan S. Katz.
      
      Teodor Sigaev
      a1c3d54f
  8. Nov 01, 2013
    • Tom Lane's avatar
      Ensure all files created for a single BufFile have the same resource owner. · 2f2507e3
      Tom Lane authored
      Callers expect that they only have to set the right resource owner when
      creating a BufFile, not during subsequent operations on it.  While we could
      insist this be fixed at the caller level, it seems more sensible for the
      BufFile to take care of it.  Without this, some temp files belonging to
      a BufFile can go away too soon, eg at the end of a subtransaction,
      leading to errors or crashes.
      
      Reported and fixed by Andres Freund.  Back-patch to all active branches.
      2f2507e3
    • Tom Lane's avatar
      Fix some odd behaviors when using a SQL-style simple GMT offset timezone. · 2e213495
      Tom Lane authored
      Formerly, when using a SQL-spec timezone setting with a fixed GMT offset
      (called a "brute force" timezone in the code), the session_timezone
      variable was not updated to match the nominal timezone; rather, all code
      was expected to ignore session_timezone if HasCTZSet was true.  This is
      of course obviously fragile, though a search of the code finds only
      timeofday() failing to honor the rule.  A bigger problem was that
      DetermineTimeZoneOffset() supposed that if its pg_tz parameter was
      pointer-equal to session_timezone, then HasCTZSet should override the
      parameter.  This would cause datetime input containing an explicit zone
      name to be treated as referencing the brute-force zone instead, if the
      zone name happened to match the session timezone that had prevailed
      before installing the brute-force zone setting (as reported in bug #8572).
      The same malady could affect AT TIME ZONE operators.
      
      To fix, set up session_timezone so that it matches the brute-force zone
      specification, which we can do using the POSIX timezone definition syntax
      "<abbrev>offset", and get rid of the bogus lookaside check in
      DetermineTimeZoneOffset().  Aside from fixing the erroneous behavior in
      datetime parsing and AT TIME ZONE, this will cause the timeofday() function
      to print its result in the user-requested time zone rather than some
      previously-set zone.  It might also affect results in third-party
      extensions, if there are any that make use of session_timezone without
      considering HasCTZSet, but in all cases the new behavior should be saner
      than before.
      
      Back-patch to all supported branches.
      2e213495
  9. Oct 29, 2013
    • Tom Lane's avatar
      Prevent using strncpy with src == dest in TupleDescInitEntry. · a37f94ae
      Tom Lane authored
      The C and POSIX standards state that strncpy's behavior is undefined when
      source and destination areas overlap.  While it remains dubious whether any
      implementations really misbehave when the pointers are exactly equal, some
      platforms are now starting to force the issue by complaining when an
      undefined call occurs.  (In particular OS X 10.9 has been seen to dump core
      here, though the exact set of circumstances needed to trigger that remain
      elusive.  Similar behavior can be expected to be optional on Linux and
      other platforms in the near future.)  So tweak the code to explicitly do
      nothing when nothing need be done.
      
      Back-patch to all active branches.  In HEAD, this also lets us get rid of
      an exception in valgrind.supp.
      
      Per discussion of a report from Matthias Schmitt.
      a37f94ae
  10. Oct 28, 2013
    • Andrew Dunstan's avatar
      Work around NetBSD shell issue in pg_upgrade test script. · 9060cb96
      Andrew Dunstan authored
      The NetBSD shell apparently returns non-zero from an unset command if
      the variable is already unset. This matters when, as in pg_upgrade's
      test.sh, we are working under 'set -e'. To protect against this, we
      first set the PG variables to an empty string before unsetting them
      completely.
      
      Error found on buildfarm member coypu, solution from Rémi Zara.
      9060cb96
  11. Oct 23, 2013
    • Heikki Linnakangas's avatar
      Fix two bugs in setting the vm bit of empty pages. · 4da24f12
      Heikki Linnakangas authored
      Use a critical section when setting the all-visible flag on an empty page,
      and WAL-logging it. log_newpage_buffer() contains an assertion that it
      must be called inside a critical section, and it's the right thing to do
      when modifying a buffer anyway.
      
      Also, the page should be marked dirty before calling log_newpage_buffer(),
      per the comment in log_newpage_buffer() and src/backend/access/transam/README.
      
      Patch by Andres Freund, in response to my report. Backpatch to 9.2, like
      the patch that introduced these bugs (a6370fd9).
      4da24f12
  12. Oct 21, 2013
  13. Oct 15, 2013
  14. Oct 09, 2013
  15. Oct 08, 2013
  16. Oct 07, 2013
    • Heikki Linnakangas's avatar
      Fix bugs in SSI tuple locking. · 90378433
      Heikki Linnakangas authored
      1. In heap_hot_search_buffer(), the PredicateLockTuple() call is passed
      wrong offset number. heapTuple->t_self is set to the tid of the first
      tuple in the chain that's visited, not the one actually being read.
      
      2. CheckForSerializableConflictIn() uses the tuple's t_ctid field
      instead of t_self to check for exiting predicate locks on the tuple. If
      the tuple was updated, but the updater rolled back, t_ctid points to the
      aborted dead tuple.
      
      Reported by Hannu Krosing. Backpatch to 9.1.
      90378433
    • Peter Eisentraut's avatar
      Translation updates · 4dd5c312
      Peter Eisentraut authored
      4dd5c312
    • Kevin Grittner's avatar
      Eliminate xmin from hash tag for predicate locks on heap tuples. · 1f4cdf20
      Kevin Grittner authored
      If a tuple was frozen while its predicate locks mattered,
      read-write dependencies could be missed, resulting in failure to
      detect conflicts which could lead to anomalies in committed
      serializable transactions.
      
      This field was added to the tag when we still thought that it was
      necessary to carry locks forward to a new version of an updated
      row.  That was later proven to be unnecessary, which allowed
      simplification of the code, but elimination of xmin from the tag
      was missed at the time.
      
      Per report and analysis by Heikki Linnakangas.
      Backpatch to 9.1.
      1f4cdf20
    • Andrew Dunstan's avatar
      Document support for VPATH builds of extensions. · 565beb41
      Andrew Dunstan authored
      Cédric Villemain and me.
      565beb41
  17. Oct 03, 2013
  18. Sep 30, 2013
  19. Sep 29, 2013
  20. Sep 26, 2013
    • Heikki Linnakangas's avatar
      Fix spurious warning after vacuuming a page on a table with no indexes. · e0461945
      Heikki Linnakangas authored
      There is a rare race condition, when a transaction that inserted a tuple
      aborts while vacuum is processing the page containing the inserted tuple.
      Vacuum prunes the page first, which normally removes any dead tuples, but
      if the inserting transaction aborts right after that, the loop after
      pruning will see a dead tuple and remove it instead. That's OK, but if the
      page is on a table with no indexes, and the page becomes completely empty
      after removing the dead tuple (or tuples) on it, it will be immediately
      marked as all-visible. That's OK, but the sanity check in vacuum would
      throw a warning because it thinks that the page contains dead tuples and
      was nevertheless marked as all-visible, even though it just vacuumed away
      the dead tuples and so it doesn't actually contain any.
      
      Spotted this while reading the code. It's difficult to hit the race
      condition otherwise, but can be done by putting a breakpoint after the
      heap_page_prune() call.
      
      Backpatch all the way to 8.4, where this code first appeared.
      e0461945
  21. Sep 25, 2013
    • Heikki Linnakangas's avatar
      Plug memory leak in range_cmp function. · db7e953a
      Heikki Linnakangas authored
      B-tree operators are not allowed to leak memory into the current memory
      context. Range_cmp leaked detoasted copies of the arguments. That caused
      a quick out-of-memory error when creating an index on a range column.
      
      Reported by Marian Krucina, bug #8468.
      db7e953a
  22. Sep 24, 2013
  23. Sep 23, 2013
    • Noah Misch's avatar
      Use @libdir@ in both of regress/{input,output}/security_label.source · c05e9ec1
      Noah Misch authored
      Though @libdir@ almost always matches @abs_builddir@ in this context,
      the test could only fail if they differed.  Back-patch to 9.1, where the
      test was introduced.
      
      Hamid Quddus Akhtar
      c05e9ec1
    • Stephen Frost's avatar
      Fix SSL deadlock risk in libpq · d707a8cc
      Stephen Frost authored
      In libpq, we set up and pass to OpenSSL callback routines to handle
      locking.  When we run out of SSL connections, we try to clean things
      up by de-registering the hooks.  Unfortunately, we had a few calls
      into the OpenSSL library after these hooks were de-registered during
      SSL cleanup which lead to deadlocking.  This moves the thread callback
      cleanup to be after all SSL-cleanup related OpenSSL library calls.
      I've been unable to reproduce the deadlock with this fix.
      
      In passing, also move the close_SSL call to be after unlocking our
      ssl_config mutex when in a failure state.  While it looks pretty
      unlikely to be an issue, it could have resulted in deadlocks if we
      ended up in this code path due to something other than SSL_new
      failing.  Thanks to Heikki for pointing this out.
      
      Back-patch to all supported versions; note that the close_SSL issue
      only goes back to 9.0, so that hunk isn't included in the 8.4 patch.
      
      Initially found and reported by Vesa-Matti J Kari; many thanks to
      both Heikki and Andres for their help running down the specific
      issue and reviewing the patch.
      d707a8cc
Loading