1. 20 Feb, 2019 2 commits
    • Dean Rasheed's avatar
      Fix DEFAULT-handling in multi-row VALUES lists for updatable views. · 41531e42
      Dean Rasheed authored
      INSERT ... VALUES for a single VALUES row is implemented differently
      from a multi-row VALUES list, which causes inconsistent behaviour in
      the way that DEFAULT items are handled. In particular, when inserting
      into an auto-updatable view on top of a table with a column default, a
      DEFAULT item in a single VALUES row gets correctly replaced with the
      table column's default, but for a multi-row VALUES list it is replaced
      with NULL.
      
      Fix this by allowing rewriteValuesRTE() to leave DEFAULT items in the
      VALUES list untouched if the target relation is an auto-updatable view
      and has no column default, deferring DEFAULT-expansion until the query
      against the base relation is rewritten. For all other types of target
      relation, including tables and trigger- and rule-updatable views, we
      must continue to replace DEFAULT items with NULL in the absence of a
      column default.
      
      This is somewhat complicated by the fact that if an auto-updatable
      view has DO ALSO rules attached, the VALUES lists for the product
      queries need to be handled differently from the original query, since
      the product queries need to act like rule-updatable views whereas the
      original query has auto-updatable view semantics.
      
      Back-patch to all supported versions.
      
      Reported by Roger Curley (bug #15623). Patch by Amit Langote and me.
      
      Discussion: https://postgr.es/m/15623-5d67a46788ec8b7f@postgresql.org
      41531e42
    • Michael Paquier's avatar
      Mark correctly initial slot snapshots with MVCC type when built · 56fadbed
      Michael Paquier authored
      When building an initial slot snapshot, snapshots are marked with
      historic MVCC snapshots as type with the marker field being set in
      SnapBuildBuildSnapshot() but not overriden in SnapBuildInitialSnapshot().
      Existing callers of SnapBuildBuildSnapshot() do not care about the type
      of snapshot used, but extensions calling it actually may, as reported.
      
      While on it, mark correctly the snapshot type when importing one.  This
      is cosmetic as the field is enforced to 0.
      
      Author: Antonin Houska
      Reviewed-by: Álvaro Herrera, Michael Paquier
      Discussion: https://postgr.es/m/23215.1527665193@localhost
      Backpatch-through: 9.4
      56fadbed
  2. 19 Feb, 2019 2 commits
  3. 18 Feb, 2019 10 commits
  4. 17 Feb, 2019 6 commits
    • Thomas Munro's avatar
      Fix race in dsm_unpin_segment() when handles are reused. · 0b55aaac
      Thomas Munro authored
      Teach dsm_unpin_segment() to skip segments that are in the process
      of being destroyed by another backend, when searching for a handle.
      Such a segment cannot possibly be the one we are looking for, even
      if its handle matches.  Another slot might hold a recently created
      segment that has the same handle value by coincidence, and we need
      to keep searching for that one.
      
      The bug caused rare "cannot unpin a segment that is not pinned"
      errors on 10 and 11.  Similar to commit 6c0fb941 for dsm_attach().
      
      Back-patch to 10, where dsm_unpin_segment() landed.
      
      Author: Thomas Munro
      Reported-by: Justin Pryzby
      Tested-by: Justin Pryzby (along with other recent DSA/DSM fixes)
      Discussion: https://postgr.es/m/20190216023854.GF30291@telsasoft.com
      0b55aaac
    • Joe Conway's avatar
      Fix documentation for dblink_error_message() return value · bc6d7eb6
      Joe Conway authored
      The dblink documentation claims that an empty string is returned if there
      has been no error, however OK is actually returned in that case. Also,
      clarify that an async error may not be seen unless dblink_is_busy() or
      dblink_get_result() have been called first.
      
      Backpatch to all supported branches.
      
      Reported-by: realyota
      Backpatch-through: 9.4
      Discussion: https://postgr.es/m/153371978486.1298.2091761143788088262@wrigleys.postgresql.org
      bc6d7eb6
    • Tom Lane's avatar
      Fix CREATE VIEW to allow zero-column views. · a32ca788
      Tom Lane authored
      We should logically have allowed this case when we allowed zero-column
      tables, but it was overlooked.
      
      Although this might be thought a feature addition, it's really a bug
      fix, because it was possible to create a zero-column view via
      the convert-table-to-view code path, and then you'd have a situation
      where dump/reload would fail.  Hence, back-patch to all supported
      branches.
      
      Arrange the added test cases to provide coverage of the related
      pg_dump code paths (since these views will be dumped and reloaded
      during the pg_upgrade regression test).  I also made them test
      the case where pg_dump has to postpone the view rule into post-data,
      which disturbingly had no regression coverage before.
      
      Report and patch by Ashutosh Sharma (test case by me)
      
      Discussion: https://postgr.es/m/CAE9k0PkmHdeSaeZt2ujnb_cKucmK3sDDceDzw7+d5UZoNJPYOg@mail.gmail.com
      a32ca788
    • Joe Conway's avatar
      Mark pg_config() stable rather than immutable · 290e3b77
      Joe Conway authored
      pg_config() has been marked immutable since its inception. As part of a
      larger discussion around the definition of immutable versus stable and
      related implications for marking functions parallel safe raised by
      Andres, the consensus was clearly that pg_config() is stable, since
      it could possibly change output even for the same minor version with
      a recompile or installation of a new binary. So mark it stable.
      
      Theoretically this could/should be backpatched, but it was deemed to be not
      worth the effort since in practice this is very unlikely to cause problems
      in the real world.
      
      Discussion: https://postgr.es/m/20181126234521.rh3grz7aavx2ubjv@alap3.anarazel.de
      290e3b77
    • Tatsuo Ishii's avatar
      Doc: remove ancient comment. · 69e52478
      Tatsuo Ishii authored
      There's a very old comment in rules.sgml added back to 2003.  It
      expected to a feature coming back but it never happened. So now we can
      safely remove the comment. Back-patched to all supported branches.
      
      Discussion: https://postgr.es/m/20190211.191004.219630835457494660.t-ishii%40sraoss.co.jp
      69e52478
    • Noah Misch's avatar
      Fix CLogTruncationLock documentation. · 301de4f7
      Noah Misch authored
      Back-patch to v10, which introduced the lock.
      301de4f7
  5. 16 Feb, 2019 10 commits
    • Noah Misch's avatar
      Suppress another case of MSVC warning 4146. · faee6fae
      Noah Misch authored
      faee6fae
    • Noah Misch's avatar
      In imath.h, replace stdint.h usage with c.h equivalents. · 04a87ae2
      Noah Misch authored
      As things stood, buildfarm member dory failed.  MSVC versions lacking
      stdint.h are unusable for building PostgreSQL, but pg_config.h.win32
      doesn't know that.  Even so, we support other systems lacking stdint.h,
      including buildfarm member gaur.  Per a suggestion from Tom Lane.
      
      Discussion: https://postgr.es/m/9598.1550353336@sss.pgh.pa.us
      04a87ae2
    • Andrew Gierth's avatar
      Remove float8-small-is-zero regression test variant. · 6ee89952
      Andrew Gierth authored
      Since this was also the variant used as an example in the docs, update
      the docs to use float4-misrounded-input as an example instead, since
      that is now the only remaining variant file.
      6ee89952
    • Noah Misch's avatar
      Import changes from IMath versions (1.3, 1.29]. · 48e24ba6
      Noah Misch authored
      Upstream fixed bugs over the years, but none are confirmed to have
      affected pgcrypto.  We're better off naively tracking upstream than
      reactively maintaining a twelve-year-old snapshot of upstream.  Add a
      header comment describing the synchronization procedure.  Discard use of
      INVERT_COMPARE_RESULT(); the domain of the comparisons in question is
      {-1,0,1}, controlled entirely by code in imath.c.
      
      Andrew Gierth reviewed the Makefile change.  Tom Lane reviewed the
      synchronization procedure description.
      
      Discussion: https://postgr.es/m/20190203035704.GA6226@rfd.leadboat.com
      48e24ba6
    • Noah Misch's avatar
      Fix PERMIT_DECLARATION_AFTER_STATEMENT initialization. · d1299aab
      Noah Misch authored
      The defect caused a mere warning and only for gcc versions before 3.4.0.
      d1299aab
    • Tom Lane's avatar
      Allow user control of CTE materialization, and change the default behavior. · 608b167f
      Tom Lane authored
      Historically we've always materialized the full output of a CTE query,
      treating WITH as an optimization fence (so that, for example, restrictions
      from the outer query cannot be pushed into it).  This is appropriate when
      the CTE query is INSERT/UPDATE/DELETE, or is recursive; but when the CTE
      query is non-recursive and side-effect-free, there's no hazard of changing
      the query results by pushing restrictions down.
      
      Another argument for materialization is that it can avoid duplicate
      computation of an expensive WITH query --- but that only applies if
      the WITH query is called more than once in the outer query.  Even then
      it could still be a net loss, if each call has restrictions that
      would allow just a small part of the WITH query to be computed.
      
      Hence, let's change the behavior for WITH queries that are non-recursive
      and side-effect-free.  By default, we will inline them into the outer
      query (removing the optimization fence) if they are called just once.
      If they are called more than once, we will keep the old behavior by
      default, but the user can override this and force inlining by specifying
      NOT MATERIALIZED.  Lastly, the user can force the old behavior by
      specifying MATERIALIZED; this would mainly be useful when the query had
      deliberately been employing WITH as an optimization fence to prevent a
      poor choice of plan.
      
      Andreas Karlsson, Andrew Gierth, David Fetter
      
      Discussion: https://postgr.es/m/87sh48ffhb.fsf@news-spur.riddles.org.uk
      608b167f
    • Andrew Gierth's avatar
      Fix previous MinGW fix. · 79730e2a
      Andrew Gierth authored
      Definitions required for MinGW need to be outside #if _MSC_VER. Oops.
      79730e2a
    • Michael Meskes's avatar
      Add DECLARE STATEMENT support to ECPG. · bd7c95f0
      Michael Meskes authored
      DECLARE STATEMENT is a statement that lets users declare an identifier
      pointing at a connection.  This identifier will be used in other embedded
      dynamic SQL statement such as PREPARE, EXECUTE, DECLARE CURSOR and so on.
      When connecting to a non-default connection, the AT clause can be used in
      a DECLARE STATEMENT once and is no longer needed in every dynamic SQL
      statement.  This makes ECPG applications easier and more efficient.  Moreover,
      writing code without designating connection explicitly improves portability.
      
      Authors: Ideriha-san ("Ideriha, Takeshi" <ideriha.takeshi@jp.fujitsu.com>)
               Kuroda-san ("Kuroda, Hayato" <kuroda.hayato@jp.fujitsu.com>)
      
      Discussion: https://postgr.es/m4E72940DA2BF16479384A86D54D0988A565669DF@G01JPEXMBKW04
      bd7c95f0
    • Tom Lane's avatar
      Make use of compiler builtins and/or assembly for CLZ, CTZ, POPCNT. · 02a6a54e
      Tom Lane authored
      Test for the compiler builtins __builtin_clz, __builtin_ctz, and
      __builtin_popcount, and make use of these in preference to
      handwritten C code if they're available.  Create src/port
      infrastructure for "leftmost one", "rightmost one", and "popcount"
      so as to centralize these decisions.
      
      On x86_64, __builtin_popcount generally won't make use of the POPCNT
      opcode because that's not universally supported yet.  Provide code
      that checks CPUID and then calls POPCNT via asm() if available.
      This requires indirecting through a function pointer, which is
      an annoying amount of overhead for a one-instruction operation,
      but it's probably not worth working harder than this for our
      current use-cases.
      
      I'm not sure we've found all the existing places that could profit
      from this new infrastructure; but we at least touched all the
      ones that used copied-and-pasted versions of the bitmapset.c code,
      and got rid of multiple copies of the associated constant arrays.
      
      While at it, replace c-compiler.m4's one-per-builtin-function
      macros with a single one that can handle all the cases we need
      to worry about so far.  Also, because I'm paranoid, make those
      checks into AC_LINK checks rather than just AC_COMPILE; the
      former coding failed to verify that libgcc has support for the
      builtin, in cases where it's not inline code.
      
      David Rowley, Thomas Munro, Alvaro Herrera, Tom Lane
      
      Discussion: https://postgr.es/m/CAKJS1f9WTAGG1tPeJnD18hiQW5gAk59fQ6WK-vfdAKEHyRg2RA@mail.gmail.com
      02a6a54e
    • Andrew Gierth's avatar
      Cygwin and Mingw floating-point fixes. · 72880ac1
      Andrew Gierth authored
      Deal with silent-underflow errors in float4 for cygwin and mingw by
      using our strtof() wrapper; deal with misrounding errors by adding
      them to the resultmap. Some slight reorganization of declarations was
      done to avoid duplicating material between cygwin.h and win32_port.h.
      
      While here, remove from the resultmap all references to
      float8-small-is-zero; inspection of cygwin output suggests it's no
      longer required there, and the freebsd/netbsd/openbsd entries should
      no longer be necessary (these date back to c. 2000). This commit
      doesn't remove the file itself nor the documentation references for
      it; that will happen in a subsequent commit if all goes well.
      72880ac1
  6. 15 Feb, 2019 8 commits
    • Alvaro Herrera's avatar
      Revert attempts to use POPCNT etc instructions · 457aef0f
      Alvaro Herrera authored
      This reverts commits fc6c7274, 109de05c, d0b4663c and
      711bab1e.
      
      Somebody will have to try harder before submitting this patch again.
      I've spent entirely too much time on it already, and the #ifdef maze yet
      to be written in order for it to build at all got on my nerves.  The
      amount of work needed to get a platform-specific performance improvement
      that's barely above the noise level is not worth it.
      457aef0f
    • Tom Lane's avatar
      Refactor index cost estimation functions in view of IndexClause changes. · e89f14e2
      Tom Lane authored
      Get rid of deconstruct_indexquals() in favor of just iterating over the
      IndexClause list directly.  The extra services that that function used to
      provide, such as hiding clause commutation and associating the right index
      column with each clause, are no longer useful given the new data structure.
      I'd originally thought that it'd provide a useful amount of abstraction
      by freeing callers from paying attention to the exact clause type of each
      indexqual, but that hope proves to have been vain, because few callers can
      ignore the semantic differences between different clause types.  Indeed,
      removing it results in a net code savings, and probably some cycles shaved
      by not having to build an extra list-of-structs data structure.
      
      Also, export a few formerly-static support functions, with the goal
      of allowing extension AMs to write functionality equivalent to
      genericcostestimate() without pointless code duplication.
      
      Discussion: https://postgr.es/m/24586.1550106354@sss.pgh.pa.us
      e89f14e2
    • Alvaro Herrera's avatar
      Fix compiler builtin usage in new pg_bitutils.c · fc6c7274
      Alvaro Herrera authored
      Split out these new functions in three parts: one in a new file that
      uses the compiler builtin and gets compiled with the -mpopcnt compiler
      option if it exists; another one that uses the compiler builtin but not
      the compiler option; and finally the fallback with open-coded
      algorithms.
      
      Split out the configure logic: in the original commit, it was selecting
      to use the -mpopcnt compiler switch together with deciding whether to
      use the compiler builtin, but those two things are really separate.
      Split them out.  Also, expose whether the builtin exists to
      Makefile.global, so that src/port's Makefile can decide whether to
      compile the hw-optimized file.
      
      Remove CPUID test for CTZ/CLZ.  Make pg_{right,left}most_ones use either
      the compiler intrinsic or open-coded algo; trying to use the
      HW-optimized version is a waste of time.  Make them static inline
      functions.
      
      Discussion: https://postgr.es/m/20190213221719.GA15976@alvherre.pgsql
      fc6c7274
    • Peter Eisentraut's avatar
      doc: Update README.links · b060e6c1
      Peter Eisentraut authored
      The guideline to "not use text with <ulink> so the URL appears in
      printed output" is obsolete, since the URL appears as a footnote in
      printed output in that case.
      Reported-by: default avatarChapman Flack <chap@anastigmatix.net>
      Discussion: https://www.postgresql.org/message-id/5C4B1F2F.2000106@anastigmatix.net
      b060e6c1
    • Peter Eisentraut's avatar
      Use standard diff separator for regression.diffs · 8f27a14b
      Peter Eisentraut authored
      Instead of ======..., use the standard separator for a multi-file
      diff, which is, per POSIX,
      
          "diff %s %s %s\n", <diff_options>, <filename1>, <filename2>
      
      This makes regression.diffs behave more like a proper diff file, for
      use with other tools.  And it shows the diff options used, for
      clarity.
      
      Discussion: https://www.postgresql.org/message-id/70440c81-37bb-76dd-e48b-b5a9550d5613@2ndquadrant.com
      8f27a14b
    • Michael Paquier's avatar
      Fix support for CREATE TABLE IF NOT EXISTS AS EXECUTE · 331a613e
      Michael Paquier authored
      The grammar IF NOT EXISTS for CTAS is supported since 9.5 and documented
      as such, however the case of using EXECUTE as query has never been
      covered as EXECUTE CTAS statements and normal CTAS statements are parsed
      separately.
      
      Author: Andreas Karlsson
      Discussion: https://postgr.es/m/2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se
      Backpatch-through: 9.5
      331a613e
    • Thomas Munro's avatar
      Fix race in dsm_attach() when handles are reused. · 6c0fb941
      Thomas Munro authored
      DSM handle values can be reused as soon as the underlying shared memory
      object has been destroyed.  That means that for a brief moment we
      might have two DSM slots with the same handle.  While trying to attach,
      if we encounter a slot with refcnt == 1, meaning that it is currently
      being destroyed, we should continue our search in case the same handle
      exists in another slot.
      
      The race manifested as a rare "dsa_area could not attach to segment"
      error, and was more likely in 10 and 11 due to the lack of distinct
      seed for random() in parallel workers.  It was made very unlikely in
      in master by commit 197e4af9, and older releases don't usually create
      new DSM segments in background workers so it was also unlikely there.
      
      This fixes the root cause of bug report #15585, in which the error
      could also sometimes result in a self-deadlock in the error path.
      It's not yet clear if further changes are needed to avoid that failure
      mode.
      
      Back-patch to 9.4, where dsm.c arrived.
      
      Author: Thomas Munro
      Reported-by: Justin Pryzby, Sergei Kornilov
      Discussion: https://postgr.es/m/20190207014719.GJ29720@telsasoft.com
      Discussion: https://postgr.es/m/15585-324ff6a93a18da46@postgresql.org
      6c0fb941
    • Tom Lane's avatar
      Simplify the planner's new representation of indexable clauses a little. · 8fd3fdd8
      Tom Lane authored
      In commit 1a8d5afb, I thought it'd be a good idea to define
      IndexClause.indexquals as NIL in the most common case where the given
      clause (IndexClause.rinfo) is usable exactly as-is.  It'd be more
      consistent to define the indexquals in that case as being a one-element
      list containing IndexClause.rinfo, but I thought saving the palloc
      overhead for making such a list would be worthwhile.
      
      In hindsight, that was a great example of "premature optimization is the
      root of all evil": it's complicated everyplace that needs to deal with
      the indexquals, requiring duplicative code to handle both the simple
      case and the not-simple case.  I'd initially found that tolerable but
      it's getting less so as I mop up some areas that I'd not touched in
      1a8d5afb.  In any case, two more pallocs during a planner run are
      surely at the noise level (a conclusion confirmed by a bit of
      microbenchmarking).  So let's change this decision before it becomes
      set in stone, and insist that IndexClause.indexquals always be a valid
      list of the actual index quals for the clause.
      
      Discussion: https://postgr.es/m/24586.1550106354@sss.pgh.pa.us
      8fd3fdd8
  7. 14 Feb, 2019 2 commits