1. 27 Mar, 2016 4 commits
    • Andres Freund's avatar
      Fix LWLockReportWaitEnd() parameter list to be (void). · 9f7c527a
      Andres Freund authored
      Previously it was an "old style" function declaration.
      9f7c527a
    • Andres Freund's avatar
      pg_rewind: Close backup_label file descriptor. · a6c84594
      Andres Freund authored
      This was a relatively harmless leak, as createBackupLabel() is only
      called once per pg_rewind invocation.
      
      Author: Michael Paquier
      Reported-By: Michael Paquier
      Discussion: CAB7nPqRnOw30gOXe2_SPLjh37bgm4V+txbYAPwoXb97nGQ297w@mail.gmail.com
      Backpatch: 9.5, where pg_rewind was introduced
      a6c84594
    • Andres Freund's avatar
      Don't use !! but != 0/NULL to force boolean evaluation. · 1a7a4367
      Andres Freund authored
      I introduced several uses of !! to force bit arithmetic to be boolean,
      but per discussion the project prefers != 0/NULL.
      
      Discussion: CA+TgmoZP5KakLGP6B4vUjgMBUW0woq_dJYi0paOz-My0Hwt_vQ@mail.gmail.com
      1a7a4367
    • Andres Freund's avatar
      Change various Gin*Is* macros to return 0/1. · af4472bc
      Andres Freund authored
      Returning the direct result of bit arithmetic, in a macro intended to be
      used in a boolean manner, can be problematic if the return value is
      stored in a variable of type 'bool'. If bool is implemented using C99's
      _Bool, that can lead to comparison failures if the variable is then
      compared again with the expression (see ginStepRight() for an example
      that fails), as _Bool forces the result to be 0/1. That happens in some
      configurations of newer MSVC compilers.  It's also problematic when
      storing the result of such an expression in a narrower type.
      
      Several gin macros have been declared in that style since gin's initial
      commit in 8a3631f8.
      
      There's a lot more macros like this, but this is the only one causing
      regression test failures; and I don't want to commit and backpatch a
      larger patch with lots of conflicts just before the next set of minor
      releases.
      
      Discussion: 20150811154237.GD17575@awork2.anarazel.de
      Backpatch: All supported branches
      af4472bc
  2. 26 Mar, 2016 3 commits
    • Tom Lane's avatar
      First-draft release notes for 9.5.2. · 29b6123e
      Tom Lane authored
      As usual, the release notes for other branches will be made by cutting
      these down, but put them up for community review first.
      29b6123e
    • Tom Lane's avatar
      Modernize zic's test for valid timezone abbreviations. · 221619ad
      Tom Lane authored
      We really need to sync all of our IANA-derived timezone code with upstream,
      but that's going to be a large patch and I certainly don't care to shove
      such a thing into stable branches immediately before a release.  As a
      stopgap, copy just the tzcode2016c logic that checks validity of timezone
      abbreviations.  This prevents getting multiple "time zone abbreviation
      differs from POSIX standard" bleats with tzdata 2014b and later.
      221619ad
    • Tom Lane's avatar
      Avoid a couple of zero-divide scenarios in the planner. · 76281aa9
      Tom Lane authored
      cost_subplan() supposed that the given subplan must have plan_rows > 0,
      which as far as I can tell was true until recent refactoring of the
      code in createplan.c; but now that code allows the Result for a provably
      empty subquery to have plan_rows = 0.  Rather than undo that change,
      put in a clamp to prevent zero divide.
      
      get_cheapest_fractional_path() likewise supposed that best_path->rows > 0.
      This assumption has been wrong for longer.  It's actually harmless given
      IEEE float math, because a positive value divided by zero gives +Infinity
      and compare_fractional_path_costs() will do the right thing with that.
      Still, best not to assume that.
      
      final_cost_nestloop() also seems to have some risks in this area, so
      borrow the clamping logic already present in the mergejoin cost functions.
      
      Lastly, remove unnecessary clamp_row_est() in planner.c's calls to
      get_number_of_groups().  The only thing that function does with path_rows
      is pass it to estimate_num_groups() which already has an internal clamp,
      so we don't need the extra call; and if we did, the callers are arguably
      the wrong place for it anyway.
      
      First two items reported by Piotr Stefaniak, the others are products
      of my nosing around for similar problems.  No back-patch since there's
      no evidence that problems arise in the back branches.
      76281aa9
  3. 25 Mar, 2016 8 commits
    • Tom Lane's avatar
      Update time zone data files to tzdata release 2016c. · 676265eb
      Tom Lane authored
      DST law changes in Azerbaijan, Chile, Haiti, Palestine, and Russia (Altai,
      Astrakhan, Kirov, Sakhalin, Ulyanovsk regions).  Historical corrections
      for Lithuania, Moldova, Russia (Kaliningrad, Samara, Volgograd).
      
      As of 2015b, the keepers of the IANA timezone database started to use
      numeric time zone abbreviations (e.g., "+04") instead of inventing
      abbreviations not found in the wild like "ASTT".  This causes our rather
      old copy of zic to whine "warning: time zone abbreviation differs from
      POSIX standard" several times during "make install".  This warning is
      harmless according to the IANA folk, and I don't see any problems with
      these abbreviations in some simple tests; but it seems like now would be
      a good time to update our copy of the tzcode stuff.  I'll look into that
      soon.
      676265eb
    • Tom Lane's avatar
      Fix PL/Tcl for vpath builds. · 9f73a2f6
      Tom Lane authored
      Commit cd37bb78 works for in-tree builds, but not so much for
      VPATH.  Per buildfarm.
      9f73a2f6
    • Tom Lane's avatar
      Improve PL/Tcl errorCode facility by providing decoded name for SQLSTATE. · cd37bb78
      Tom Lane authored
      We don't really want to encourage people to write numeric SQLSTATEs in
      programs; that's unreadable and error-prone.  Copy plpgsql's infrastructure
      for converting between SQLSTATEs and exception names shown in Appendix A,
      and modify examples in tests and documentation to do it that way.
      cd37bb78
    • Tom Lane's avatar
      In PL/Tcl, make database errors return additional info in the errorCode. · fb8d2a7f
      Tom Lane authored
      Tcl has a convention for returning additional info about an error in a
      global variable named errorCode.  Up to now PL/Tcl has ignored that,
      but this patch causes database errors caught by PL/Tcl to fill in
      errorCode with useful information from the ErrorData struct.
      
      Jim Nasby, reviewed by Pavel Stehule and myself
      fb8d2a7f
    • Tom Lane's avatar
      Fix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator. · c94959d4
      Tom Lane authored
      This avoids leaving dangling links in pg_operator; which while fairly
      harmless are also unsightly.
      
      While we're at it, simplify OperatorUpd, which went through
      heap_modify_tuple for no very good reason considering it had already made
      a tuple copy it could just scribble on.
      
      Roma Sokolov, reviewed by Tomas Vondra, additional hacking by Robert Haas
      and myself.
      c94959d4
    • Tom Lane's avatar
      Don't split up SRFs when choosing to postpone SELECT output expressions. · d543170f
      Tom Lane authored
      In commit 9118d03a we taught the planner to postpone evaluation of
      set-returning functions in a SELECT's targetlist until after any sort done
      to satisfy ORDER BY.  However, if we postpone some SRFs this way while
      others do not get postponed (because they're sort or group key columns)
      we will break the traditional behavior by which all SRFs in the tlist run
      in-step during ExecTargetList(), so that you get the least common multiple
      of their periods not the product.  Fix make_sort_input_target() so it will
      not split up SRF evaluation in such cases.
      
      There is still a hazard of similar odd behavior if there's a SRF in a
      grouping column and another one that isn't, but that was true before
      and we're just trying to preserve bug-compatibility with the traditional
      behavior.  This whole area is overdue to be rethought and reimplemented,
      but we'll try to avoid changing behavior until then.
      
      Per report from Regina Obe.
      d543170f
    • Tom Lane's avatar
      Link libpq after libpgfeutils to satisfy Windows linker. · 7caaeaf3
      Tom Lane authored
      Some of the non-MSVC Windows buildfarm members seem to need this to avoid
      getting "undefined symbol" errors on libpgfeutils' references to libpq.
      I could understand that if libpq were a static library, but surely it is
      not?  Oh well, at least the extra reference is no more harmful than it is
      for libpgcommon or libpgport.
      7caaeaf3
    • Tom Lane's avatar
      Move psql's psqlscan.l into src/fe_utils. · c1156411
      Tom Lane authored
      This completes (at least for now) the project of getting rid of ad-hoc
      linkages among the src/bin/ subdirectories.  Everything they share is now
      in src/fe_utils/ and is included from a static library at link time.
      
      A side benefit is that we can restore the FLEX_NO_BACKUP check for
      psqlscanslash.l.  We might need to think of another way to do that check
      if we ever need to build two lexers with that property in the same source
      directory, but there's no foreseeable reason to need that.
      c1156411
  4. 24 Mar, 2016 9 commits
    • Tom Lane's avatar
      Move psql's print.c and mbprint.c into src/fe_utils. · d65bea26
      Tom Lane authored
      Just turning the crank ...
      d65bea26
    • Tom Lane's avatar
      Suppress compiler warning for get_am_type_string(). · a376960c
      Tom Lane authored
      Compilers that don't know that elog(ERROR) doesn't return complained
      that this function might fail to return a value.  Per buildfarm.
      
      While at it, const-ify the function's declaration, since the intent
      is evidently to always return a constant string.
      a376960c
    • Tom Lane's avatar
      Add missed inclusion requirement in Mkvcbuild.pm. · 0ecd3fed
      Tom Lane authored
      Per buildfarm.
      0ecd3fed
    • Tom Lane's avatar
      Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. · 588d963b
      Tom Lane authored
      Per discussion, we want to create a static library and put the stuff into
      it that until now has been shared across src/bin/ directories by ad-hoc
      methods like symlinking a source file.  This commit creates the library and
      populates it with a couple of files that contain the widely-useful portions
      of pg_dump's dumputils.c file.  dumputils.c survives, because it has some
      stuff that didn't seem appropriate for fe_utils, but it's significantly
      smaller and is no longer referenced from any other directory.
      
      Follow-on patches will move more stuff into fe_utils.
      
      The Mkvcbuild.pm hacking here is just a best guess; we'll see how the
      buildfarm likes it.
      588d963b
    • Robert Haas's avatar
      Improve documentation for combine functions. · a596db33
      Robert Haas authored
      David Rowley
      a596db33
    • Robert Haas's avatar
      Use correct GetDatum function. · 59a02815
      Robert Haas authored
      Oops.
      59a02815
    • Tom Lane's avatar
      Avoid PGDLLIMPORT for simple local references in frontend programs. · c2d1eea9
      Tom Lane authored
      I was wondering if this would be an issue, and buildfarm member frogmouth
      says it is.
      c2d1eea9
    • Alvaro Herrera's avatar
      Support CREATE ACCESS METHOD · 473b9328
      Alvaro Herrera authored
      This enables external code to create access methods.  This is useful so
      that extensions can add their own access methods which can be formally
      tracked for dependencies, so that DROP operates correctly.  Also, having
      explicit support makes pg_dump work correctly.
      
      Currently only index AMs are supported, but we expect different types to
      be added in the future.
      
      Authors: Alexander Korotkov, Petr Jelínek
      Reviewed-By: Teodor Sigaev, Petr Jelínek, Jim Nasby
      Commitfest-URL: https://commitfest.postgresql.org/9/353/
      Discussion: https://www.postgresql.org/message-id/CAPpHfdsXwZmojm6Dx+TJnpYk27kT4o7Ri6X_4OSWcByu1Rm+VA@mail.gmail.com
      473b9328
    • Tom Lane's avatar
      Move keywords.c/kwlookup.c into src/common/. · 2c6af4f4
      Tom Lane authored
      Now that we have src/common/ for code shared between frontend and backend,
      we can get rid of (most of) the klugy ways that the keyword table and
      keyword lookup code were formerly shared between different uses.
      This is a first step towards a more general plan of getting rid of
      special-purpose kluges for sharing code in src/bin/.
      
      I chose to merge kwlookup.c back into keywords.c, as it once was, and
      always has been so far as keywords.h is concerned.  We could have
      kept them separate, but there is noplace that uses ScanKeywordLookup
      without also wanting access to the backend's keyword list, so there
      seems little point.
      
      ecpg is still a bit weird, but at least now the trickiness is documented.
      
      I think that the MSVC build script should require no adjustments beyond
      what's done here ... but we'll soon find out.
      2c6af4f4
  5. 23 Mar, 2016 6 commits
    • Robert Haas's avatar
      Disable abbreviated keys for string-sorting in non-C locales. · 3df9c374
      Robert Haas authored
      Unfortunately, every version of glibc thus far tested has bugs whereby
      strcoll() ordering does not match strxfrm() ordering as required by
      the standard.  This can result in, for example, corrupted indexes.
      Disabling abbreviated keys in these cases slows down non-C-collation
      string sorting considerably, but there seems to be no practical
      alternative.  Users who are confident that their libc implementations
      are solid in this regard can re-enable the optimization by compiling
      with TRUST_STRXFRM.
      
      Users who have built indexes using PostgreSQL 9.5 or PostgreSQL 9.5.1
      should REINDEX if there is a possibility that they may have been
      affected by this problem.
      
      Report by Marc-Olaf Jaschke.  Investigation mostly by Tom Lane, with
      help from Peter Geoghegan, Noah Misch, Stephen Frost, and me.  Patch
      by me, reviewed by Peter Geoghegan and Tom Lane.
      3df9c374
    • Robert Haas's avatar
      postgres_fdw: Fix crash when pushing down multiple joins. · 3151f16e
      Robert Haas authored
      A join clause might mention multiple relations on either side, so it
      need not be the case that a given joinrel's constituent relations are
      all on one side of the join clause or all on the other.
      
      Report by Rajkumar Raghuwanshi.  Analysis and fix by Michael Paquier
      and Ashutosh Bapat.
      3151f16e
    • Robert Haas's avatar
      Partition the freelist for shared dynahash tables. · 44ca4022
      Robert Haas authored
      Without this, contention on the freelist can become a pretty serious
      problem on large servers.
      
      Aleksander Alekseev, reviewed by Anastasia Lubennikova, Dilip Kumar,
      and me.
      44ca4022
    • Tom Lane's avatar
      Code review for error reports in jsonb_set(). · ea4b8bd6
      Tom Lane authored
      User-facing (even tested by regression tests) error conditions were thrown
      with elog(), hence had wrong SQLSTATE and were untranslatable.  And the
      error message texts weren't up to project style, either.
      ea4b8bd6
    • Tom Lane's avatar
      Fix unsafe use of strtol() on a non-null-terminated Text datum. · 384dfbde
      Tom Lane authored
      jsonb_set() could produce wrong answers or incorrect error reports, or in
      the worst case even crash, when trying to convert a path-array element into
      an integer for use as an array subscript.  Per report from Vitaly Burovoy.
      Back-patch to 9.5 where the faulty code was introduced (in commit
      c6947010).
      
      Michael Paquier
      384dfbde
    • Simon Riggs's avatar
      8320c625
  6. 22 Mar, 2016 3 commits
    • Tom Lane's avatar
      Fix EvalPlanQual bug when query contains both locked and not-locked rels. · 71404af2
      Tom Lane authored
      In commit afb9249d, we (probably I) made ExecLockRows assign
      null test tuples to all relations of the query while setting up to do an
      EvalPlanQual recheck for a newly-updated locked row.  This was sheerest
      brain fade: we should only set test tuples for relations that are lockable
      by the LockRows node, and in particular empty test tuples are only sensible
      for inheritance child relations that weren't the source of the current
      tuple from their inheritance tree.  Setting a null test tuple for an
      unrelated table causes it to return NULLs when it should not, as exhibited
      in bug #14034 from Bronislav Houdek.  To add insult to injury, doing it the
      wrong way required two loops where one would suffice; so the corrected code
      is even a bit shorter and faster.
      
      Add a regression test case based on his example, and back-patch to 9.5
      where the bug was introduced.
      71404af2
    • Teodor Sigaev's avatar
      Improve docs of pg_trgm changes · f6bd0da6
      Teodor Sigaev authored
      Artur Zakirov, per gripe from Jeff Janes
      f6bd0da6
    • Fujii Masao's avatar
      Fix typo in docs. · 112a2d06
      Fujii Masao authored
      Jeff Janes
      112a2d06
  7. 21 Mar, 2016 7 commits
    • Tom Lane's avatar
      Allow the delay in psql's \watch command to be a fractional second. · b2830965
      Tom Lane authored
      Instead of just "2" seconds, allow eg. "2.5" seconds.  Per request
      from Alvaro Herrera.  No docs change since the docs didn't say you
      couldn't do this already.
      b2830965
    • Tom Lane's avatar
      Improve header output from psql's \watch command. · dea2b596
      Tom Lane authored
      Include the \pset title string if there is one, and shorten the prefab
      part of the header to be "timestamp (every Ns)".  Per suggestion by
      David Johnston.
      
      Michael Paquier and Tom Lane
      dea2b596
    • Tom Lane's avatar
      Clean up some Coverity complaints about commit 0bf3ae88. · 92b7902d
      Tom Lane authored
      The two get_tle_by_resno() calls introduced by this commit lacked any
      check for a NULL return, unlike any other calls of that function anywhere
      in our tree.  Coverity quite properly complained about it.  Also fix a
      misindented line in process_query_params(), which Coverity also complained
      about on the grounds that the bad indentation suggested possible programmer
      misinterpretation.
      92b7902d
    • Robert Haas's avatar
      Make max_parallel_degree PGC_USERSET. · ae507d92
      Robert Haas authored
      It was intended to be this way all along, just like other planner
      GUCs such as work_mem.  But I goofed.
      ae507d92
    • Robert Haas's avatar
      Support parallel aggregation. · e06a3896
      Robert Haas authored
      Parallel workers can now partially aggregate the data and pass the
      transition values back to the leader, which can combine the partial
      results to produce the final answer.
      
      David Rowley, based on earlier work by Haribabu Kommi.  Reviewed by
      Álvaro Herrera, Tomas Vondra, Amit Kapila, James Sewell, and me.
      e06a3896
    • Andres Freund's avatar
      Properly declare FeBeWaitSet. · 7fa00640
      Andres Freund authored
      Surprising that this worked on a number of systems. Reported by
      buildfarm member longfin.
      7fa00640
    • Andres Freund's avatar
      Introduce WaitEventSet API. · 98a64d0b
      Andres Freund authored
      Commit ac1d7945 ("Make idle backends exit if the postmaster dies.")
      introduced a regression on, at least, large linux systems. Constantly
      adding the same postmaster_alive_fds to the OSs internal datastructures
      for implementing poll/select can cause significant contention; leading
      to a performance regression of nearly 3x in one example.
      
      This can be avoided by using e.g. linux' epoll, which avoids having to
      add/remove file descriptors to the wait datastructures at a high rate.
      Unfortunately the current latch interface makes it hard to allocate any
      persistent per-backend resources.
      
      Replace, with a backward compatibility layer, WaitLatchOrSocket with a
      new WaitEventSet API. Users can allocate such a Set across multiple
      calls, and add more than one file-descriptor to wait on. The latter has
      been added because there's upcoming postgres features where that will be
      helpful.
      
      In addition to the previously existing poll(2), select(2),
      WaitForMultipleObjects() implementations also provide an epoll_wait(2)
      based implementation to address the aforementioned performance
      problem. Epoll is only available on linux, but that is the most likely
      OS for machines large enough (four sockets) to reproduce the problem.
      
      To actually address the aforementioned regression, create and use a
      long-lived WaitEventSet for FE/BE communication.  There are additional
      places that would benefit from a long-lived set, but that's a task for
      another day.
      
      Thanks to Amit Kapila, who helped make the windows code I blindly wrote
      actually work.
      
      Reported-By: Dmitry Vasilyev Discussion:
      CAB-SwXZh44_2ybvS5Z67p_CDz=XFn4hNAD=CnMEF+QqkXwFrGg@mail.gmail.com
      20160114143931.GG10941@awork2.anarazel.de
      98a64d0b