Skip to content
Snippets Groups Projects
  1. May 08, 2017
    • Tom Lane's avatar
      Further patch rangetypes_selfuncs.c's statistics slot management. · 4509b4eb
      Tom Lane authored
      Values in a STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM slot are float8,
      not of the type of the column the statistics are for.
      
      This bug is at least partly the fault of sloppy specification comments
      for get_attstatsslot()/free_attstatsslot(): the type OID they want is that
      of the stavalues entries, not of the underlying column.  (I double-checked
      other callers and they seem to get this right.)  Adjust the comments to be
      more correct.
      
      Per buildfarm.
      
      Security: CVE-2017-7484
      4509b4eb
  2. Jul 25, 2015
    • Tom Lane's avatar
      Redesign tablesample method API, and do extensive code review. · 6fcb337f
      Tom Lane authored
      The original implementation of TABLESAMPLE modeled the tablesample method
      API on index access methods, which wasn't a good choice because, without
      specialized DDL commands, there's no way to build an extension that can
      implement a TSM.  (Raw inserts into system catalogs are not an acceptable
      thing to do, because we can't undo them during DROP EXTENSION, nor will
      pg_upgrade behave sanely.)  Instead adopt an API more like procedural
      language handlers or foreign data wrappers, wherein the only SQL-level
      support object needed is a single handler function identified by having
      a special return type.  This lets us get rid of the supporting catalog
      altogether, so that no custom DDL support is needed for the feature.
      
      Adjust the API so that it can support non-constant tablesample arguments
      (the original coding assumed we could evaluate the argument expressions at
      ExecInitSampleScan time, which is undesirable even if it weren't outright
      unsafe), and discourage sampling methods from looking at invisible tuples.
      Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
      within and across queries, as required by the SQL standard, and deal more
      honestly with methods that can't support that requirement.
      
      Make a full code-review pass over the tablesample additions, and fix
      assorted bugs, omissions, infelicities, and cosmetic issues (such as
      failure to put the added code stanzas in a consistent ordering).
      Improve EXPLAIN's output of tablesample plans, too.
      
      Back-patch to 9.5 so that we don't have to support the original API
      in production.
      6fcb337f
  3. May 24, 2015
  4. May 15, 2015
    • Simon Riggs's avatar
      TABLESAMPLE, SQL Standard and extensible · f6d208d6
      Simon Riggs authored
      Add a TABLESAMPLE clause to SELECT statements that allows
      user to specify random BERNOULLI sampling or block level
      SYSTEM sampling. Implementation allows for extensible
      sampling functions to be written, using a standard API.
      Basic version follows SQLStandard exactly. Usable
      concrete use cases for the sampling API follow in later
      commits.
      
      Petr Jelinek
      
      Reviewed by Michael Paquier and Simon Riggs
      f6d208d6
  5. Apr 26, 2015
    • Peter Eisentraut's avatar
      Add transforms feature · cac76582
      Peter Eisentraut authored
      This provides a mechanism for specifying conversions between SQL data
      types and procedural languages.  As examples, there are transforms
      for hstore and ltree for PL/Perl and PL/Python.
      
      reviews by Pavel Stěhule and Andres Freund
      cac76582
  6. Apr 06, 2015
    • Alvaro Herrera's avatar
      pg_event_trigger_dropped_objects: add is_temp column · e9a077ca
      Alvaro Herrera authored
      It now also reports temporary objects dropped that are local to the
      backend.  Previously we weren't reporting any temp objects because it
      was deemed unnecessary; but as it turns out, it is necessary if we want
      to keep close track of DDL command execution inside one session.  Temp
      objects are reported as living in schema pg_temp, which works because
      such a schema-qualification always refers to the temp objects of the
      current session.
      e9a077ca
  7. Jan 06, 2015
  8. Nov 25, 2014
    • Tom Lane's avatar
      Support arrays as input to array_agg() and ARRAY(SELECT ...). · bac27394
      Tom Lane authored
      These cases formerly failed with errors about "could not find array type
      for data type".  Now they yield arrays of the same element type and one
      higher dimension.
      
      The implementation involves creating functions with API similar to the
      existing accumArrayResult() family.  I (tgl) also extended the base family
      by adding an initArrayResult() function, which allows callers to avoid
      special-casing the zero-inputs case if they just want an empty array as
      result.  (Not all do, so the previous calling convention remains valid.)
      This allowed simplifying some existing code in xml.c and plperl.c.
      
      Ali Akbar, reviewed by Pavel Stehule, significantly modified by me
      bac27394
  9. Aug 06, 2014
    • Robert Haas's avatar
      Don't require sort support functions to provide a comparator. · 1d41739e
      Robert Haas authored
      This could be useful for datatypes like text, where we might want
      to optimize for some collations but not others.  However, this patch
      doesn't introduce any new sortsupport functions that work this way;
      it merely revises the code so that future patches may do so.
      
      Patch by me.  Review by Peter Geoghegan.
      1d41739e
  10. 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
  11. Jan 07, 2014
  12. Dec 23, 2013
    • Tom Lane's avatar
      Support ordered-set (WITHIN GROUP) aggregates. · 8d65da1f
      Tom Lane authored
      This patch introduces generic support for ordered-set and hypothetical-set
      aggregate functions, as well as implementations of the instances defined in
      SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(),
      percent_rank(), cume_dist()).  We also added mode() though it is not in the
      spec, as well as versions of percentile_cont() and percentile_disc() that
      can compute multiple percentile values in one pass over the data.
      
      Unlike the original submission, this patch puts full control of the sorting
      process in the hands of the aggregate's support functions.  To allow the
      support functions to find out how they're supposed to sort, a new API
      function AggGetAggref() is added to nodeAgg.c.  This allows retrieval of
      the aggregate call's Aggref node, which may have other uses beyond the
      immediate need.  There is also support for ordered-set aggregates to
      install cleanup callback functions, so that they can be sure that
      infrastructure such as tuplesort objects gets cleaned up.
      
      In passing, make some fixes in the recently-added support for variadic
      aggregates, and make some editorial adjustments in the recent FILTER
      additions for aggregates.  Also, simplify use of IsBinaryCoercible() by
      allowing it to succeed whenever the target type is ANY or ANYELEMENT.
      It was inconsistent that it dealt with other polymorphic target types
      but not these.
      
      Atri Sharma and Andrew Gierth; reviewed by Pavel Stehule and Vik Fearing,
      and rather heavily editorialized upon by Tom Lane
      8d65da1f
  13. Jan 01, 2013
  14. Aug 30, 2012
    • Alvaro Herrera's avatar
      Split tuple struct defs from htup.h to htup_details.h · c219d9b0
      Alvaro Herrera authored
      This reduces unnecessary exposure of other headers through htup.h, which
      is very widely included by many files.
      
      I have chosen to move the function prototypes to the new file as well,
      because that means htup.h no longer needs to include tupdesc.h.  In
      itself this doesn't have much effect in indirect inclusion of tupdesc.h
      throughout the tree, because it's also required by execnodes.h; but it's
      something to explore in the future, and it seemed best to do the htup.h
      change now while I'm busy with it.
      c219d9b0
  15. Aug 29, 2012
  16. Jun 10, 2012
  17. Feb 14, 2012
    • Robert Haas's avatar
      Allow LEAKPROOF functions for better performance of security views. · cd30728f
      Robert Haas authored
      We don't normally allow quals to be pushed down into a view created
      with the security_barrier option, but functions without side effects
      are an exception: they're OK.  This allows much better performance in
      common cases, such as when using an equality operator (that might
      even be indexable).
      
      There is an outstanding issue here with the CREATE FUNCTION / ALTER
      FUNCTION syntax: there's no way to use ALTER FUNCTION to unset the
      leakproof flag.  But I'm committing this as-is so that it doesn't
      have to be rebased again; we can fix up the grammar in a future
      commit.
      
      KaiGai Kohei, with some wordsmithing by me.
      cd30728f
  18. Jan 02, 2012
  19. Dec 07, 2011
    • Tom Lane's avatar
      Create a "sort support" interface API for faster sorting. · c6e3ac11
      Tom Lane authored
      This patch creates an API whereby a btree index opclass can optionally
      provide non-SQL-callable support functions for sorting.  In the initial
      patch, we only use this to provide a directly-callable comparator function,
      which can be invoked with a bit less overhead than the traditional
      SQL-callable comparator.  While that should be of value in itself, the real
      reason for doing this is to provide a datatype-extensible framework for
      more aggressive optimizations, as in Peter Geoghegan's recent work.
      
      Robert Haas and Tom Lane
      c6e3ac11
  20. Dec 01, 2011
    • Tom Lane's avatar
      Fix getTypeIOParam to support type record[]. · 65d9aedb
      Tom Lane authored
      Since record[] uses array_in, it needs to have its element type passed
      as typioparam.  In HEAD and 9.1, this fix essentially reverts commit
      9bc933b2, which was a hack that is no
      longer needed since domains don't set their typelem anymore.  Before
      that, adjust the logic so that only domains are excluded from being
      treated like arrays, rather than assuming that only base types should
      be included.  Add a regression test to demonstrate the need for this.
      Per report from Maxim Boguk.
      
      Back-patch to 8.4, where type record[] was added.
      65d9aedb
  21. Nov 21, 2011
  22. Nov 03, 2011
  23. Jul 06, 2011
    • Tom Lane's avatar
      Remove assumptions that not-equals operators cannot be in any opclass. · 14f67192
      Tom Lane authored
      get_op_btree_interpretation assumed this in order to save some duplication
      of code, but it's not true in general anymore because we added <> support
      to btree_gist.  (We still assume it for btree opclasses, though.)
      
      Also, essentially the same logic was baked into predtest.c.  Get rid of
      that duplication by generalizing get_op_btree_interpretation so that it
      can be used by predtest.c.
      
      Per bug report from Denis de Bernardy and investigation by Jeff Davis,
      though I didn't use Jeff's patch exactly as-is.
      
      Back-patch to 9.1; we do not support this usage before that.
      14f67192
  24. Jul 04, 2011
  25. Jun 03, 2011
    • Tom Lane's avatar
      Fix failure to check whether a rowtype's component types are sortable. · ea8e42f3
      Tom Lane authored
      The existence of a btree opclass accepting composite types caused us to
      assume that every composite type is sortable.  This isn't true of course;
      we need to check if the column types are all sortable.  There was logic
      for this for the case of array comparison (ie, check that the element
      type is sortable), but we missed the point for rowtypes.  Per Teodor's
      report of an ANALYZE failure for an unsortable composite type.
      
      Rather than just add some more ad-hoc logic for this, I moved knowledge of
      the issue into typcache.c.  The typcache will now only report out array_eq,
      record_cmp, and friends as usable operators if the array or composite type
      will work with those functions.
      
      Unfortunately we don't have enough info to do this for anonymous RECORD
      types; in that case, just assume it will work, and take the runtime failure
      as before if it doesn't.
      
      This patch might be a candidate for back-patching at some point, but
      given the lack of complaints from the field, I'd rather just test it in
      HEAD for now.
      
      Note: most of the places touched in this patch will need further work
      when we get around to supporting hashing of record types.
      ea8e42f3
  26. Apr 10, 2011
  27. Mar 26, 2011
    • Tom Lane's avatar
      Clean up a few failures to set collation fields in expression nodes. · b23c9fa9
      Tom Lane authored
      I'm not sure these have any non-cosmetic implications, but I'm not sure
      they don't, either.  In particular, ensure the CaseTestExpr generated
      by transformAssignmentIndirection to represent the base target column
      carries the correct collation, because parse_collate.c won't fix that.
      Tweak lsyscache.c API so that we can get the appropriate collation
      without an extra syscache lookup.
      b23c9fa9
    • Tom Lane's avatar
      Pass collation to makeConst() instead of looking it up internally. · bfa4440c
      Tom Lane authored
      In nearly all cases, the caller already knows the correct collation, and
      in a number of places, the value the caller has handy is more correct than
      the default for the type would be.  (In particular, this patch makes it
      significantly less likely that eval_const_expressions will result in
      changing the exposed collation of an expression.)  So an internal lookup
      is both expensive and wrong.
      bfa4440c
  28. Feb 08, 2011
    • Peter Eisentraut's avatar
      Per-column collation support · 414c5a2e
      Peter Eisentraut authored
      This adds collation support for columns and domains, a COLLATE clause
      to override it per expression, and B-tree index support.
      
      Peter Eisentraut
      reviewed by Pavel Stehule, Itagaki Takahiro, Robert Haas, Noah Misch
      414c5a2e
  29. Jan 01, 2011
  30. Dec 03, 2010
    • Tom Lane's avatar
      Create core infrastructure for KNNGIST. · d583f10b
      Tom Lane authored
      This is a heavily revised version of builtin_knngist_core-0.9.  The
      ordering operators are no longer mixed in with actual quals, which would
      have confused not only humans but significant parts of the planner.
      Instead, ordering operators are carried separately throughout planning and
      execution.
      
      Since the API for ambeginscan and amrescan functions had to be changed
      anyway, this commit takes the opportunity to rationalize that a bit.
      RelationGetIndexScan no longer forces a premature index_rescan call;
      instead, callers of index_beginscan must call index_rescan too.  Aside from
      making the AM-side initialization logic a bit less peculiar, this has the
      advantage that we do not make a useless extra am_rescan call when there are
      runtime key values.  AMs formerly could not assume that the key values
      passed to amrescan were actually valid; now they can.
      
      Teodor Sigaev and Tom Lane
      d583f10b
  31. Nov 24, 2010
    • Tom Lane's avatar
      Create the system catalog infrastructure needed for KNNGIST. · 725d52d0
      Tom Lane authored
      This commit adds columns amoppurpose and amopsortfamily to pg_amop, and
      column amcanorderbyop to pg_am.  For the moment all the entries in
      amcanorderbyop are "false", since the underlying support isn't there yet.
      
      Also, extend the CREATE OPERATOR CLASS/ALTER OPERATOR FAMILY commands with
      [ FOR SEARCH | FOR ORDER BY sort_operator_family ] clauses to allow the new
      columns of pg_amop to be populated, and create pg_dump support for dumping
      that information.
      
      I also added some documentation, although it's perhaps a bit premature
      given that the feature doesn't do anything useful yet.
      
      Teodor Sigaev, Robert Haas, Tom Lane
      725d52d0
  32. Oct 31, 2010
    • Tom Lane's avatar
      Provide hashing support for arrays. · 186cbbda
      Tom Lane authored
      The core of this patch is hash_array() and associated typcache
      infrastructure, which works just about exactly like the existing support
      for array comparison.
      
      In addition I did some work to ensure that the planner won't think that an
      array type is hashable unless its element type is hashable, and similarly
      for sorting.  This includes adding a datatype parameter to op_hashjoinable
      and op_mergejoinable, and adding an explicit "hashable" flag to
      SortGroupClause.  The lack of a cross-check on the element type was a
      pre-existing bug in mergejoin support --- but it didn't matter so much
      before, because if you couldn't sort the element type there wasn't any good
      alternative to failing anyhow.  Now that we have the alternative of hashing
      the array type, there are cases where we can avoid a failure by being picky
      at the planner stage, so it's time to be picky.
      
      The issue of exactly how to combine the per-element hash values to produce
      an array hash is still open for discussion, but the rest of this is pretty
      solid, so I'll commit it as-is.
      186cbbda
  33. Oct 21, 2010
    • Tom Lane's avatar
      Improve handling of domains over arrays. · 529cb267
      Tom Lane authored
      This patch eliminates various bizarre behaviors caused by sloppy thinking
      about the difference between a domain type and its underlying array type.
      In particular, the operation of updating one element of such an array
      has to be considered as yielding a value of the underlying array type,
      *not* a value of the domain, because there's no assurance that the
      domain's CHECK constraints are still satisfied.  If we're intending to
      store the result back into a domain column, we have to re-cast to the
      domain type so that constraints are re-checked.
      
      For similar reasons, such a domain can't be blindly matched to an ANYARRAY
      polymorphic parameter, because the polymorphic function is likely to apply
      array-ish operations that could invalidate the domain constraints.  For the
      moment, we just forbid such matching.  We might later wish to insert an
      automatic downcast to the underlying array type, but such a change should
      also change matching of domains to ANYELEMENT for consistency.
      
      To ensure that all such logic is rechecked, this patch removes the original
      hack of setting a domain's pg_type.typelem field to match its base type;
      the typelem will always be zero instead.  In those places where it's really
      okay to look through the domain type with no other logic changes, use the
      newly added get_base_element_type function in place of get_element_type.
      catversion bumped due to change in pg_type contents.
      
      Per bug #5717 from Richard Huxton and subsequent discussion.
      529cb267
  34. Sep 20, 2010
  35. Aug 05, 2010
    • Robert Haas's avatar
      Standardize get_whatever_oid functions for object types with · 2a6ef344
      Robert Haas authored
      unqualified names.
      
      - Add a missing_ok parameter to get_tablespace_oid.
      - Avoid duplicating get_tablespace_od guts in objectNamesToOids.
      - Add a missing_ok parameter to get_database_oid.
      - Replace get_roleid and get_role_checked with get_role_oid.
      - Add get_namespace_oid, get_language_oid, get_am_oid.
      - Refactor existing code to use new interfaces.
      
      Thanks to KaiGai Kohei for the review.
      2a6ef344
  36. Jul 10, 2010
    • Tom Lane's avatar
      Avoid an Assert failure in deconstruct_array() by making get_attstatsslot() · 5ce63f48
      Tom Lane authored
      use the actual element type of the array it's disassembling, rather than
      trusting the type OID passed in by its caller.  This is needed because
      sometimes the planner passes in a type OID that's only binary-compatible
      with the target column's type, rather than being an exact match.  Per an
      example from Bernd Helmle.
      
      Possibly we should refactor get_attstatsslot/free_attstatsslot to not expect
      the caller to supply type ID data at all, but for now I'll just do the
      minimum-change fix.
      
      Back-patch to 7.4.  Bernd's test case only crashes back to 8.0, but since
      these subroutines are the same in 7.4, I suspect there may be variant
      cases that would crash 7.4 as well.
      5ce63f48
  37. Apr 24, 2010
  38. Feb 26, 2010
Loading