Skip to content
Snippets Groups Projects
  1. Jun 21, 2012
    • Tom Lane's avatar
      Fix memory leak in ARRAY(SELECT ...) subqueries. · 66567ab2
      Tom Lane authored
      Repeated execution of an uncorrelated ARRAY_SUBLINK sub-select (which
      I think can only happen if the sub-select is embedded in a larger,
      correlated subquery) would leak memory for the duration of the query,
      due to not reclaiming the array generated in the previous execution.
      Per bug #6698 from Armando Miraglia.  Diagnosis and fix idea by Heikki,
      patch itself by me.
      
      This has been like this all along, so back-patch to all supported versions.
      66567ab2
  2. Jun 10, 2012
  3. Apr 21, 2012
    • Alvaro Herrera's avatar
      Recast "ONLY" column CHECK constraints as NO INHERIT · 09ff76fc
      Alvaro Herrera authored
      The original syntax wasn't universally loved, and it didn't allow its
      usage in CREATE TABLE, only ALTER TABLE.  It now works everywhere, and
      it also allows using ALTER TABLE ONLY to add an uninherited CHECK
      constraint, per discussion.
      
      The pg_constraint column has accordingly been renamed connoinherit.
      
      This commit partly reverts some of the changes in
      61d81bd2, particularly some pg_dump and
      psql bits, because now pg_get_constraintdef includes the necessary NO
      INHERIT within the constraint definition.
      
      Author: Nikhil Sontakke
      Some tweaks by me
      09ff76fc
  4. Apr 19, 2012
    • Tom Lane's avatar
      Revise parameterized-path mechanism to fix assorted issues. · 5b7b5518
      Tom Lane authored
      This patch adjusts the treatment of parameterized paths so that all paths
      with the same parameterization (same set of required outer rels) for the
      same relation will have the same rowcount estimate.  We cache the rowcount
      estimates to ensure that property, and hopefully save a few cycles too.
      Doing this makes it practical for add_path_precheck to operate without
      a rowcount estimate: it need only assume that paths with different
      parameterizations never dominate each other, which is close enough to
      true anyway for coarse filtering, because normally a more-parameterized
      path should yield fewer rows thanks to having more join clauses to apply.
      
      In add_path, we do the full nine yards of comparing rowcount estimates
      along with everything else, so that we can discard parameterized paths that
      don't actually have an advantage.  This fixes some issues I'd found with
      add_path rejecting parameterized paths on the grounds that they were more
      expensive than not-parameterized ones, even though they yielded many fewer
      rows and hence would be cheaper once subsequent joining was considered.
      
      To make the same-rowcounts assumption valid, we have to require that any
      parameterized path enforce *all* join clauses that could be obtained from
      the particular set of outer rels, even if not all of them are useful for
      indexing.  This is required at both base scans and joins.  It's a good
      thing anyway since the net impact is that join quals are checked at the
      lowest practical level in the join tree.  Hence, discard the original
      rather ad-hoc mechanism for choosing parameterization joinquals, and build
      a better one that has a more principled rule for when clauses can be moved.
      The original rule was actually buggy anyway for lack of knowledge about
      which relations are part of an outer join's outer side; getting this right
      requires adding an outer_relids field to RestrictInfo.
      5b7b5518
  5. Apr 06, 2012
  6. Mar 27, 2012
    • Tom Lane's avatar
      Add some infrastructure for contrib/pg_stat_statements. · a40fa613
      Tom Lane authored
      Add a queryId field to Query and PlannedStmt.  This is not used by the
      core backend, except for being copied around at appropriate times.
      It's meant to allow plug-ins to track a particular query forward from
      parse analysis to execution.
      
      The queryId is intentionally not dumped into stored rules (and hence this
      commit doesn't bump catversion).  You could argue that choice either way,
      but it seems better that stored rule strings not have any dependency
      on plug-ins that might or might not be present.
      
      Also, add a post_parse_analyze_hook that gets invoked at the end of
      parse analysis (but only for top-level analysis of complete queries,
      not cases such as analyzing a domain's default-value expression).
      This is mainly meant to be used to compute and assign a queryId,
      but it could have other applications.
      
      Peter Geoghegan
      a40fa613
  7. Mar 24, 2012
    • Tom Lane's avatar
      Fix planner's handling of outer PlaceHolderVars within subqueries. · 8279eb41
      Tom Lane authored
      For some reason, in the original coding of the PlaceHolderVar mechanism
      I had supposed that PlaceHolderVars couldn't propagate into subqueries.
      That is of course entirely possible.  When it happens, we need to treat
      an outer-level PlaceHolderVar much like an outer Var or Aggref, that is
      SS_replace_correlation_vars() needs to replace the PlaceHolderVar with
      a Param, and then when building the finished SubPlan we have to provide
      the PlaceHolderVar expression as an actual parameter for the SubPlan.
      The handling of the contained expression is a bit delicate but it can be
      treated exactly like an Aggref's expression.
      
      In addition to the missing logic in subselect.c, prepjointree.c was failing
      to search subqueries for PlaceHolderVars that need their relids adjusted
      during subquery pullup.  It looks like everyplace else that touches
      PlaceHolderVars got it right, though.
      
      Per report from Mark Murawski.  In 9.1 and HEAD, queries affected by this
      oversight would fail with "ERROR: Upper-level PlaceHolderVar found where
      not expected".  But in 9.0 and 8.4, you'd silently get possibly-wrong
      answers, since the value transmitted into the subquery wouldn't go to null
      when it should.
      8279eb41
  8. Mar 23, 2012
    • Tom Lane's avatar
      Code review for protransform patches. · 0339047b
      Tom Lane authored
      Fix loss of previous expression-simplification work when a transform
      function fires: we must not simply revert to untransformed input tree.
      Instead build a dummy FuncExpr node to pass to the transform function.
      This has the additional advantage of providing a simpler, more uniform
      API for transform functions.
      
      Move documentation to a somewhat less buried spot, relocate some
      poorly-placed code, be more wary of null constants and invalid typmod
      values, add an opr_sanity check on protransform function signatures,
      and some other minor cosmetic adjustments.
      
      Note: although this patch touches pg_proc.h, no need for catversion
      bump, because the changes are cosmetic and don't actually change the
      intended catalog contents.
      0339047b
  9. Mar 20, 2012
    • Tom Lane's avatar
      Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. · 9dbf2b7d
      Tom Lane authored
      Making this operation look like a utility statement seems generally a good
      idea, and particularly so in light of the desire to provide command
      triggers for utility statements.  The original choice of representing it as
      SELECT with an IntoClause appendage had metastasized into rather a lot of
      places, unfortunately, so that this patch is a great deal more complicated
      than one might at first expect.
      
      In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
      subcommands required restructuring some EXPLAIN-related APIs.  Add-on code
      that calls ExplainOnePlan or ExplainOneUtility, or uses
      ExplainOneQuery_hook, will need adjustment.
      
      Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
      which formerly were accepted though undocumented, are no longer accepted.
      The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
      The CREATE RULE case doesn't seem to have much real-world use (since the
      rule would work only once before failing with "table already exists"),
      so we'll not bother with that one.
      
      Both SELECT INTO and CREATE TABLE AS still return a command tag of
      "SELECT nnnn".  There was some discussion of returning "CREATE TABLE nnnn",
      but for the moment backwards compatibility wins the day.
      
      Andres Freund and Tom Lane
      9dbf2b7d
  10. Mar 16, 2012
    • Tom Lane's avatar
      Revisit handling of UNION ALL subqueries with non-Var output columns. · dd4134ea
      Tom Lane authored
      In commit 57664ed2 I tried to fix a bug
      reported by Teodor Sigaev by making non-simple-Var output columns distinct
      (by wrapping their expressions with dummy PlaceHolderVar nodes).  This did
      not work too well.  Commit b28ffd0f fixed
      some ensuing problems with matching to child indexes, but per a recent
      report from Claus Stadler, constraint exclusion of UNION ALL subqueries was
      still broken, because constant-simplification didn't handle the injected
      PlaceHolderVars well either.  On reflection, the original patch was quite
      misguided: there is no reason to expect that EquivalenceClass child members
      will be distinct.  So instead of trying to make them so, we should ensure
      that we can cope with the situation when they're not.
      
      Accordingly, this patch reverts the code changes in the above-mentioned
      commits (though the regression test cases they added stay).  Instead, I've
      added assorted defenses to make sure that duplicate EC child members don't
      cause any problems.  Teodor's original problem ("MergeAppend child's
      targetlist doesn't match MergeAppend") is addressed more directly by
      revising prepare_sort_from_pathkeys to let the parent MergeAppend's sort
      list guide creation of each child's sort list.
      
      In passing, get rid of add_sort_column; as far as I can tell, testing for
      duplicate sort keys at this stage is dead code.  Certainly it doesn't
      trigger often enough to be worth expending cycles on in ordinary queries.
      And keeping the test would've greatly complicated the new logic in
      prepare_sort_from_pathkeys, because comparing pathkey list entries against
      a previous output array requires that we not skip any entries in the list.
      
      Back-patch to 9.1, like the previous patches.  The only known issue in
      this area that wasn't caused by the ill-advised previous patches was the
      MergeAppend planning failure, which of course is not relevant before 9.1.
      It's possible that we need some of the new defenses against duplicate child
      EC entries in older branches, but until there's some clear evidence of that
      I'm going to refrain from back-patching further.
      dd4134ea
  11. Mar 09, 2012
    • Tom Lane's avatar
      Revise FDW planning API, again. · b1495393
      Tom Lane authored
      Further reflection shows that a single callback isn't very workable if we
      desire to let FDWs generate multiple Paths, because that forces the FDW to
      do all work necessary to generate a valid Plan node for each Path.  Instead
      split the former PlanForeignScan API into three steps: GetForeignRelSize,
      GetForeignPaths, GetForeignPlan.  We had already bit the bullet of breaking
      the 9.1 FDW API for 9.2, so this shouldn't cause very much additional pain,
      and it's substantially more flexible for complex FDWs.
      
      Add an fdw_private field to RelOptInfo so that the new functions can save
      state there rather than possibly having to recalculate information two or
      three times.
      
      In addition, we'd not thought through what would be needed to allow an FDW
      to set up subexpressions of its choice for runtime execution.  We could
      treat ForeignScan.fdw_private as an executable expression but that seems
      likely to break existing FDWs unnecessarily (in particular, it would
      restrict the set of node types allowable in fdw_private to those supported
      by expression_tree_walker).  Instead, invent a separate field fdw_exprs
      which will receive the postprocessing appropriate for expression trees.
      (One field is enough since it can be a list of expressions; also, we assume
      the corresponding expression state tree(s) will be held within fdw_state,
      so we don't need to add anything to ForeignScanState.)
      
      Per review of Hanada Shigeru's pgsql_fdw patch.  We may need to tweak this
      further as we continue to work on that patch, but to me it feels a lot
      closer to being right now.
      b1495393
  12. Mar 05, 2012
    • Tom Lane's avatar
      Redesign PlanForeignScan API to allow multiple paths for a foreign table. · 6b289942
      Tom Lane authored
      The original API specification only allowed an FDW to create a single
      access path, which doesn't seem like a terribly good idea in hindsight.
      Instead, move the responsibility for building the Path node and calling
      add_path() into the FDW's PlanForeignScan function.  Now, it can do that
      more than once if appropriate.  There is no longer any need for the
      transient FdwPlan struct, so get rid of that.
      
      Etsuro Fujita, Shigeru Hanada, Tom Lane
      6b289942
  13. Feb 27, 2012
    • Alvaro Herrera's avatar
      ALTER TABLE: skip FK validation when it's safe to do so · cb3a7c2b
      Alvaro Herrera authored
      We already skip rewriting the table in these cases, but we still force a
      whole table scan to validate the data.  This can be skipped, and thus
      we can make the whole ALTER TABLE operation just do some catalog touches
      instead of scanning the table, when these two conditions hold:
      
      (a) Old and new pg_constraint.conpfeqop match exactly.  This is actually
      stronger than needed; we could loosen things by way of operator
      families, but it'd require a lot more effort.
      
      (b) The functions, if any, implementing a cast from the foreign type to
      the primary opcintype are the same.  For this purpose, we can consider a
      binary coercion equivalent to an exact type match.  When the opcintype
      is polymorphic, require that the old and new foreign types match
      exactly.  (Since ri_triggers.c does use the executor, the stronger check
      for polymorphic types is no mere future-proofing.  However, no core type
      exercises its necessity.)
      
      Author: Noah Misch
      
      Committer's note: catalog version bumped due to change of the Constraint
      node.  I can't actually find any way to have such a node in a stored
      rule, but given that we have "out" support for them, better be safe.
      cb3a7c2b
  14. Feb 14, 2012
    • Tom Lane's avatar
      Preserve column names in the execution-time tupledesc for a RowExpr. · 398f70ec
      Tom Lane authored
      The hstore and json datatypes both have record-conversion functions that
      pay attention to column names in the composite values they're handed.
      We used to not worry about inserting correct field names into tuple
      descriptors generated at runtime, but given these examples it seems
      useful to do so.  Observe the nicer-looking results in the regression
      tests whose results changed.
      
      catversion bump because there is a subtle change in requirements for stored
      rule parsetrees: RowExprs from ROW() constructs now have to include field
      names.
      
      Andrew Dunstan and Tom Lane
      398f70ec
  15. Jan 28, 2012
    • Tom Lane's avatar
      Use parameterized paths to generate inner indexscans more flexibly. · e2fa76d8
      Tom Lane authored
      This patch fixes the planner so that it can generate nestloop-with-
      inner-indexscan plans even with one or more levels of joining between
      the indexscan and the nestloop join that is supplying the parameter.
      The executor was fixed to handle such cases some time ago, but the
      planner was not ready.  This should improve our plans in many situations
      where join ordering restrictions formerly forced complete table scans.
      
      There is probably a fair amount of tuning work yet to be done, because
      of various heuristics that have been added to limit the number of
      parameterized paths considered.  However, we are not going to find out
      what needs to be adjusted until the code gets some real-world use, so
      it's time to get it in there where it can be tested easily.
      
      Note API change for index AM amcostestimate functions.  I'm not aware of
      any non-core index AMs, but if there are any, they will need minor
      adjustments.
      e2fa76d8
  16. Jan 26, 2012
  17. Jan 24, 2012
  18. Jan 07, 2012
    • Peter Eisentraut's avatar
      Rename the internal structures of the CREATE TABLE (LIKE ...) facility · db49517c
      Peter Eisentraut authored
      The original implementation of this interpreted it as a kind of
      "inheritance" facility and named all the internal structures
      accordingly.  This turned out to be very confusing, because it has
      nothing to do with the INHERITS feature.  So rename all the internal
      parser infrastructure, update the comments, adjust the error messages,
      and split up the regression tests.
      db49517c
  19. Jan 05, 2012
  20. Jan 02, 2012
  21. Dec 25, 2011
    • Tom Lane's avatar
      Rethink representation of index clauses' mapping to index columns. · 472d3935
      Tom Lane authored
      In commit e2c2c2e8 I made use of nested
      list structures to show which clauses went with which index columns, but
      on reflection that's a data structure that only an old-line Lisp hacker
      could love.  Worse, it adds unnecessary complication to the many places
      that don't much care which clauses go with which index columns.  Revert
      to the previous arrangement of flat lists of clauses, and instead add a
      parallel integer list of column numbers.  The places that care about the
      pairing can chase both lists with forboth(), while the places that don't
      care just examine one list the same as before.
      
      The only real downside to this is that there are now two more lists that
      need to be passed to amcostestimate functions in case they care about
      column matching (which btcostestimate does, so not passing the info is not
      an option).  Rather than deal with 11-argument amcostestimate functions,
      pass just the IndexPath and expect the functions to extract fields from it.
      That gets us down to 7 arguments which is better than 11, and it seems
      more future-proof against likely additions to the information we keep
      about an index path.
      472d3935
  22. 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
  23. Dec 22, 2011
    • Robert Haas's avatar
      Add a security_barrier option for views. · 0e4611c0
      Robert Haas authored
      When a view is marked as a security barrier, it will not be pulled up
      into the containing query, and no quals will be pushed down into it,
      so that no function or operator chosen by the user can be applied to
      rows not exposed by the view.  Views not configured with this
      option cannot provide robust row-level security, but will perform far
      better.
      
      Patch by KaiGai Kohei; original problem report by Heikki Linnakangas
      (in October 2009!).  Review (in earlier versions) by Noah Misch and
      others.  Design advice by Tom Lane and myself.  Further review and
      cleanup by me.
      0e4611c0
  24. Dec 19, 2011
    • Peter Eisentraut's avatar
      Add support for privileges on types · 72920557
      Peter Eisentraut authored
      This adds support for the more or less SQL-conforming USAGE privilege
      on types and domains.  The intent is to be able restrict which users
      can create dependencies on types, which restricts the way in which
      owners can alter types.
      
      reviewed by Yeb Havinga
      72920557
  25. Dec 18, 2011
    • Tom Lane's avatar
      Replace simple constant pg_am.amcanreturn with an AM support function. · 3695a555
      Tom Lane authored
      The need for this was debated when we put in the index-only-scan feature,
      but at the time we had no near-term expectation of having AMs that could
      support such scans for only some indexes; so we kept it simple.  However,
      the SP-GiST AM forces the issue, so let's fix it.
      
      This patch only installs the new API; no behavior actually changes.
      3695a555
  26. Dec 07, 2011
    • Peter Eisentraut's avatar
      Add const qualifiers to node inspection functions · d5f23af6
      Peter Eisentraut authored
      Thomas Munro
      d5f23af6
    • 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
  27. Nov 28, 2011
    • Tom Lane's avatar
      Ensure that whole-row junk Vars are always of composite type. · dd3bab5f
      Tom Lane authored
      The EvalPlanQual machinery assumes that whole-row Vars generated for the
      outputs of non-table RTEs will be of composite types.  However, for the
      case where the RTE is a function call returning a scalar type, we were
      doing the wrong thing, as a result of sharing code with a parser case
      where the function's scalar output is wanted.  (Or at least, that's what
      that case has done historically; it does seem a bit inconsistent.)
      
      To fix, extend makeWholeRowVar's API so that it can support both use-cases.
      This fixes Belinda Cussen's report of crashes during concurrent execution
      of UPDATEs involving joins to the result of UNNEST() --- in READ COMMITTED
      mode, we'd run the EvalPlanQual machinery after a conflicting row update
      commits, and it was expecting to get a HeapTuple not a scalar datum from
      the "wholerowN" variable referencing the function RTE.
      
      Back-patch to 9.0 where the current EvalPlanQual implementation appeared.
      
      In 9.1 and up, this patch also fixes failure to attach the correct
      collation to the Var generated for a scalar-result case.  An example:
      regression=# select upper(x.*) from textcat('ab', 'cd') x;
      ERROR:  could not determine which collation to use for upper() function
      dd3bab5f
  28. Nov 25, 2011
    • Tom Lane's avatar
      Fix unsupported options in CREATE TABLE ... AS EXECUTE. · 9ed439a9
      Tom Lane authored
      The WITH [NO] DATA option was not supported, nor the ability to specify
      replacement column names; the former limitation wasn't even documented, as
      per recent complaint from Naoya Anzai.  Fix by moving the responsibility
      for supporting these options into the executor.  It actually takes less
      code this way ...
      
      catversion bump due to change in representation of IntoClause, which might
      affect stored rules.
      9ed439a9
  29. Nov 21, 2011
  30. Nov 18, 2011
    • Robert Haas's avatar
      Further consolidation of DROP statement handling. · fc6d1006
      Robert Haas authored
      This gets rid of an impressive amount of duplicative code, with only
      minimal behavior changes.  DROP FOREIGN DATA WRAPPER now requires object
      ownership rather than superuser privileges, matching the documentation
      we already have.  We also eliminate the historical warning about dropping
      a built-in function as unuseful.  All operations are now performed in the
      same order for all object types handled by dropcmds.c.
      
      KaiGai Kohei, with minor revisions by me
      fc6d1006
  31. Nov 03, 2011
    • Heikki Linnakangas's avatar
      Support range data types. · 4429f6a9
      Heikki Linnakangas authored
      Selectivity estimation functions are missing for some range type operators,
      which is a TODO.
      
      Jeff Davis
      4429f6a9
    • Tom Lane's avatar
      Fix handling of PlaceHolderVars in nestloop parameter management. · 7e3bf99b
      Tom Lane authored
      If we use a PlaceHolderVar from the outer relation in an inner indexscan,
      we need to reference the PlaceHolderVar as such as the value to be passed
      in from the outer relation.  The previous code effectively tried to
      reconstruct the PHV from its component expression, which doesn't work since
      (a) the Vars therein aren't necessarily bubbled up far enough, and (b) it
      would be the wrong semantics anyway because of the possibility that the PHV
      is supposed to have gone to null at some point before the current join.
      Point (a) led to "variable not found in subplan target list" planner
      errors, but point (b) would have led to silently wrong answers.
      Per report from Roger Niederland.
      7e3bf99b
  32. Oct 23, 2011
    • Tom Lane's avatar
      Don't trust deferred-unique indexes for join removal. · 0f39d505
      Tom Lane authored
      The uniqueness condition might fail to hold intra-transaction, and assuming
      it does can give incorrect query results.  Per report from Marti Raudsepp,
      though this is not his proposed patch.
      
      Back-patch to 9.0, where both these features were introduced.  In the
      released branches, add the new IndexOptInfo field to the end of the struct,
      to try to minimize ABI breakage for third-party code that may be examining
      that struct.
      0f39d505
  33. Oct 16, 2011
  34. Oct 14, 2011
    • Tom Lane's avatar
      Measure the number of all-visible pages for use in index-only scan costing. · e6858e66
      Tom Lane authored
      Add a column pg_class.relallvisible to remember the number of pages that
      were all-visible according to the visibility map as of the last VACUUM
      (or ANALYZE, or some other operations that update pg_class.relpages).
      Use relallvisible/relpages, instead of an arbitrary constant, to estimate
      how many heap page fetches can be avoided during an index-only scan.
      
      This is pretty primitive and will no doubt see refinements once we've
      acquired more field experience with the index-only scan mechanism, but
      it's way better than using a constant.
      
      Note: I had to adjust an underspecified query in the window.sql regression
      test, because it was changing answers when the plan changed to use an
      index-only scan.  Some of the adjacent tests perhaps should be adjusted
      as well, but I didn't do that here.
      e6858e66
  35. Oct 11, 2011
    • Tom Lane's avatar
      Rearrange the implementation of index-only scans. · a0185461
      Tom Lane authored
      This commit changes index-only scans so that data is read directly from the
      index tuple without first generating a faux heap tuple.  The only immediate
      benefit is that indexes on system columns (such as OID) can be used in
      index-only scans, but this is necessary infrastructure if we are ever to
      support index-only scans on expression indexes.  The executor is now ready
      for that, though the planner still needs substantial work to recognize
      the possibility.
      
      To do this, Vars in index-only plan nodes have to refer to index columns
      not heap columns.  I introduced a new special varno, INDEX_VAR, to mark
      such Vars to avoid confusion.  (In passing, this commit renames the two
      existing special varnos to OUTER_VAR and INNER_VAR.)  This allows
      ruleutils.c to handle them with logic similar to what we use for subplan
      reference Vars.
      
      Since index-only scans are now fundamentally different from regular
      indexscans so far as their expression subtrees are concerned, I also chose
      to change them to have their own plan node type (and hence, their own
      executor source file).
      a0185461
  36. Oct 08, 2011
    • Tom Lane's avatar
      Support index-only scans using the visibility map to avoid heap fetches. · a2822fb9
      Tom Lane authored
      When a btree index contains all columns required by the query, and the
      visibility map shows that all tuples on a target heap page are
      visible-to-all, we don't need to fetch that heap page.  This patch depends
      on the previous patches that made the visibility map reliable.
      
      There's a fair amount left to do here, notably trying to figure out a less
      chintzy way of estimating the cost of an index-only scan, but the core
      functionality seems ready to commit.
      
      Robert Haas and Ibrar Ahmed, with some previous work by Heikki Linnakangas.
      a2822fb9
  37. Sep 22, 2011
    • Tom Lane's avatar
      Make EXPLAIN ANALYZE report the numbers of rows rejected by filter steps. · f1972723
      Tom Lane authored
      This provides information about the numbers of tuples that were visited
      but not returned by table scans, as well as the numbers of join tuples
      that were considered and discarded within a join plan node.
      
      There is still some discussion going on about the best way to report counts
      for outer-join situations, but I think most of what's in the patch would
      not change if we revise that, so I'm going to go ahead and commit it as-is.
      
      Documentation changes to follow (they weren't in the submitted patch
      either).
      
      Marko Tiikkaja, reviewed by Marc Cousin, somewhat revised by Tom
      f1972723
  38. Sep 16, 2011
    • Tom Lane's avatar
      Redesign the plancache mechanism for more flexibility and efficiency. · e6faf910
      Tom Lane authored
      Rewrite plancache.c so that a "cached plan" (which is rather a misnomer
      at this point) can support generation of custom, parameter-value-dependent
      plans, and can make an intelligent choice between using custom plans and
      the traditional generic-plan approach.  The specific choice algorithm
      implemented here can probably be improved in future, but this commit is
      all about getting the mechanism in place, not the policy.
      
      In addition, restructure the API to greatly reduce the amount of extraneous
      data copying needed.  The main compromise needed to make that possible was
      to split the initial creation of a CachedPlanSource into two steps.  It's
      worth noting in particular that SPI_saveplan is now deprecated in favor of
      SPI_keepplan, which accomplishes the same end result with zero data
      copying, and no need to then spend even more cycles throwing away the
      original SPIPlan.  The risk of long-term memory leaks while manipulating
      SPIPlans has also been greatly reduced.  Most of this improvement is based
      on use of the recently-added MemoryContextSetParent primitive.
      e6faf910
Loading