1. 10 Nov, 2016 3 commits
    • Tom Lane's avatar
      Support "COPY view FROM" for views with INSTEAD OF INSERT triggers. · 279c439c
      Tom Lane authored
      We just pass the data to the INSTEAD trigger.
      
      Haribabu Kommi, reviewed by Dilip Kumar
      
      Patch: <CAJrrPGcSQkrNkO+4PhLm4B8UQQQmU9YVUuqmtgM=pmzMfxWaWQ@mail.gmail.com>
      279c439c
    • Tom Lane's avatar
      Fix partial aggregation for the case of a degenerate GROUP BY clause. · e1b449be
      Tom Lane authored
      The plan generated for sorted partial aggregation with "GROUP BY constant"
      included a Sort node with no sort keys, which the executor does not like.
      
      Per report from Steve Randall.  I'd add a regression test case if I could
      think of a compact one, but it doesn't seem worth expending lots of cycles
      on.
      
      Report: <CABVd52UAdGXpg_rCk46egpNKYdXOzCjuJ1zG26E2xBe_8bj+Fg@mail.gmail.com>
      e1b449be
    • Tom Lane's avatar
      Doc: improve link. · 0b1b5033
      Tom Lane authored
      Discussion: <5019.1478790246@sss.pgh.pa.us>
      0b1b5033
  2. 09 Nov, 2016 2 commits
  3. 08 Nov, 2016 11 commits
    • Tom Lane's avatar
      Simplify code by getting rid of SPI_push, SPI_pop, SPI_restore_connection. · 1833f1a1
      Tom Lane authored
      The idea behind SPI_push was to allow transitioning back into an
      "unconnected" state when a SPI-using procedure calls unrelated code that
      might or might not invoke SPI.  That sounds good, but in practice the only
      thing it does for us is to catch cases where a called SPI-using function
      forgets to call SPI_connect --- which is a highly improbable failure mode,
      since it would be exposed immediately by direct testing of said function.
      As against that, we've had multiple bugs induced by forgetting to call
      SPI_push/SPI_pop around code that might invoke SPI-using functions; these
      are much harder to catch and indeed have gone undetected for years in some
      cases.  And we've had to band-aid around some problems of this ilk by
      introducing conditional push/pop pairs in some places, which really kind
      of defeats the purpose altogether; if we can't draw bright lines between
      connected and unconnected code, what's the point?
      
      Hence, get rid of SPI_push[_conditional], SPI_pop[_conditional], and the
      underlying state variable _SPI_curid.  It turns out SPI_restore_connection
      can go away too, which is a nice side benefit since it was never more than
      a kluge.  Provide no-op macros for the deleted functions so as to avoid an
      API break for external modules.
      
      A side effect of this removal is that SPI_palloc and allied functions no
      longer permit being called when unconnected; they'll throw an error
      instead.  The apparent usefulness of the previous behavior was a mirage
      as well, because it was depended on by only a few places (which I fixed in
      preceding commits), and it posed a risk of allocations being unexpectedly
      long-lived if someone forgot a SPI_push call.
      
      Discussion: <20808.1478481403@sss.pgh.pa.us>
      1833f1a1
    • Robert Haas's avatar
      psql: Tab completion for renaming enum values. · 577f0bdd
      Robert Haas authored
      For ALTER TYPE .. RENAME, add "VALUE" to the list of possible
      completions.  Complete ALTER TYPE .. RENAME VALUE with possible
      enum values.  After that, complete with "TO".
      
      Dagfinn Ilmari Mannsåker, reviewed by Artur Zakirov.
      577f0bdd
    • Tom Lane's avatar
      Replace uses of SPI_modifytuple that intend to allocate in current context. · 9257f078
      Tom Lane authored
      Invent a new function heap_modify_tuple_by_cols() that is functionally
      equivalent to SPI_modifytuple except that it always allocates its result
      by simple palloc.  I chose however to make the API details a bit more
      like heap_modify_tuple: pass a tupdesc rather than a Relation, and use
      bool convention for the isnull array.
      
      Use this function in place of SPI_modifytuple at all call sites where the
      intended behavior is to allocate in current context.  (There actually are
      only two call sites left that depend on the old behavior, which makes me
      wonder if we should just drop this function rather than keep it.)
      
      This new function is easier to use than heap_modify_tuple() for purposes
      of replacing a single column (or, really, any fixed number of columns).
      There are a number of places where it would simplify the code to change
      over, but I resisted that temptation for the moment ... everywhere except
      in plpgsql's exec_assign_value(); changing that might offer some small
      performance benefit, so I did it.
      
      This is on the way to removing SPI_push/SPI_pop, but it seems like
      good code cleanup in its own right.
      
      Discussion: <9633.1478552022@sss.pgh.pa.us>
      9257f078
    • Robert Haas's avatar
      Fix typo. · dce429b1
      Robert Haas authored
      Michael Paquier
      dce429b1
    • Tom Lane's avatar
      Make SPI_fnumber() reject dropped columns. · 6d30fb1f
      Tom Lane authored
      There's basically no scenario where it's sensible for this to match
      dropped columns, so put a test for dropped-ness into SPI_fnumber()
      itself, and excise the test from the small number of callers that
      were paying attention to the case.  (Most weren't :-(.)
      
      In passing, normalize tests at call sites: always reject attnum <= 0
      if we're disallowing system columns.  Previously there was a mixture
      of "< 0" and "<= 0" tests.  This makes no practical difference since
      SPI_fnumber() never returns 0, but I'm feeling pedantic today.
      
      Also, in the places that are actually live user-facing code and not
      legacy cruft, distinguish "column not found" from "can't handle
      system column".
      
      Per discussion with Jim Nasby; thi supersedes his original patch
      that just changed the behavior at one call site.
      
      Discussion: <b2de8258-c4c0-1cb8-7b97-e8538e5c975c@BlueTreble.com>
      6d30fb1f
    • Magnus Hagander's avatar
      Fix typo · 36ac6d0e
      Magnus Hagander authored
      36ac6d0e
    • Robert Haas's avatar
      Fix mistake in XLOG_SEG_SIZE test. · 60379f66
      Robert Haas authored
      The intent of the test is to check whether XLOG_SEG_SIZE is in a
      particular range, but actually in one case it compares XLOG_BLCKSZ
      by mistake.  Repair.
      
      Commit 88e98230 introduced this
      faulty test.
      
      Kuntal Ghosh, reviewed by Michael Paquier.
      60379f66
    • Tom Lane's avatar
      Use heap_modify_tuple not SPI_modifytuple in pl/python triggers. · de4026c6
      Tom Lane authored
      The code here would need some change anyway given planned change in
      SPI_modifytuple semantics, since this executes after we've exited the
      SPI environment.  But really it's better to just use heap_modify_tuple.
      
      While at it, normalize use of SPI_fnumber: make error messages distinguish
      no-such-column from can't-set-system-column, and remove test for deleted
      column which is going to migrate into SPI_fnumber.  The lack of a check
      for system column names is actually a pre-existing bug here, and might
      even qualify as a security bug except that we don't have any trusted
      version of plpython.
      de4026c6
    • Tom Lane's avatar
      Use heap_modify_tuple not SPI_modifytuple in pl/perl triggers. · 0d444608
      Tom Lane authored
      The code here would need some change anyway given planned change in
      SPI_modifytuple semantics, since this executes after we've exited the
      SPI environment.  But really it's better to just use heap_modify_tuple.
      The code's actually shorter this way, and this avoids depending on some
      rather indirect reasoning about why the temporary arrays can't be overrun.
      (I think the old code is safe, as long as Perl hashes can't contain
      duplicate keys; but with this way we don't need that assumption, only
      the assumption that SPI_fnumber doesn't return an out-of-range attnum.)
      
      While at it, normalize use of SPI_fnumber: make error messages distinguish
      no-such-column from can't-set-system-column, and remove test for deleted
      column which is going to migrate into SPI_fnumber.
      0d444608
    • Robert Haas's avatar
      Improve handling of dead tuples in hash indexes. · f0e72a25
      Robert Haas authored
      When squeezing a bucket during vacuum, it's not necessary to retain
      any tuples already marked as dead, so ignore them when deciding which
      tuples must be moved in order to empty a bucket page.  Similarly, when
      splitting a bucket, relocating dead tuples to the new bucket is a
      waste of effort; instead, just ignore them.
      
      Amit Kapila, reviewed by me.  Testing help provided by Ashutosh
      Sharma.
      f0e72a25
    • Noah Misch's avatar
      Change qr/foo$/m to qr/foo\n/m, for Perl 5.8.8. · 650b9670
      Noah Misch authored
      In each case, absence of a trailing newline would itself constitute a
      PostgreSQL bug.  Therefore, this slightly enhances the changed tests.
      This works around a bug that last appeared in Perl 5.8.8, fixing
      src/test/modules/test_pg_dump when run against that version.  Commit
      e7293e32 worked around the bug, but the
      subsequent addition of test_pg_dump introduced affected code.  As that
      commit had shown, slight increases in pattern complexity can suppress
      the bug.  This commit edits qr/foo$/m patterns too complex to encounter
      the bug today, for style consistency and robustness against unrelated
      pattern changes.  Back-patch to 9.6, where test_pg_dump was introduced.
      
      As of this writing, a fresh MSYS installation includes an affected Perl
      5.8.8.  The Perl 5.8.8 in Red Hat Enterprise Linux 5.11 carries a patch
      that renders it unaffected, but the Perl 5.8.5 of Red Hat Enterprise
      Linux 4.4 is affected.
      650b9670
  4. 07 Nov, 2016 7 commits
  5. 06 Nov, 2016 6 commits
    • Tom Lane's avatar
      Support PL/Tcl functions that return composite types and/or sets. · 26abb50c
      Tom Lane authored
      Jim Nasby, rather heavily editorialized by me
      
      Patch: <f2134651-14b3-efeb-f274-c69f3c084031@BlueTreble.com>
      26abb50c
    • Tom Lane's avatar
      Modernize result-tuple construction in pltcl_trigger_handler(). · 2178cbf4
      Tom Lane authored
      Use Tcl_ListObjGetElements instead of Tcl_SplitList.  Aside from being
      possibly more efficient in its own right, this means we are no longer
      responsible for freeing a malloc'd result array, so we can get rid of
      a PG_TRY/PG_CATCH block.
      
      Use heap_form_tuple instead of SPI_modifytuple.  We don't need the
      extra generality of the latter, since we're always replacing all
      columns.  Nor do we need its memory-context-munging, since at this
      point we're already out of the SPI environment.
      
      Per comparison of this code to tuple-building code submitted by Jim Nasby.
      I've abandoned the thought of merging the two cases into a single routine,
      but we may as well make the older code simpler and faster where we can.
      2178cbf4
    • Tom Lane's avatar
      Rationalize and document pltcl's handling of magic ".tupno" array element. · fd2664dc
      Tom Lane authored
      For a very long time, pltcl's spi_exec and spi_execp commands have had
      a behavior of storing the current row number as an element of output
      arrays, but this was never documented.  Fix that.
      
      For an equally long time, pltcl_trigger_handler had a behavior of silently
      ignoring ".tupno" as an output column name, evidently so that the result
      of spi_exec could be used directly as a trigger result tuple.  Not sure
      how useful that really is, but in any case it's bad that it would break
      attempts to use ".tupno" as an actual column name.  We can fix it by not
      checking for ".tupno" until after we check for a column name match.  This
      comports with the effective behavior of spi_exec[p] that ".tupno" is only
      magic when you don't have an actual column named that.
      
      In passing, wordsmith the description of returning modified tuples from
      a pltcl trigger.
      
      Noted while working on Jim Nasby's patch to support composite results
      from pltcl.  The inability to return trigger tuples using ".tupno" as
      a column name is a bug, so back-patch to all supported branches.
      fd2664dc
    • Tom Lane's avatar
      Need to do SPI_push/SPI_pop around expression evaluation in plpgsql. · fc8b81a2
      Tom Lane authored
      We must do this in case the expression evaluation results in calling
      another plpgsql function (or, really, anything using SPI).  I missed
      the need for this when I converted exec_cast_value() from doing a
      simple InputFunctionCall() to doing ExecEvalExpr() in commit 1345cc67.
      There is a SPI_push_conditional in InputFunctionCall(), so that there
      was no bug before that.
      
      Per bug #14414 from Marcos Castedo.  Add a regression test based on his
      example, which was that a plpgsql function in a domain check constraint
      didn't work when assigning to a domain-type variable within plpgsql.
      
      Report: <20161106010947.1387.66380@wrigleys.postgresql.org>
      fc8b81a2
    • Tom Lane's avatar
      Fix silly nil-pointer-dereference bug introduced in commit d5f6f13f. · 5485c99e
      Tom Lane authored
      Don't fetch record->xl_info before we've verified that record isn't
      NULL.  Per Coverity.
      
      Michael Paquier
      5485c99e
    • Tom Lane's avatar
      More zic cleanup. · 32416b0f
      Tom Lane authored
      The workaround the IANA guys chose to get rid of the clang warning
      we'd silenced in commit 23ed2ba8 turns out not to satisfy Coverity.
      Go back to the previous solution, ie, remove the useless comparison
      to SIZE_MAX.  (In principle, there could be machines out there where
      it's not useless because ptrdiff_t is wider than size_t.  But the whole
      thing is pretty academic anyway, as we could never approach this limit
      for any sane estimate of the amount of data that zic will ever be asked
      to work with.)
      
      Also, s/lineno/lineno_t/g, because if we accept their decision to start
      using "lineno" as a typedef, it is going to have very unpleasant
      consequences in our next pgindent run.  Noted that while fooling with
      pltcl yesterday.
      32416b0f
  6. 05 Nov, 2016 6 commits
    • Tom Lane's avatar
      Improve minor error-handling details in pltcl. · 1b00dd0e
      Tom Lane authored
      Don't ask Tcl_GetIndexFromObj to store an error message in the interpreter
      in cases where the next argument isn't necessarily one of the options
      we're asking it to check for.  At best that is a waste of time, and at
      worst it might cause an inappropriate error result to get left behind.
      
      Be sure to check for valid syntax (ie, no command arguments) in
      pltcl_SPI_lastoid.
      
      Extracted from a larger and otherwise-unrelated patch.
      
      Jim Nasby
      
      Patch: <f2134651-14b3-efeb-f274-c69f3c084031@BlueTreble.com>
      1b00dd0e
    • Tom Lane's avatar
      Adjust cost_merge_append() to reflect use of binaryheap_replace_first(). · 34ca0905
      Tom Lane authored
      Commit 7a2fe9bd improved merge append so that replacement of a tuple
      takes log(N) operations, not twice log(N).  Since cost_merge_append knew
      about that explicitly, we should adjust it.  This probably makes little
      difference in practice, but the obsolete comment is confusing.
      
      Ideally this would have been put in in 9.3 with the underlying behavior
      change; but I'm not going to back-patch it, since there's some small chance
      of changing a plan choice that somebody's optimized for.
      
      Thomas Munro
      
      Discussion: <CAEepm=0WQBSvuYcMOUj4Ga4NXpu2J=ejZcE=e=eiTjTX-6_gDw@mail.gmail.com>
      34ca0905
    • Tom Lane's avatar
      Remove duplicate macro definition. · 86d19d27
      Tom Lane authored
      Seems to be a copy-and-pasteo.  Odd that we heard no reports of
      compiler warnings about it.
      
      Thomas Munro
      86d19d27
    • Tom Lane's avatar
      pgwin32_is_junction's argument should be "const char *" not "char *". · 06f5fd2f
      Tom Lane authored
      We're passing const strings to it in places, and that's not an
      unreasonable thing to do.  Per buildfarm (noted on frogmouth
      in particular).
      06f5fd2f
    • Peter Eisentraut's avatar
      doc: Don't reformat .fo files before processing by fop · d49cc588
      Peter Eisentraut authored
      This messes up the whitespace in the output PDF document in some places.
      d49cc588
    • Peter Eisentraut's avatar
      6feb69f6
  7. 04 Nov, 2016 5 commits
    • Tom Lane's avatar
      Provide DLLEXPORT markers for C functions via PG_FUNCTION_INFO_V1 macro. · c8ead2a3
      Tom Lane authored
      Second try at the change originally made in commit 8518583c;
      this time with contrib updates so that manual extern declarations
      are also marked with PGDLLEXPORT.  The release notes should point
      this out as a significant source-code change for extension authors,
      since they'll have to make similar additions to avoid trouble on Windows.
      
      Laurenz Albe, doc change by me
      
      Patch: <A737B7A37273E048B164557ADEF4A58B53962ED8@ntex2010a.host.magwien.gv.at>
      c8ead2a3
    • Tom Lane's avatar
      Delete contrib/xml2's legacy implementation of xml_is_well_formed(). · 20540710
      Tom Lane authored
      This function is unreferenced in modern usage; it was superseded in 9.1
      by a core function of the same name.  It has been left in place in the C
      code only so that pre-9.1 SQL definitions of the contrib/xml2 functions
      would continue to work.  Six years seems like enough time for people to
      have updated to the extension-style version of the xml2 module, so let's
      drop this.
      
      The key reason for not keeping it any longer is that we want to stick
      an explicit PGDLLEXPORT into PG_FUNCTION_INFO_V1(), and the similarity
      of name to the core function creates a conflict that compilers will
      complain about.
      
      Extracted from a larger patch for that purpose.  I'm committing this
      change separately to give it more visibility in the commit logs.
      
      While at it, remove the documentation entry that claimed that
      xml_is_well_formed() is a function provided by contrib/xml2, and
      instead mention the even more ancient alias xml_valid().
      
      Laurenz Albe, doc change by me
      
      Patch: <A737B7A37273E048B164557ADEF4A58B53962ED8@ntex2010a.host.magwien.gv.at>
      20540710
    • Tom Lane's avatar
      Be more consistent about masking xl_info with ~XLR_INFO_MASK. · d5f6f13f
      Tom Lane authored
      Generally, WAL resource managers are only supposed to examine the
      top 4 bits of a WAL record's xl_info; the rest are reserved for
      the WAL mechanism itself.  A few places were not consistent about
      doing this with respect to XLOG_CHECKPOINT and XLOG_SWITCH records.
      There's no bug currently, since no additional bits ever get set in
      these specific record types, but that might not be true forever.
      Let's follow the generic coding rule here too.
      
      Michael Paquier
      d5f6f13f
    • Tom Lane's avatar
      Fix gin_leafpage_items(). · 367b99bb
      Tom Lane authored
      On closer inspection, commit 84ad68d6 broke gin_leafpage_items(),
      because the aligned copy of the page got palloc'd in a short-lived
      context whereas it needs to be in the SRF's multi_call_memory_ctx.
      This was not exposed by the regression test, because the regression
      test doesn't actually exercise the function in a meaningful way.
      Fix the code bug, and extend the test in what I hope is a portable
      fashion.
      367b99bb
    • Kevin Grittner's avatar
      Improve tab completion for CREATE TRIGGER. · 927d7bb6
      Kevin Grittner authored
      This includes support for the new REFERENCING clause.
      927d7bb6