Skip to content
Snippets Groups Projects
  1. Sep 18, 2012
    • Tom Lane's avatar
      Fix planning of btree index scans using ScalarArrayOpExpr quals. · 807a40c5
      Tom Lane authored
      In commit 9e8da0f7, I improved btree
      to handle ScalarArrayOpExpr quals natively, so that constructs like
      "indexedcol IN (list)" could be supported by index-only scans.  Using
      such a qual results in multiple scans of the index, under-the-hood.
      I went to some lengths to ensure that this still produces rows in index
      order ... but I failed to recognize that if a higher-order index column
      is lacking an equality constraint, rescans can produce out-of-order
      data from that column.  Tweak the planner to not expect sorted output
      in that case.  Per trouble report from Robert McGehee.
      807a40c5
  2. Apr 26, 2012
    • Tom Lane's avatar
      Fix oversight in recent parameterized-path patch. · 7c85aa39
      Tom Lane authored
      bitmap_scan_cost_est() has to be able to cope with a BitmapOrPath, but
      I'd taken a shortcut that didn't work for that case.  Noted by Heikki.
      Add some regression tests since this area is evidently under-covered.
      7c85aa39
    • Tom Lane's avatar
      Modify create_index regression test to avoid intermittent failures. · d6d5f67b
      Tom Lane authored
      We have been seeing intermittent buildfarm failures due to a query
      sometimes not using an index-only scan plan, because a background
      auto-ANALYZE prevented the table's all-visible bits from being set
      immediately, thereby causing the estimated cost of an index-only scan
      to go up considerably.  Adjust the test case so that a bitmap index scan is
      preferred instead, which serves equally well for the purpose the test case
      is actually meant for.  (Of course, it would be better to eliminate the
      interference from auto-ANALYZE, but I see no low-risk way to do that,
      so any such fix will have to be left for 9.3 or later.)
      d6d5f67b
  3. Apr 06, 2012
  4. Mar 11, 2012
    • Tom Lane's avatar
      Teach SPGiST to store nulls and do whole-index scans. · c6a11b89
      Tom Lane authored
      This patch fixes the other major compatibility-breaking limitation of
      SPGiST, that it didn't store anything for null values of the indexed
      column, and so could not support whole-index scans or "x IS NULL"
      tests.  The approach is to create a wholly separate search tree for
      the null entries, and use fixed "allTheSame" insertion and search
      rules when processing this tree, instead of calling the index opclass
      methods.  This way the opclass methods do not need to worry about
      dealing with nulls.
      
      Catversion bump is for pg_am updates as well as the change in on-disk
      format of SPGiST indexes; there are some tweaks in SPGiST WAL records
      as well.
      
      Heavily rewritten version of a patch by Oleg Bartunov and Teodor Sigaev.
      (The original also stored nulls separately, but it reused GIN code to do
      so; which required undesirable compromises in the on-disk format, and
      would likely lead to bugs due to the GIN code being required to work in
      two very different contexts.)
      c6a11b89
  5. Jan 12, 2012
  6. Dec 29, 2011
    • Tom Lane's avatar
      Adjust SP-GiST regression tests to be less locale-sensitive. · 15ba5907
      Tom Lane authored
      The original test cases gave varying results depending on whether the
      locale sorts digits before or after letters.  Since that's not really
      what we wish to test here, adjust the test data to not contain any strings
      beginning with digits.  Per report from Pavel Stehule.
      15ba5907
  7. Dec 24, 2011
    • Tom Lane's avatar
      Improve planner's handling of duplicated index column expressions. · e2c2c2e8
      Tom Lane authored
      It's potentially useful for an index to repeat the same indexable column
      or expression in multiple index columns, if the columns have different
      opclasses.  (If they share opclasses too, the duplicate column is pretty
      useless, but nonetheless we've allowed such cases since 9.0.)  However,
      the planner failed to cope with this, because createplan.c was relying on
      simple equal() matching to figure out which index column each index qual
      is intended for.  We do have that information available upstream in
      indxpath.c, though, so the fix is to not flatten the multi-level indexquals
      list when putting it into an IndexPath.  Then we can rely on the sublist
      structure to identify target index columns in createplan.c.  There's a
      similar issue for index ORDER BYs (the KNNGIST feature), so introduce a
      multi-level-list representation for that too.  This adds a bit more
      representational overhead, but we might more or less buy that back by not
      having to search for matching index columns anymore in createplan.c;
      likewise btcostestimate saves some cycles.
      
      Per bug #6351 from Christian Rudolph.  Likely symptoms include the "btree
      index keys must be ordered by attribute" failure shown there, as well as
      "operator MMMM is not a member of opfamily NNNN".
      
      Although this is a pre-existing problem that can be demonstrated in 9.0 and
      9.1, I'm not going to back-patch it, because the API changes in the planner
      seem likely to break things such as index plugins.  The corner cases where
      this matters seem too narrow to justify possibly breaking things in a minor
      release.
      e2c2c2e8
  8. Dec 17, 2011
    • Tom Lane's avatar
      Add SP-GiST (space-partitioned GiST) index access method. · 8daeb5dd
      Tom Lane authored
      SP-GiST is comparable to GiST in flexibility, but supports non-balanced
      partitioned search structures rather than balanced trees.  As described at
      PGCon 2011, this new indexing structure can beat GiST in both index build
      time and query speed for search problems that it is well matched to.
      
      There are a number of areas that could still use improvement, but at this
      point the code seems committable.
      
      Teodor Sigaev and Oleg Bartunov, with considerable revisions by Tom Lane
      8daeb5dd
  9. Nov 02, 2011
    • Tom Lane's avatar
      Fix btree stop-at-nulls logic properly. · 882368e8
      Tom Lane authored
      As pointed out by Naoya Anzai, my previous try at this was a few bricks
      shy of a load, because I had forgotten that the initial-positioning logic
      might not try to skip over nulls at the end of the index the scan will
      start from.  We ought to fix that, because it represents an unnecessary
      inefficiency, but first let's get the scan-stop logic back to a safe
      state.  With this patch, we preserve the performance benefit requested
      in bug #6278 for the case of scanning forward into NULLs (in a NULLS
      LAST index), but the reverse case of scanning backward across NULLs
      when there's no suitable initial-positioning qual is still inefficient.
      882368e8
  10. Jun 30, 2011
    • Tom Lane's avatar
      Restore correct btree preprocessing of "indexedcol IS NULL" conditions. · a5652d3e
      Tom Lane authored
      Such a condition is unsatisfiable in combination with any other type of
      btree-indexable condition (since we assume btree operators are always
      strict).  8.3 and 8.4 had an explicit test for this, which I removed in
      commit 29c4ad98, mistakenly thinking that
      the case would be subsumed by the more general handling of IS (NOT) NULL
      added in that patch.  Put it back, and improve the comments about it, and
      add a regression test case.
      
      Per bug #6079 from Renat Nasyrov, and analysis by Dean Rasheed.
      a5652d3e
  11. Jan 25, 2011
    • Tom Lane's avatar
      Implement ALTER TABLE ADD UNIQUE/PRIMARY KEY USING INDEX. · 88452d5b
      Tom Lane authored
      This feature allows a unique or pkey constraint to be created using an
      already-existing unique index.  While the constraint isn't very
      functionally different from the bare index, it's nice to be able to do that
      for documentation purposes.  The main advantage over just issuing a plain
      ALTER TABLE ADD UNIQUE/PRIMARY KEY is that the index can be created with
      CREATE INDEX CONCURRENTLY, so that there is not a long interval where the
      table is locked against updates.
      
      On the way, refactor some of the code in DefineIndex() and index_create()
      so that we don't have to pass through those functions in order to create
      the index constraint's catalog entries.  Also, in parse_utilcmd.c, pass
      around the ParseState pointer in struct CreateStmtContext to save on
      notation, and add error location pointers to some error reports that didn't
      have one before.
      
      Gurjeet Singh, reviewed by Steve Singer and Tom Lane
      88452d5b
  12. Jan 08, 2011
    • Tom Lane's avatar
      Fix GIN to support null keys, empty and null items, and full index scans. · 73912e7f
      Tom Lane authored
      Per my recent proposal(s).  Null key datums can now be returned by
      extractValue and extractQuery functions, and will be stored in the index.
      Also, placeholder entries are made for indexable items that are NULL or
      contain no keys according to extractValue.  This means that the index is
      now always complete, having at least one entry for every indexed heap TID,
      and so we can get rid of the prohibition on full-index scans.  A full-index
      scan is implemented much the same way as partial-match scans were already:
      we build a bitmap representing all the TIDs found in the index, and then
      drive the results off that.
      
      Also, introduce a concept of a "search mode" that can be requested by
      extractQuery when the operator requires matching to empty items (this is
      just as cheap as matching to a single key) or requires a full index scan
      (which is not so cheap, but it sure beats failing or giving wrong answers).
      The behavior remains backward compatible for opclasses that don't return
      any null keys or request a non-default search mode.
      
      Using these features, we can now make the GIN index opclass for anyarray
      behave in a way that matches the actual anyarray operators for &&, <@, @>,
      and = ... which it failed to do before in assorted corner cases.
      
      This commit fixes the core GIN code and ginarrayprocs.c, updates the
      documentation, and adds some simple regression test cases for the new
      behaviors using the array operators.  The tsearch and contrib GIN opclass
      support functions still need to be looked over and probably fixed.
      
      Another thing I intend to fix separately is that this is pretty inefficient
      for cases where more than one scan condition needs a full-index search:
      we'll run duplicate GinScanEntrys, each one of which builds a large bitmap.
      There is some existing logic to merge duplicate GinScanEntrys but it needs
      refactoring to make it work for entries belonging to different scan keys.
      
      Note that most of gin.h has been split out into a new file gin_private.h,
      so that gin.h doesn't export anything that's not supposed to be used by GIN
      opclasses or the rest of the backend.  I did quite a bit of other code
      beautification work as well, mostly fixing comments and choosing more
      appropriate names for things.
      73912e7f
  13. Dec 04, 2010
    • Tom Lane's avatar
      KNNGIST, otherwise known as order-by-operator support for GIST. · 55450687
      Tom Lane authored
      This commit represents a rather heavily editorialized version of
      Teodor's builtin_knngist_itself-0.8.2 and builtin_knngist_proc-0.8.1
      patches.  I redid the opclass API to add a separate Distance method
      instead of turning the Consistent method into an illogical mess,
      fixed some bit-rot in the rbtree interfaces, and generally worked over
      the code style and comments.
      
      There's still no non-code documentation to speak of, but I'll work on
      that separately.  Some contrib-module changes are also yet to come
      (right now, point <-> point is the only KNN-ified operator).
      
      Teodor Sigaev and Tom Lane
      55450687
  14. Nov 23, 2010
  15. Jan 14, 2010
  16. Jan 01, 2010
    • Tom Lane's avatar
      Support "x IS NOT NULL" clauses as indexscan conditions. This turns out · 29c4ad98
      Tom Lane authored
      to be just a minor extension of the previous patch that made "x IS NULL"
      indexable, because we can treat the IS NOT NULL condition as if it were
      "x < NULL" or "x > NULL" (depending on the index's NULLS FIRST/LAST option),
      just like IS NULL is treated like "x = NULL".  Aside from any possible
      usefulness in its own right, this is an important improvement for
      index-optimized MAX/MIN aggregates: it is now reliably possible to get
      a column's min or max value cheaply, even when there are a lot of nulls
      cluttering the interesting end of the index.
      29c4ad98
  17. Dec 23, 2009
    • Tom Lane's avatar
      Allow the index name to be omitted in CREATE INDEX, causing the system to · d68e08d1
      Tom Lane authored
      choose an index name the same as it would do for an unnamed index constraint.
      (My recent changes to the index naming logic have helped to ensure that this
      will be a reasonable choice.)  Per a suggestion from Peter.
      
      A necessary side-effect is to promote CONCURRENTLY to type_func_name_keyword
      status, ie, it can't be a table/column/index name anymore unless quoted.
      This is not all bad, since we have heard more than once of people typing
      CREATE INDEX CONCURRENTLY ON foo (...) and getting a normal index build of
      an index named "concurrently", which was not what they wanted.  Now this
      syntax will result in a concurrent build of an index with system-chosen
      name; which they can rename afterwards if they want something else.
      d68e08d1
  18. Jul 28, 2009
  19. Jul 27, 2009
    • Tom Lane's avatar
      Experiment with using EXPLAIN COSTS OFF in regression tests. · 8835d63b
      Tom Lane authored
      This is a simple test to see whether COSTS OFF will help much with getting
      EXPLAIN output that's sufficiently platform-independent for use in the
      regression tests.  The planner does have some freedom of choice in these
      examples (plain via bitmap indexscan), so I'm not sure what will happen.
      8835d63b
  20. Jul 11, 2008
  21. Apr 11, 2008
    • Tom Lane's avatar
      Replace "amgetmulti" AM functions with "amgetbitmap", in which the whole · 4e82a954
      Tom Lane authored
      indexscan always occurs in one call, and the results are returned in a
      TIDBitmap instead of a limited-size array of TIDs.  This should improve
      speed a little by reducing AM entry/exit overhead, and it is necessary
      infrastructure if we are ever to support bitmap indexes.
      
      In an only slightly related change, add support for TIDBitmaps to preserve
      (somewhat lossily) the knowledge that particular TIDs reported by an index
      need to have their quals rechecked when the heap is visited.  This facility
      is not really used yet; we'll need to extend the forced-recheck feature to
      plain indexscans before it's useful, and that hasn't been coded yet.
      The intent is to use it to clean up 8.3's horrid @@@ kluge for text search
      with weighted queries.  There might be other uses in future, but that one
      alone is sufficient reason.
      
      Heikki Linnakangas, with some adjustments by me.
      4e82a954
  22. Apr 07, 2007
  23. Jan 09, 2007
    • Tom Lane's avatar
      Support ORDER BY ... NULLS FIRST/LAST, and add ASC/DESC/NULLS FIRST/NULLS LAST · 44317582
      Tom Lane authored
      per-column options for btree indexes.  The planner's support for this is still
      pretty rudimentary; it does not yet know how to plan mergejoins with
      nondefault ordering options.  The documentation is pretty rudimentary, too.
      I'll work on improving that stuff later.
      
      Note incompatible change from prior behavior: ORDER BY ... USING will now be
      rejected if the operator is not a less-than or greater-than member of some
      btree opclass.  This prevents less-than-sane behavior if an operator that
      doesn't actually define a proper sort ordering is selected.
      44317582
  24. Sep 10, 2006
    • Tom Lane's avatar
      Rename contains/contained-by operators to @> and <@, per discussion that · ba920e1c
      Tom Lane authored
      agreed these symbols are less easily confused.  I made new pg_operator
      entries (with new OIDs) for the old names, so as to provide backward
      compatibility while making it pretty easy to remove the old names in
      some future release cycle.  This commit only touches the core datatypes,
      contrib will be fixed separately.
      ba920e1c
  25. Aug 25, 2006
  26. Jul 11, 2006
  27. May 02, 2006
  28. Nov 07, 2005
  29. Jul 02, 2005
  30. Jul 01, 2005
  31. Apr 12, 2005
  32. Nov 21, 2003
    • Tom Lane's avatar
      COMMENT ON casts, conversions, languages, operator classes, and · 42ce74bf
      Tom Lane authored
      large objects.  Dump all these in pg_dump; also add code to pg_dump
      user-defined conversions.  Make psql's large object code rely on
      the backend for inserting/deleting LOB comments, instead of trying to
      hack pg_description directly.  Documentation and regression tests added.
      
      Christopher Kings-Lynne, code reviewed by Tom
      42ce74bf
  33. Nov 12, 2003
    • Tom Lane's avatar
      Cross-data-type comparisons are now indexable by btrees, pursuant to my · fa5c8a05
      Tom Lane authored
      pghackers proposal of 8-Nov.  All the existing cross-type comparison
      operators (int2/int4/int8 and float4/float8) have appropriate support.
      The original proposal of storing the right-hand-side datatype as part of
      the primary key for pg_amop and pg_amproc got modified a bit in the event;
      it is easier to store zero as the 'default' case and only store a nonzero
      when the operator is actually cross-type.  Along the way, remove the
      long-since-defunct bigbox_ops operator class.
      fa5c8a05
  34. May 29, 2003
  35. May 28, 2003
    • Tom Lane's avatar
      Replace functional-index facility with expressional indexes. Any column · fc8d970c
      Tom Lane authored
      of an index can now be a computed expression instead of a simple variable.
      Restrictions on expressions are the same as for predicates (only immutable
      functions, no sub-selects).  This fixes problems recently introduced with
      inlining SQL functions, because the inlining transformation is applied to
      both expression trees so the planner can still match them up.  Along the
      way, improve efficiency of handling index predicates (both predicates and
      index expressions are now cached by the relcache) and fix 7.3 oversight
      that didn't record dependencies of predicate expressions.
      fc8d970c
  36. Aug 28, 2001
  37. Jul 16, 2001
  38. Feb 17, 2000
    • Tom Lane's avatar
      Finish repairing 6.5's problems with r-tree indexes: create appropriate · 598ea2c3
      Tom Lane authored
      selectivity functions and make the r-tree operators use them.  The
      estimation functions themselves are just stubs, unfortunately, but
      perhaps someday someone will make them compute realistic estimates.
      Change pg_am so that the optimizer can reliably tell the difference
      between ordered and unordered indexes --- before it would think that
      an r-tree index can be scanned in '<<' order, which is not right AFAIK.
      Repair broken negator links for network_sup and related ops.
      Initdb forced.  This might be my last initdb force for 7.0 ... hope so
      anyway ...
      598ea2c3
  39. Jan 05, 2000
Loading