Skip to content
Snippets Groups Projects
  1. Feb 06, 2017
  2. Jan 03, 2017
  3. Nov 29, 2016
    • Tom Lane's avatar
      Test all contrib-created operator classes with amvalidate. · ade49c60
      Tom Lane authored
      I'd supposed that people would do this manually when creating new operator
      classes, but the folly of that was exposed today.  The tests seem fast
      enough that we can just apply them during the normal regression tests.
      
      contrib/isn fails the checks for lack of complete sets of cross-type
      operators.  That's a nice-to-have policy rather than a functional
      requirement, so leave it as-is, but insert ORDER BY in the query to
      ensure consistent cross-platform output.
      
      Discussion: https://postgr.es/m/7076.1480446837@sss.pgh.pa.us
      ade49c60
  4. Aug 27, 2016
    • Tom Lane's avatar
      Add macros to make AllocSetContextCreate() calls simpler and safer. · ea268cdc
      Tom Lane authored
      I found that half a dozen (nearly 5%) of our AllocSetContextCreate calls
      had typos in the context-sizing parameters.  While none of these led to
      especially significant problems, they did create minor inefficiencies,
      and it's now clear that expecting people to copy-and-paste those calls
      accurately is not a great idea.  Let's reduce the risk of future errors
      by introducing single macros that encapsulate the common use-cases.
      Three such macros are enough to cover all but two special-purpose contexts;
      those two calls can be left as-is, I think.
      
      While this patch doesn't in itself improve matters for third-party
      extensions, it doesn't break anything for them either, and they can
      gradually adopt the simplified notation over time.
      
      In passing, change TopMemoryContext to use the default allocation
      parameters.  Formerly it could only be extended 8K at a time.  That was
      probably reasonable when this code was written; but nowadays we create
      many more contexts than we did then, so that it's not unusual to have a
      couple hundred K in TopMemoryContext, even without considering various
      dubious code that sticks other things there.  There seems no good reason
      not to let it use growing blocks like most other contexts.
      
      Back-patch to 9.6, mostly because that's still close enough to HEAD that
      it's easy to do so, and keeping the branches in sync can be expected to
      avoid some future back-patching pain.  The bugs fixed by these changes
      don't seem to be significant enough to justify fixing them further back.
      
      Discussion: <21072.1472321324@sss.pgh.pa.us>
      ea268cdc
  5. Jun 20, 2016
    • Tom Lane's avatar
      pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. · e611515d
      Tom Lane authored
      Per buildfarm.  Fortunately, it's not quite too late to squeeze this fix
      into the pg_trgm 1.3 update.
      e611515d
    • Tom Lane's avatar
      Fix comparison of similarity to threshold in GIST trigram searches. · 9c852566
      Tom Lane authored
      There was some very strange code here, dating to commit b525bf77, that
      purported to work around an ancient gcc bug by forcing a float4 comparison
      to be done as int instead.  Commit 5871b884 broke that when it changed
      one side of the comparison to "double" but left the comparison code alone.
      Commit f576b17c doubled down on the weirdness by introducing a "volatile"
      marker, which had nothing to do with the actual problem.
      
      Guess that the gcc bug, even if it's still present in the wild, was
      triggered by comparison of float4's and can be avoided if we store the
      result of cnt_sml() into a double before comparing to the double "nlimit".
      This will at least work correctly on non-broken compilers, and it's way
      more readable.
      
      Per bug #14202 from Greg Navis.  Add a regression test based on his
      example.
      
      Report: <20160620115321.5792.10766@wrigleys.postgresql.org>
      9c852566
  6. Jun 14, 2016
    • Robert Haas's avatar
      Update extensions with GIN/GIST support for parallel query. · 2910fc82
      Robert Haas authored
      Commit 749a787c bumped the extension
      version on all of these extensions already, and we haven't had a
      release since then, so we can make further changes without bumping the
      extension version again.  Take this opportunity to mark all of the
      functions exported by these modules PARALLEL SAFE -- except for
      pg_trgm's set_limit().  Mark that one PARALLEL RESTRICTED, because it
      makes a persistent change to a GUC value.
      
      Note that some of the markings added by this commit don't have any
      effect; for example, gseg_picksplit() isn't likely to be mentioned
      explicitly in a query and therefore it's parallel-safety marking will
      never be consulted.  But this commit just marks everything for
      consistency: if it were somehow used in a query, that would be fine as
      far as parallel query is concerned, since it does not consult any
      backend-private state, attempt to write data, etc.
      
      Andreas Karlsson, with a few revisions by me.
      2910fc82
  7. Jun 10, 2016
  8. Jun 09, 2016
    • Tom Lane's avatar
      Handle contrib's GIN/GIST support function signature changes honestly. · 749a787c
      Tom Lane authored
      In commits 9ff60273 and dbe23289 I (tgl) fixed the
      signatures of a bunch of contrib's GIN and GIST support functions so that
      they would pass validation by the recently-added amvalidate functions.
      The backend does not actually consult or check those signatures otherwise,
      so I figured this was basically cosmetic and did not require an extension
      version bump.  However, Alexander Korotkov pointed out that that would
      leave us in a pretty messy situation if we ever wanted to redefine those
      functions later, because there wouldn't be a unique way to name them.
      Since we're going to be bumping these extensions' versions anyway for
      parallel-query cleanups, let's take care of this now.
      
      Andreas Karlsson, adjusted for more search-path-safety by me
      749a787c
  9. Mar 18, 2016
  10. Mar 16, 2016
  11. Jan 19, 2016
    • 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
  12. Jan 02, 2016
  13. Dec 25, 2015
  14. Jul 20, 2015
  15. May 15, 2015
    • Alvaro Herrera's avatar
      Move strategy numbers to include/access/stratnum.h · 26df7066
      Alvaro Herrera authored
      For upcoming BRIN opclasses, it's convenient to have strategy numbers
      defined in a single place.  Since there's nothing appropriate, create
      it.  The StrategyNumber typedef now lives there, as well as existing
      strategy numbers for B-trees (from skey.h) and R-tree-and-friends (from
      gist.h).  skey.h is forced to include stratnum.h because of the
      StrategyNumber typedef, but gist.h is not; extensions that currently
      rely on gist.h for rtree strategy numbers might need to add a new
      
      A few .c files can stop including skey.h and/or gist.h, which is a nice
      side benefit.
      
      Per discussion:
      https://www.postgresql.org/message-id/20150514232132.GZ2523@alvh.no-ip.org
      
      Authored by Emre Hasegeli and Álvaro.
      
      (It's not clear to me why bootscanner.l has any #include lines at all.)
      26df7066
  16. Apr 14, 2015
    • Heikki Linnakangas's avatar
      Reorganize our CRC source files again. · 4f700bcd
      Heikki Linnakangas authored
      Now that we use CRC-32C in WAL and the control file, the "traditional" and
      "legacy" CRC-32 variants are not used in any frontend programs anymore.
      Move the code for those back from src/common to src/backend/utils/hash.
      
      Also move the slicing-by-8 implementation (back) to src/port. This is in
      preparation for next patch that will add another implementation that uses
      Intel SSE 4.2 instructions to calculate CRC-32C, where available.
      4f700bcd
  17. Feb 20, 2015
    • Tom Lane's avatar
      Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. · 09d8d110
      Tom Lane authored
      Replace some bogus "x[1]" declarations with "x[FLEXIBLE_ARRAY_MEMBER]".
      Aside from being more self-documenting, this should help prevent bogus
      warnings from static code analyzers and perhaps compiler misoptimizations.
      
      This patch is just a down payment on eliminating the whole problem, but
      it gets rid of a lot of easy-to-fix cases.
      
      Note that the main problem with doing this is that one must no longer rely
      on computing sizeof(the containing struct), since the result would be
      compiler-dependent.  Instead use offsetof(struct, lastfield).  Autoconf
      also warns against spelling that offsetof(struct, lastfield[0]).
      
      Michael Paquier, review and additional fixes by me.
      09d8d110
  18. Jan 24, 2015
    • Tom Lane's avatar
      Replace a bunch more uses of strncpy() with safer coding. · 586dd5d6
      Tom Lane authored
      strncpy() has a well-deserved reputation for being unsafe, so make an
      effort to get rid of nearly all occurrences in HEAD.
      
      A large fraction of the remaining uses were passing length less than or
      equal to the known strlen() of the source, in which case no null-padding
      can occur and the behavior is equivalent to memcpy(), though doubtless
      slower and certainly harder to reason about.  So just use memcpy() in
      these cases.
      
      In other cases, use either StrNCpy() or strlcpy() as appropriate (depending
      on whether padding to the full length of the destination buffer seems
      useful).
      
      I left a few strncpy() calls alone in the src/timezone/ code, to keep it
      in sync with upstream (the IANA tzcode distribution).  There are also a
      few such calls in ecpg that could possibly do with more analysis.
      
      AFAICT, none of these changes are more than cosmetic, except for the four
      occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength
      source leads to a non-null-terminated destination buffer and ensuing
      misbehavior.  These don't seem like security issues, first because no stack
      clobber is possible and second because if your values of sslcert etc are
      coming from untrusted sources then you've got problems way worse than this.
      Still, it's undesirable to have unpredictable behavior for overlength
      inputs, so back-patch those four changes to all active branches.
      586dd5d6
  19. Jan 06, 2015
  20. Dec 18, 2014
    • Tom Lane's avatar
      Improve hash_create's API for selecting simple-binary-key hash functions. · 4a14f13a
      Tom Lane authored
      Previously, if you wanted anything besides C-string hash keys, you had to
      specify a custom hashing function to hash_create().  Nearly all such
      callers were specifying tag_hash or oid_hash; which is tedious, and rather
      error-prone, since a caller could easily miss the opportunity to optimize
      by using hash_uint32 when appropriate.  Replace this with a design whereby
      callers using simple binary-data keys just specify HASH_BLOBS and don't
      need to mess with specific support functions.  hash_create() itself will
      take care of optimizing when the key size is four bytes.
      
      This nets out saving a few hundred bytes of code space, and offers
      a measurable performance improvement in tidbitmap.c (which was not
      exploiting the opportunity to use hash_uint32 for its 4-byte keys).
      There might be some wins elsewhere too, I didn't analyze closely.
      
      In future we could look into offering a similar optimized hashing function
      for 8-byte keys.  Under this design that could be done in a centralized
      and machine-independent fashion, whereas getting it right for keys of
      platform-dependent sizes would've been notationally painful before.
      
      For the moment, the old way still works fine, so as not to break source
      code compatibility for loadable modules.  Eventually we might want to
      remove tag_hash and friends from the exported API altogether, since there's
      no real need for them to be explicitly referenced from outside dynahash.c.
      
      Teodor Sigaev and Tom Lane
      4a14f13a
  21. Nov 05, 2014
    • Tom Lane's avatar
      Fix volatility markings of some contrib I/O functions. · 66c029c8
      Tom Lane authored
      In general, datatype I/O functions are supposed to be immutable or at
      worst stable.  Some contrib I/O functions were, through oversight, not
      marked with any volatility property at all, which made them VOLATILE.
      Since (most of) these functions actually behave immutably, the erroneous
      marking isn't terribly harmful; but it can be user-visible in certain
      circumstances, as per a recent bug report from Joe Van Dyk in which a
      cast to text was disallowed in an expression index definition.
      
      To fix, just adjust the declarations in the extension SQL scripts.  If we
      were being very fussy about this, we'd bump the extension version numbers,
      but that seems like more trouble (for both developers and users) than the
      problem is worth.
      
      A fly in the ointment is that chkpass_in actually is volatile, because
      of its use of random() to generate a fresh salt when presented with a
      not-yet-encrypted password.  This is bad because of the general assumption
      that I/O functions aren't volatile: the consequence is that records or
      arrays containing chkpass elements may have input behavior a bit different
      from a bare chkpass column.  But there seems no way to fix this without
      breaking existing usage patterns for chkpass, and the consequences of the
      inconsistency don't seem bad enough to justify that.  So for the moment,
      just document it in a comment.
      
      Since we're not bumping version numbers, there seems no harm in
      back-patching these fixes; at least future installations will get the
      functions marked correctly.
      66c029c8
  22. Nov 04, 2014
    • Heikki Linnakangas's avatar
      Switch to CRC-32C in WAL and other places. · 5028f22f
      Heikki Linnakangas authored
      The old algorithm was found to not be the usual CRC-32 algorithm, used by
      Ethernet et al. We were using a non-reflected lookup table with code meant
      for a reflected lookup table. That's a strange combination that AFAICS does
      not correspond to any bit-wise CRC calculation, which makes it difficult to
      reason about its properties. Although it has worked well in practice, seems
      safer to use a well-known algorithm.
      
      Since we're changing the algorithm anyway, we might as well choose a
      different polynomial. The Castagnoli polynomial has better error-correcting
      properties than the traditional CRC-32 polynomial, even if we had
      implemented it correctly. Another reason for picking that is that some new
      CPUs have hardware support for calculating CRC-32C, but not CRC-32, let
      alone our strange variant of it. This patch doesn't add any support for such
      hardware, but a future patch could now do that.
      
      The old algorithm is kept around for tsquery and pg_trgm, which use the
      values in indexes that need to remain compatible so that pg_upgrade works.
      While we're at it, share the old lookup table for CRC-32 calculation
      between hstore, ltree and core. They all use the same table, so might as
      well.
      5028f22f
  23. Aug 25, 2014
  24. Jul 14, 2014
  25. Jul 10, 2014
  26. May 06, 2014
    • Bruce Momjian's avatar
      pgindent run for 9.4 · 0a783200
      Bruce Momjian authored
      This includes removing tabs after periods in C comments, which was
      applied to back branches, so this change should not effect backpatching.
      0a783200
  27. Apr 18, 2014
    • Peter Eisentraut's avatar
      Create function prototype as part of PG_FUNCTION_INFO_V1 macro · e7128e8d
      Peter Eisentraut authored
      Because of gcc -Wmissing-prototypes, all functions in dynamically
      loadable modules must have a separate prototype declaration.  This is
      meant to detect global functions that are not declared in header files,
      but in cases where the function is called via dfmgr, this is redundant.
      Besides filling up space with boilerplate, this is a frequent source of
      compiler warnings in extension modules.
      
      We can fix that by creating the function prototype as part of the
      PG_FUNCTION_INFO_V1 macro, which such modules have to use anyway.  That
      makes the code of modules cleaner, because there is one less place where
      the entry points have to be listed, and creates an additional check that
      functions have the right prototype.
      
      Remove now redundant prototypes from contrib and other modules.
      e7128e8d
  28. Apr 13, 2014
  29. Apr 06, 2014
    • Tom Lane's avatar
      Improve contrib/pg_trgm's heuristics for regexp index searches. · 80a5cf64
      Tom Lane authored
      When extracting trigrams from a regular expression for search of a GIN or
      GIST trigram index, it's useful to penalize (preferentially discard)
      trigrams that contain whitespace, since those are typically far more common
      in the index than trigrams not containing whitespace.  Of course, this
      should only be a preference not a hard rule, since we might otherwise end
      up with no trigrams to search for.  The previous coding tended to produce
      fairly inefficient trigram search sets for anchored regexp patterns, as
      reported by Erik Rijkers.  This patch penalizes whitespace-containing
      trigrams, and also reduces the target number of extracted trigrams, since
      experience suggests that the original coding tended to select too many
      trigrams to search for.
      
      Alexander Korotkov, reviewed by Tom Lane
      80a5cf64
  30. Jan 13, 2014
    • Tom Lane's avatar
      Fix possible buffer overrun in contrib/pg_trgm. · c3ccc9ee
      Tom Lane authored
      Allow for the possibility that folding a string to lower case makes it
      longer (due to replacing a character with a longer multibyte character).
      This doesn't change the number of trigrams that will be extracted, but
      it does affect the required size of an intermediate buffer in
      generate_trgm().  Per bug #8821 from Ufuk Kayserilioglu.
      
      Also install some checks that the input string length is not so large
      as to cause overflow in the calculations of palloc request sizes.
      
      Back-patch to all supported versions.
      c3ccc9ee
  31. Jan 07, 2014
  32. Oct 31, 2013
  33. Jul 18, 2013
  34. May 29, 2013
  35. Apr 15, 2013
    • Tom Lane's avatar
      Improve GiST index search performance for trigram regex queries. · 410bed2a
      Tom Lane authored
      The initial coding just descended the index if any of the target trigrams
      were possibly present at the next level down.  But actually we can apply
      trigramsMatchGraph() so as to take advantage of AND requirements when there
      are some.  The input data might contain false positive matches, but that
      can only result in a false positive result, not false negative, so it's
      safe to do it this way.
      
      Alexander Korotkov
      410bed2a
  36. Apr 10, 2013
Loading