1. 24 Jan, 2016 2 commits
  2. 23 Jan, 2016 4 commits
    • Tom Lane's avatar
      Still further adjust degree-based trig functions for more portability. · 360f67d3
      Tom Lane authored
      Indeed, the non-static declaration foreseen in my previous commit message
      is necessary.  Per Noah Misch.
      360f67d3
    • Tom Lane's avatar
      Further adjust degree-based trig functions for more portability. · 65abaab5
      Tom Lane authored
      The last round didn't do it.  Per Noah Misch, the problem on at least
      some machines is that the compiler pre-evaluates trig functions having
      constant arguments using code slightly different from what will be used
      at runtime.  Therefore, we must prevent the compiler from seeing constant
      arguments to any of the libm trig functions used in this code.
      
      The method used here might still fail if init_degree_constants() gets
      inlined into the call sites.  That probably won't happen given the large
      number of call sites; but if it does, we could probably fix it by making
      init_degree_constants() non-static.  I'll avoid that till proven
      necessary, though.
      65abaab5
    • Tom Lane's avatar
      Adjust degree-based trig functions for more portability. · 73193d82
      Tom Lane authored
      The buildfarm isn't very happy with the results of commit e1bd684a.
      To try to get the expected exact results everywhere:
      
      * Replace M_PI / 180 subexpressions with a precomputed constant, so that
      the compiler can't decide to rearrange that division with an adjacent
      operation.  Hopefully this will fix failures to get exactly 0.5 from
      sind(30) and cosd(60).
      
      * Add scaling to ensure that tand(45) and cotd(45) give exactly 1; there
      was nothing particularly guaranteeing that before.
      
      * Replace minus zero by zero when tand() or cotd() would output that;
      many machines did so for tand(180) and cotd(270), but not all.  We could
      alternatively deem both results valid, but that doesn't seem likely to
      be what users will want.
      73193d82
    • Peter Eisentraut's avatar
      psql: Improve completion of FDW DDL commands · 6ae4c8de
      Peter Eisentraut authored
      Add
      - ALTER FOREIGN DATA WRAPPER -> RENAME TO
      - ALTER SERVER -> RENAME TO
      - ALTER SERVER ... VERSION ... -> OPTIONS
      - CREATE FOREIGN DATA WRAPPER -> OPTIONS
      - CREATE SERVER -> OPTIONS
      - CREATE|ALTER USER MAPPING -> OPTIONS
      
      From: Andreas Karlsson <andreas@proxel.se>
      6ae4c8de
  3. 22 Jan, 2016 8 commits
    • Alvaro Herrera's avatar
      pg_dump: Fix quoting of domain constraint names · df43fcf4
      Alvaro Herrera authored
      The original code was adding double quotes to an already-quoted
      identifier, leading to nonsensical results.  Remove the quoting call.
      
      I introduced the broken code in 7eca575d of 9.5 era, so backpatch to
      9.5.
      
      Report and patch by Elvis Pranskevichus
      Reviewed by Michael Paquier
      df43fcf4
    • Tom Lane's avatar
      Add trigonometric functions that work in degrees. · e1bd684a
      Tom Lane authored
      The implementations go to some lengths to deliver exact results for values
      where an exact result can be expected, such as sind(30) = 0.5 exactly.
      
      Dean Rasheed, reviewed by Michael Paquier
      e1bd684a
    • Tom Lane's avatar
      Improve cross-platform consistency of Inf/NaN handling in trig functions. · fd5200c3
      Tom Lane authored
      Ensure that the trig functions return NaN for NaN input regardless of what
      the underlying C library functions might do.  Also ensure that an error
      is thrown for Inf (or otherwise out-of-range) input, except for atan/atan2
      which should accept it.
      
      All these behaviors should now conform to the POSIX spec; previously, all
      our popular platforms deviated from that in one case or another.
      
      The main remaining platform dependency here is whether the C library might
      choose to throw a domain error for sin/cos/tan inputs that are large but
      less than infinity.  (Doing so is not unreasonable, since once a single
      unit-in-the-last-place exceeds PI, there can be no significance at all in
      the result; however there doesn't seem to be any suggestion in POSIX that
      such an error is allowed.)  We will report such errors if they are reported
      via "errno", but not if they are reported via "fetestexcept" which is the
      other mechanism sanctioned by POSIX.  Some preliminary experiments with
      fetestexcept indicated that it might also report errors we could do
      without, such as complaining about underflow at an unreasonably large
      threshold.  So let's skip that complexity for now.
      
      Dean Rasheed, reviewed by Michael Paquier
      fd5200c3
    • Tom Lane's avatar
      Improve levenshtein() docs. · 80aa2191
      Tom Lane authored
      Fix chars-vs-bytes confusion here too.  Improve poor grammar and
      markup.
      80aa2191
    • Tom Lane's avatar
      Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN. · a396144a
      Tom Lane authored
      Commit e529cd4f introduced an Assert requiring NAMEDATALEN to be
      less than MAX_LEVENSHTEIN_STRLEN, which has been 255 for a long time.
      Since up to that instant we had always allowed NAMEDATALEN to be
      substantially more than that, this was ill-advised.
      
      It's debatable whether we need MAX_LEVENSHTEIN_STRLEN at all (versus
      putting a CHECK_FOR_INTERRUPTS into the loop), or whether it has to be
      so tight; but this patch takes the narrower approach of just not applying
      the MAX_LEVENSHTEIN_STRLEN limit to calls from the parser.
      
      Trusting the parser for this seems reasonable, first because the strings
      are limited to NAMEDATALEN which is unlikely to be hugely more than 256,
      and second because the maximum distance is tightly constrained by
      MAX_FUZZY_DISTANCE (though we'd forgotten to make use of that limit in one
      place).  That means the cost is not really O(mn) but more like O(max(m,n)).
      
      Relaxing the limit for user-supplied calls is left for future research;
      given the lack of complaints to date, it doesn't seem very high priority.
      
      In passing, fix confusion between lengths-in-bytes and lengths-in-chars
      in comments and error messages.
      
      Per gripe from Kevin Day; solution suggested by Robert Haas.  Back-patch
      to 9.5 where the unwanted restriction was introduced.
      a396144a
    • Tom Lane's avatar
      Make extract() do something more reasonable with infinite datetimes. · 647d87c5
      Tom Lane authored
      Historically, extract() just returned zero for any case involving an
      infinite timestamp[tz] input; even cases in which the unit name was
      invalid.  This is not very sensible.  Instead, return infinity or
      -infinity as appropriate when the requested field is one that is
      monotonically increasing (e.g, year, epoch), or NULL when it is not
      (e.g., day, hour).  Also, throw the expected errors for bad unit names.
      
      BACKWARDS INCOMPATIBLE CHANGE
      
      Vitaly Burovoy, reviewed by Vik Fearing
      647d87c5
    • Tom Lane's avatar
      Suppress compiler warning. · d9b9289c
      Tom Lane authored
      Given the limited range of i, these shifts should not cause any
      problem, but that apparently doesn't stop some compilers from
      whining about them.
      
      David Rowley
      d9b9289c
    • Tom Lane's avatar
      Improve index AMs' opclass validation procedures. · be44ed27
      Tom Lane authored
      The amvalidate functions added in commit 65c5fcd3 were on the
      crude side.  Improve them in a few ways:
      
      * Perform signature checking for operators and support functions.
      
      * Apply more thorough checks for missing operators and functions,
      where possible.
      
      * Instead of reporting problems as ERRORs, report most problems as INFO
      messages and make the amvalidate function return FALSE.  This allows
      more than one problem to be discovered per run.
      
      * Report object names rather than OIDs, and work a bit harder on making
      the messages understandable.
      
      Also, remove a few more opr_sanity regression test queries that are
      now superseded by the amvalidate checks.
      be44ed27
  4. 21 Jan, 2016 6 commits
    • Tom Lane's avatar
      Add defenses against putting expanded objects into Const nodes. · b9955183
      Tom Lane authored
      Putting a reference to an expanded-format value into a Const node would be
      a bad idea for a couple of reasons.  It'd be possible for the supposedly
      immutable Const to change value, if something modified the referenced
      variable ... in fact, if the Const's reference were R/W, any function that
      has the Const as argument might itself change it at runtime.  Also, because
      datumIsEqual() is pretty simplistic, the Const might fail to compare equal
      to other Consts that it should compare equal to, notably including copies
      of itself.  This could lead to unexpected planner behavior, such as "could
      not find pathkey item to sort" errors or inferior plans.
      
      I have not been able to find any way to get an expanded value into a Const
      within the existing core code; but Paul Ramsey was able to trigger the
      problem by writing a datatype input function that returns an expanded
      value.
      
      The best fix seems to be to establish a rule that varlena values being
      placed into Const nodes should be passed through pg_detoast_datum().
      That will do nothing (and cost little) in normal cases, but it will flatten
      expanded values and thereby avoid the above problems.  Also, it will
      convert short-header or compressed values into canonical format, which will
      avoid possible unexpected lack-of-equality issues for those cases too.
      And it provides a last-ditch defense against putting a toasted value into
      a Const, which we already knew was dangerous, cf commit 2b0c86b6.
      (In the light of this discussion, I'm no longer sure that that commit
      provided 100% protection against such cases, but this fix should do it.)
      
      The test added in commit 65c3d05e to catch datatype input functions
      with unstable results would fail for functions that returned expanded
      values; but it seems a bit uncharitable to deem a result unstable just
      because it's expressed in expanded form, so revise the coding so that we
      check for bitwise equality only after applying pg_detoast_datum().  That's
      a sufficient condition anyway given the new rule about detoasting when
      forming a Const.
      
      Back-patch to 9.5 where the expanded-object facility was added.  It's
      possible that this should go back further; but in the absence of clear
      evidence that there's any live bug in older branches, I'll refrain for now.
      b9955183
    • Fujii Masao's avatar
      Remove unused argument from ginInsertCleanup() · 38710a37
      Fujii Masao authored
      It's an oversight in commit dc943ad9.
      38710a37
    • Simon Riggs's avatar
      Refactor headers to split out standby defs · c80b31d5
      Simon Riggs authored
      Jeff Janes
      c80b31d5
    • Simon Riggs's avatar
      Speedup 2PC by skipping two phase state files in normal path · 978b2f65
      Simon Riggs authored
      2PC state info is written only to WAL at PREPARE, then read back from WAL at
      COMMIT PREPARED/ABORT PREPARED. Prepared transactions that live past one bufmgr
      checkpoint cycle will be written to disk in the same form as previously. Crash
      recovery path is not altered. Measured performance gains of 50-100% for short
      2PC transactions by completely avoiding writing files and fsyncing. Other
      optimizations still available, further patches in related areas expected.
      
      Stas Kelvich and heavily edited by Simon Riggs
      
      Based upon earlier ideas and patches by Michael Paquier and Heikki Linnakangas,
      a concrete example of how Postgres-XC has fed back ideas into PostgreSQL.
      
      Reviewed by Michael Paquier, Jeff Janes and Andres Freund
      Performance testing by Jesper Pedersen
      978b2f65
    • Peter Eisentraut's avatar
      psql: Add tab completion for COPY with query · d0f2f53c
      Peter Eisentraut authored
      From: Andreas Karlsson <andreas@proxel.se>
      d0f2f53c
    • Simon Riggs's avatar
      Refactor to create generic WAL page read callback · 422a55a6
      Simon Riggs authored
      Previously we didn’t have a generic WAL page read callback function,
      surprisingly. Logical decoding has logical_read_local_xlog_page(), which was
      actually generic, so move that to xlogfunc.c and rename to
      read_local_xlog_page().
      Maintain logical_read_local_xlog_page() so existing callers still work.
      
      As requested by Michael Paquier, Alvaro Herrera and Andres Freund
      422a55a6
  5. 20 Jan, 2016 5 commits
    • Robert Haas's avatar
      Support parallel joins, and make related improvements. · 45be99f8
      Robert Haas authored
      The core innovation of this patch is the introduction of the concept
      of a partial path; that is, a path which if executed in parallel will
      generate a subset of the output rows in each process.  Gathering a
      partial path produces an ordinary (complete) path.  This allows us to
      generate paths for parallel joins by joining a partial path for one
      side (which at the baserel level is currently always a Partial Seq
      Scan) to an ordinary path on the other side.  This is subject to
      various restrictions at present, especially that this strategy seems
      unlikely to be sensible for merge joins, so only nested loops and
      hash joins paths are generated.
      
      This also allows an Append node to be pushed below a Gather node in
      the case of a partitioned table.
      
      Testing revealed that early versions of this patch made poor decisions
      in some cases, which turned out to be caused by the fact that the
      original cost model for Parallel Seq Scan wasn't very good.  So this
      patch tries to make some modest improvements in that area.
      
      There is much more to be done in the area of generating good parallel
      plans in all cases, but this seems like a useful step forward.
      
      Patch by me, reviewed by Dilip Kumar and Amit Kapila.
      45be99f8
    • Robert Haas's avatar
      Support multi-stage aggregation. · a7de3dc5
      Robert Haas authored
      Aggregate nodes now have two new modes: a "partial" mode where they
      output the unfinalized transition state, and a "finalize" mode where
      they accept unfinalized transition states rather than individual
      values as input.
      
      These new modes are not used anywhere yet, but they will be necessary
      for parallel aggregation.  The infrastructure also figures to be
      useful for cases where we want to aggregate local data and remote
      data via the FDW interface, and want to bring back partial aggregates
      from the remote side that can then be combined with locally generated
      partial aggregates to produce the final value.  It may also be useful
      even when neither FDWs nor parallelism are in play, as explained in
      the comments in nodeAgg.c.
      
      David Rowley and Simon Riggs, reviewed by KaiGai Kohei, Heikki
      Linnakangas, Haribabu Kommi, and me.
      a7de3dc5
    • Alvaro Herrera's avatar
      PostgresNode: Add names to nodes · c8642d90
      Alvaro Herrera authored
      This makes the log files easier to follow when investigating a test
      failure.
      
      Author: Michael Paquier
      Review: Noah Misch
      c8642d90
    • Bruce Momjian's avatar
      Properly install dynloader.h on MSVC builds · 216d5684
      Bruce Momjian authored
      This will enable PL/Java to be cleanly compiled, as dynloader.h is a
      requirement.
      
      Report by Chapman Flack
      
      Patch by Michael Paquier
      
      Backpatch through 9.1
      216d5684
    • Tom Lane's avatar
      Fix assorted inconsistencies in GIN opclass support function declarations. · dbe23289
      Tom Lane authored
      GIN had some minor issues too, mostly using "internal" where something
      else would be more appropriate.  I went with the same approach as in
      9ff60273, namely preferring the opclass' indexed datatype for
      arguments that receive an operator RHS value, even if that's not
      necessarily what they really are.
      
      Again, this is with an eye to having a uniform rule for ginvalidate()
      to check support function signatures.
      dbe23289
  6. 19 Jan, 2016 3 commits
    • Alvaro Herrera's avatar
      Add two HyperLogLog functions · 948c9795
      Alvaro Herrera authored
      New functions initHyperLogLogError() and freeHyperLogLog() simplify
      using this module from elsewhere.
      
      Author: Tomáš Vondra
      Review: Peter Geoghegan
      948c9795
    • Tom Lane's avatar
      Fix assorted inconsistencies in GiST opclass support function declarations. · 9ff60273
      Tom Lane authored
      The conventions specified by the GiST SGML documentation were widely
      ignored.  For example, the strategy-number argument for "consistent" and
      "distance" functions is specified to be a smallint, but most of the
      built-in support functions declared it as an integer, and for that matter
      the core code passed it using Int32GetDatum not Int16GetDatum.  None of
      that makes any real difference at runtime, but it's quite confusing for
      newcomers to the code, and it makes it very hard to write an amvalidate()
      function that checks support function signatures.  So let's try to instill
      some consistency here.
      
      Another similar issue is that the "query" argument is not of a single
      well-defined type, but could have different types depending on the strategy
      (corresponding to search operators with different righthand-side argument
      types).  Some of the functions threw up their hands and declared the query
      argument as being of "internal" type, which surely isn't right ("any" would
      have been more appropriate); but the majority position seemed to be to
      declare it as being of the indexed data type, corresponding to a search
      operator with both input types the same.  So I've specified a convention
      that that's what to do always.
      
      Also, the result of the "union" support function actually must be of the
      index's storage type, but the documentation suggested declaring it to
      return "internal", and some of the functions followed that.  Standardize
      on telling the truth, instead.
      
      Similarly, standardize on declaring the "same" function's inputs as
      being of the storage type, not "internal".
      
      Also, somebody had forgotten to add the "recheck" argument to both
      the documentation of the "distance" support function and all of their
      SQL declarations, even though the C code was happily using that argument.
      Clean that up too.
      
      Fix up some other omissions in the docs too, such as documenting that
      union's second input argument is vestigial.
      
      So far as the errors in core function declarations go, we can just fix
      pg_proc.h and bump catversion.  Adjusting the erroneous declarations in
      contrib modules is more debatable: in principle any change in those
      scripts should involve an extension version bump, which is a pain.
      However, since these changes are purely cosmetic and make no functional
      difference, I think we can get away without doing that.
      9ff60273
    • Andrew Dunstan's avatar
      Remove Cygwin-specific code from pg_ctl · 53c949c1
      Andrew Dunstan authored
      This code has been there for a long time, but it's never really been
      needed. Cygwin has its own utility for registering, unregistering,
      stopping and starting Windows services, and that's what's used in the
      Cygwin postgres packages. So now pg_ctl for Cygwin looks like it is for
      any Unix platform.
      
      Michael Paquier and me
      53c949c1
  7. 18 Jan, 2016 4 commits
    • Tatsuo Ishii's avatar
      Fix typo. · 85f22281
      Tatsuo Ishii authored
      Reported by KOIZUMI Satoru.
      85f22281
    • Tom Lane's avatar
      Add explicit cast to amcostestimate call. · 49b49506
      Tom Lane authored
      My compiler doesn't complain here, but David Rowley's does ...
      49b49506
    • Tom Lane's avatar
      Restructure index access method API to hide most of it at the C level. · 65c5fcd3
      Tom Lane authored
      This patch reduces pg_am to just two columns, a name and a handler
      function.  All the data formerly obtained from pg_am is now provided
      in a C struct returned by the handler function.  This is similar to
      the designs we've adopted for FDWs and tablesample methods.  There
      are multiple advantages.  For one, the index AM's support functions
      are now simple C functions, making them faster to call and much less
      error-prone, since the C compiler can now check function signatures.
      For another, this will make it far more practical to define index access
      methods in installable extensions.
      
      A disadvantage is that SQL-level code can no longer see attributes
      of index AMs; in particular, some of the crosschecks in the opr_sanity
      regression test are no longer possible from SQL.  We've addressed that
      by adding a facility for the index AM to perform such checks instead.
      (Much more could be done in that line, but for now we're content if the
      amvalidate functions more or less replace what opr_sanity used to do.)
      We might also want to expose some sort of reporting functionality, but
      this patch doesn't do that.
      
      Alexander Korotkov, reviewed by Petr Jelínek, and rather heavily
      editorialized on by me.
      65c5fcd3
    • Tom Lane's avatar
      Re-pgindent a few files. · 8d290c8e
      Tom Lane authored
      In preparation for landing index AM interface changes.
      8d290c8e
  8. 17 Jan, 2016 2 commits
    • Tom Lane's avatar
      Remove dead code in pg_dump. · 57ce9acc
      Tom Lane authored
      Coverity quite reasonably complained that this check for fout==NULL
      occurred after we'd already dereferenced fout.  However, the check
      is just dead code since there is no code path by which CreateArchive
      can return a null pointer.  Errors such as can't-open-that-file are
      reported down inside CreateArchive, and control doesn't return.
      So let's silence the warning by removing the dead code, rather than
      continuing to pretend it does something.
      
      Coverity didn't complain about this before 5b5fea2a, so back-patch
      to 9.5 like that patch.
      57ce9acc
    • Peter Eisentraut's avatar
      psql: Add completion support for DROP INDEX CONCURRENTLY · 4189e3d6
      Peter Eisentraut authored
      based on patch by Kyotaro Horiguchi
      4189e3d6
  9. 15 Jan, 2016 2 commits
  10. 14 Jan, 2016 2 commits
    • Tom Lane's avatar
      Fix build_grouping_chain() to not clobber its input lists. · a923af38
      Tom Lane authored
      There's no good reason for stomping on the input data; it makes the logic
      in this function no simpler, in fact probably the reverse.  And it makes
      it impossible to separate path generation from plan generation, as I'm
      working towards doing; that will require more than one traversal of these
      lists.
      a923af38
    • Magnus Hagander's avatar
      Properly close token in sspi authentication · 6a61d1ff
      Magnus Hagander authored
      We can never leak more than one token, but we shouldn't do that. We
      don't bother closing it in the error paths since the process will
      exit shortly anyway.
      
      Christian Ullrich
      6a61d1ff
  11. 13 Jan, 2016 2 commits
    • Tom Lane's avatar
      Handle extension members when first setting object dump flags in pg_dump. · e72d7d85
      Tom Lane authored
      pg_dump's original approach to handling extension member objects was to
      run around and clear (or set) their dump flags rather late in its data
      collection process.  Unfortunately, quite a lot of code expects those flags
      to be valid before that; which was an entirely reasonable expectation
      before we added extensions.  In particular, this explains Karsten Hilbert's
      recent report of pg_upgrade failing on a database in which an extension
      has been installed into the pg_catalog schema.  Its objects are initially
      marked as not-to-be-dumped on the strength of their schema, and later we
      change them to must-dump because we're doing a binary upgrade of their
      extension; but we've already skipped essential tasks like making associated
      DO_SHELL_TYPE objects.
      
      To fix, collect extension membership data first, and incorporate it in the
      initial setting of the dump flags, so that those are once again correct
      from the get-go.  This has the undesirable side effect of slightly
      lengthening the time taken before pg_dump acquires table locks, but testing
      suggests that the increase in that window is not very much.
      
      Along the way, get rid of ugly special-case logic for deciding whether
      to dump procedural languages, FDWs, and foreign servers; dump decisions
      for those are now correct up-front, too.
      
      In 9.3 and up, this also fixes erroneous logic about when to dump event
      triggers (basically, they were *always* dumped before).  In 9.5 and up,
      transform objects had that problem too.
      
      Since this problem came in with extensions, back-patch to all supported
      versions.
      e72d7d85
    • Tom Lane's avatar
      Access pg_dump's options structs through Archive struct, not directly. · 5b5fea2a
      Tom Lane authored
      Rather than passing around DumpOptions and RestoreOptions as separate
      arguments, add fields to struct Archive to carry pointers to these objects,
      and access them through those fields when needed.  There already was a
      RestoreOptions pointer in Archive, though for no obvious reason it was part
      of the "private" struct rather than out where pg_dump.c could see it.
      
      Doing this allows reversion of quite a lot of parameter-addition changes
      made in commit 0eea8047, which is a good thing IMO because this will
      reduce the code delta between 9.4 and 9.5, probably easing a few future
      back-patch efforts.  Moreover, the previous commit only added a DumpOptions
      argument to functions that had to have it at the time, which means we could
      anticipate still more code churn (and more back-patch hazard) as the
      requirement spread further.  I'd hit exactly that problem in my upcoming
      patch to fix extension membership marking, which is what motivated me to
      do this.
      5b5fea2a