1. 06 2月, 2013 1 次提交
  2. 23 1月, 2013 1 次提交
    • A
      Improve concurrency of foreign key locking · 0ac5ad51
      Alvaro Herrera 提交于
      This patch introduces two additional lock modes for tuples: "SELECT FOR
      KEY SHARE" and "SELECT FOR NO KEY UPDATE".  These don't block each
      other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
      FOR UPDATE".  UPDATE commands that do not modify the values stored in
      the columns that are part of the key of the tuple now grab a SELECT FOR
      NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
      with tuple locks of the FOR KEY SHARE variety.
      
      Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
      means the concurrency improvement applies to them, which is the whole
      point of this patch.
      
      The added tuple lock semantics require some rejiggering of the multixact
      module, so that the locking level that each transaction is holding can
      be stored alongside its Xid.  Also, multixacts now need to persist
      across server restarts and crashes, because they can now represent not
      only tuple locks, but also tuple updates.  This means we need more
      careful tracking of lifetime of pg_multixact SLRU files; since they now
      persist longer, we require more infrastructure to figure out when they
      can be removed.  pg_upgrade also needs to be careful to copy
      pg_multixact files over from the old server to the new, or at least part
      of multixact.c state, depending on the versions of the old and new
      servers.
      
      Tuple time qualification rules (HeapTupleSatisfies routines) need to be
      careful not to consider tuples with the "is multi" infomask bit set as
      being only locked; they might need to look up MultiXact values (i.e.
      possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
      whereas they previously were assured to only use information readily
      available from the tuple header.  This is considered acceptable, because
      the extra I/O would involve cases that would previously cause some
      commands to block waiting for concurrent transactions to finish.
      
      Another important change is the fact that locking tuples that have
      previously been updated causes the future versions to be marked as
      locked, too; this is essential for correctness of foreign key checks.
      This causes additional WAL-logging, also (there was previously a single
      WAL record for a locked tuple; now there are as many as updated copies
      of the tuple there exist.)
      
      With all this in place, contention related to tuples being checked by
      foreign key rules should be much reduced.
      
      As a bonus, the old behavior that a subtransaction grabbing a stronger
      tuple lock than the parent (sub)transaction held on a given tuple and
      later aborting caused the weaker lock to be lost, has been fixed.
      
      Many new spec files were added for isolation tester framework, to ensure
      overall behavior is sane.  There's probably room for several more tests.
      
      There were several reviewers of this patch; in particular, Noah Misch
      and Andres Freund spent considerable time in it.  Original idea for the
      patch came from Simon Riggs, after a problem report by Joel Jacobson.
      Most code is from me, with contributions from Marti Raudsepp, Alexander
      Shulgin, Noah Misch and Andres Freund.
      
      This patch was discussed in several pgsql-hackers threads; the most
      important start at the following message-ids:
      	AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
      	1290721684-sup-3951@alvh.no-ip.org
      	1294953201-sup-2099@alvh.no-ip.org
      	1320343602-sup-2290@alvh.no-ip.org
      	1339690386-sup-8927@alvh.no-ip.org
      	4FE5FF020200002500048A3D@gw.wicourts.gov
      	4FEAB90A0200002500048B7D@gw.wicourts.gov
      0ac5ad51
  3. 02 1月, 2013 1 次提交
  4. 13 9月, 2012 1 次提交
    • T
      Fix case of window function + aggregate + GROUP BY expression. · a2099360
      Tom Lane 提交于
      In commit 1bc16a94 I added a minor
      optimization to drop the component variables of a GROUP BY expression from
      the target list computed at the aggregation level of a query, if those Vars
      weren't referenced elsewhere in the tlist.  However, I overlooked that the
      window-function planning code would deconstruct such expressions and thus
      need to have access to their component variables.  Fix it to not do that.
      
      While at it, I removed the distinction between volatile and nonvolatile
      window partition/order expressions: the code now computes all of them
      at the aggregation level.  This saves a relatively expensive check for
      volatility, and it's unclear that the resulting plan isn't better anyway.
      
      Per bug #7535 from Louis-David Mitterrand.  Back-patch to 9.2.
      a2099360
  5. 06 9月, 2012 1 次提交
    • T
      Fix PARAM_EXEC assignment mechanism to be safe in the presence of WITH. · 46c508fb
      Tom Lane 提交于
      The planner previously assumed that parameter Vars having the same absolute
      query level, varno, and varattno could safely be assigned the same runtime
      PARAM_EXEC slot, even though they might be different Vars appearing in
      different subqueries.  This was (probably) safe before the introduction of
      CTEs, but the lazy-evalution mechanism used for CTEs means that a CTE can
      be executed during execution of some other subquery, causing the lifespan
      of Params at the same syntactic nesting level as the CTE to overlap with
      use of the same slots inside the CTE.  In 9.1 we created additional hazards
      by using the same parameter-assignment technology for nestloop inner scan
      parameters, but it was broken before that, as illustrated by the added
      regression test.
      
      To fix, restructure the planner's management of PlannerParamItems so that
      items having different semantic lifespans are kept rigorously separated.
      This will probably result in complex queries using more runtime PARAM_EXEC
      slots than before, but the slots are cheap enough that this hardly matters.
      Also, stop generating PlannerParamItems containing Params for subquery
      outputs: all we really need to do is reserve the PARAM_EXEC slot number,
      and that now only takes incrementing a counter.  The planning code is
      simpler and probably faster than before, as well as being more correct.
      
      Per report from Vik Reykja.
      
      These changes will mostly also need to be made in the back branches, but
      I'm going to hold off on that until after 9.2.0 wraps.
      46c508fb
  6. 01 9月, 2012 1 次提交
  7. 31 8月, 2012 1 次提交
    • A
      Split tuple struct defs from htup.h to htup_details.h · c219d9b0
      Alvaro Herrera 提交于
      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
  8. 27 8月, 2012 1 次提交
    • T
      Fix up planner infrastructure to support LATERAL properly. · 9ff79b9d
      Tom Lane 提交于
      This patch takes care of a number of problems having to do with failure
      to choose valid join orders and incorrect handling of lateral references
      pulled up from subqueries.  Notable changes:
      
      * Add a LateralJoinInfo data structure similar to SpecialJoinInfo, to
      represent join ordering constraints created by lateral references.
      (I first considered extending the SpecialJoinInfo structure, but the
      semantics are different enough that a separate data structure seems
      better.)  Extend join_is_legal() and related functions to prevent trying
      to form unworkable joins, and to ensure that we will consider joins that
      satisfy lateral references even if the joins would be clauseless.
      
      * Fill in the infrastructure needed for the last few types of relation scan
      paths to support parameterization.  We'd have wanted this eventually
      anyway, but it is necessary now because a relation that gets pulled up out
      of a UNION ALL subquery may acquire a reltargetlist containing lateral
      references, meaning that its paths *have* to be parameterized whether or
      not we have any code that can push join quals down into the scan.
      
      * Compute data about lateral references early in query_planner(), and save
      in RelOptInfo nodes, to avoid repetitive calculations later.
      
      * Assorted corner-case bug fixes.
      
      There's probably still some bugs left, but this is a lot closer to being
      real than it was before.
      9ff79b9d
  9. 13 8月, 2012 1 次提交
    • T
      More fixes for planner's handling of LATERAL. · c1774d2c
      Tom Lane 提交于
      Re-allow subquery pullup for LATERAL subqueries, except when the subquery
      is below an outer join and contains lateral references to relations outside
      that outer join.  If we pull up in such a case, we risk introducing lateral
      cross-references into outer joins' ON quals, which is something the code is
      entirely unprepared to cope with right now; and I'm not sure it'll ever be
      worth coping with.
      
      Support lateral refs in VALUES (this seems to be the only additional path
      type that needs such support as a consequence of re-allowing subquery
      pullup).
      
      Put in a slightly hacky fix for joinpath.c's refusal to consider
      parameterized join paths even when there cannot be any unparameterized
      ones.  This was causing "could not devise a query plan for the given query"
      failures in queries involving more than two FROM items.
      
      Put in an even more hacky fix for distribute_qual_to_rels() being unhappy
      with join quals that contain references to rels outside their syntactic
      scope; which is to say, disable that test altogether.  Need to think about
      how to preserve some sort of debugging cross-check here, while not
      expending more cycles than befits a debugging cross-check.
      c1774d2c
  10. 08 8月, 2012 1 次提交
    • T
      Implement SQL-standard LATERAL subqueries. · 5ebaaa49
      Tom Lane 提交于
      This patch implements the standard syntax of LATERAL attached to a
      sub-SELECT in FROM, and also allows LATERAL attached to a function in FROM,
      since set-returning function calls are expected to be one of the principal
      use-cases.
      
      The main change here is a rewrite of the mechanism for keeping track of
      which relations are visible for column references while the FROM clause is
      being scanned.  The parser "namespace" lists are no longer lists of bare
      RTEs, but are lists of ParseNamespaceItem structs, which carry an RTE
      pointer as well as some visibility-controlling flags.  Aside from
      supporting LATERAL correctly, this lets us get rid of the ancient hacks
      that required rechecking subqueries and JOIN/ON and function-in-FROM
      expressions for invalid references after they were initially parsed.
      Invalid column references are now always correctly detected on sight.
      
      In passing, remove assorted parser error checks that are now dead code by
      virtue of our having gotten rid of add_missing_from, as well as some
      comments that are obsolete for the same reason.  (It was mainly
      add_missing_from that caused so much fudging here in the first place.)
      
      The planner support for this feature is very minimal, and will be improved
      in future patches.  It works well enough for testing purposes, though.
      
      catversion bump forced due to new field in RangeTblEntry.
      5ebaaa49
  11. 22 7月, 2012 1 次提交
    • T
      Account for SRFs in targetlists in planner rowcount estimates. · 31c7c642
      Tom Lane 提交于
      We made use of the ROWS estimate for set-returning functions used in FROM,
      but not for those used in SELECT targetlists; which is a bit of an
      oversight considering there are common usages that require the latter
      approach.  Improve that.  (I had initially thought it might be worth
      folding this into cost_qual_eval, but after investigation concluded that
      that wouldn't be very helpful, so just do it separately.)  Per complaint
      from David Johnston.
      
      Back-patch to 9.2, but not further, for fear of destabilizing plan choices
      in existing releases.
      31c7c642
  12. 11 6月, 2012 1 次提交
  13. 26 4月, 2012 1 次提交
    • T
      Fix planner's handling of RETURNING lists in writable CTEs. · 9fa82c98
      Tom Lane 提交于
      setrefs.c failed to do "rtoffset" adjustment of Vars in RETURNING lists,
      which meant they were left with the wrong varnos when the RETURNING list
      was in a subquery.  That was never possible before writable CTEs, of
      course, but now it's broken.  The executor fails to notice any problem
      because ExecEvalVar just references the ecxt_scantuple for any normal
      varno; but EXPLAIN breaks when the varno is wrong, as illustrated in a
      recent complaint from Bartosz Dmytrak.
      
      Since the eventual rtoffset of the subquery is not known at the time
      we are preparing its plan node, the previous scheme of executing
      set_returning_clause_references() at that time cannot handle this
      adjustment.  Fortunately, it turns out that we don't really need to do it
      that way, because all the needed information is available during normal
      setrefs.c execution; we just have to dig it out of the ModifyTable node.
      So, do that, and get rid of the kluge of early setrefs processing of
      RETURNING lists.  (This is a little bit of a cheat in the case of inherited
      UPDATE/DELETE, because we are not passing a "root" struct that corresponds
      exactly to what the subplan was built with.  But that doesn't matter, and
      anyway this is less ugly than early setrefs processing was.)
      
      Back-patch to 9.1, where the problem became possible to hit.
      9fa82c98
  14. 20 4月, 2012 1 次提交
    • T
      Revise parameterized-path mechanism to fix assorted issues. · 5b7b5518
      Tom Lane 提交于
      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
  15. 28 3月, 2012 1 次提交
    • T
      Add some infrastructure for contrib/pg_stat_statements. · a40fa613
      Tom Lane 提交于
      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
  16. 20 3月, 2012 1 次提交
    • T
      Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. · 9dbf2b7d
      Tom Lane 提交于
      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
  17. 15 2月, 2012 1 次提交
    • T
      Preserve column names in the execution-time tupledesc for a RowExpr. · 398f70ec
      Tom Lane 提交于
      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
  18. 29 1月, 2012 1 次提交
    • T
      Fix handling of init_plans list in inheritance_planner(). · 4ec6581c
      Tom Lane 提交于
      Formerly we passed an empty list to each per-child-table invocation of
      grouping_planner, and then merged the results into the global list.
      However, that fails if there's a CTE attached to the statement, because
      create_ctescan_plan uses the list to find the plan referenced by a CTE
      reference; so it was unable to find any CTEs attached to the outer UPDATE
      or DELETE.  But there's no real reason not to use the same list throughout
      the process, and doing so is simpler and faster anyway.
      
      Per report from Josh Berkus of "could not find plan for CTE" failures.
      Back-patch to 9.1 where we added support for WITH attached to UPDATE or
      DELETE.  Add some regression test cases, too.
      4ec6581c
  19. 28 1月, 2012 1 次提交
    • T
      Use parameterized paths to generate inner indexscans more flexibly. · e2fa76d8
      Tom Lane 提交于
      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
  20. 02 1月, 2012 1 次提交
  21. 25 12月, 2011 1 次提交
    • T
      Rethink representation of index clauses' mapping to index columns. · 472d3935
      Tom Lane 提交于
      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. 08 10月, 2011 1 次提交
    • T
      Support index-only scans using the visibility map to avoid heap fetches. · a2822fb9
      Tom Lane 提交于
      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
  23. 25 9月, 2011 1 次提交
    • T
      Recognize self-contradictory restriction clauses for non-table relations. · 7741dd65
      Tom Lane 提交于
      The constraint exclusion feature checks for contradictions among scan
      restriction clauses, as well as contradictions between those clauses and a
      table's CHECK constraints.  The first aspect of this testing can be useful
      for non-table relations (such as subqueries or functions-in-FROM), but the
      feature was coded with only the CHECK case in mind so we were applying it
      only to plain-table RTEs.  Move the relation_excluded_by_constraints call
      so that it is applied to all RTEs not just plain tables.  With the default
      setting of constraint_exclusion this results in no extra work, but with
      constraint_exclusion = ON we will detect optimizations that we missed
      before (at the cost of more planner cycles than we expended before).
      
      Per a gripe from Gunnlaugur Þór Briem.  Experimentation with
      his example also showed we were not being very bright about the case where
      constraint exclusion is proven within a subquery within UNION ALL, so tweak
      the code to allow set_append_rel_pathlist to recognize such cases.
      7741dd65
  24. 04 9月, 2011 1 次提交
    • T
      Rearrange planner to save the whole PlannerInfo (subroot) for a subquery. · b3aaf908
      Tom Lane 提交于
      Formerly, set_subquery_pathlist and other creators of plans for subqueries
      saved only the rangetable and rowMarks lists from the lower-level
      PlannerInfo.  But there's no reason not to remember the whole PlannerInfo,
      and indeed this turns out to simplify matters in a number of places.
      
      The immediate reason for doing this was so that the subroot will still be
      accessible when we're trying to extract column statistics out of an
      already-planned subquery.  But now that I've done it, it seems like a good
      code-beautification effort in its own right.
      
      I also chose to get rid of the transient subrtable and subrowmark fields in
      SubqueryScan nodes, in favor of having setrefs.c look up the subquery's
      RelOptInfo.  That required changing all the APIs in setrefs.c to pass
      PlannerInfo not PlannerGlobal, which was a large but quite mechanical
      transformation.
      
      One side-effect not foreseen at the beginning is that this finally broke
      inheritance_planner's assumption that replanning the same subquery RTE N
      times would necessarily give interchangeable results each time.  That
      assumption was always pretty risky, but now we really have to make a
      separate RTE for each instance so that there's a place to carry the
      separate subroots.
      b3aaf908
  25. 01 9月, 2011 1 次提交
  26. 17 7月, 2011 1 次提交
    • T
      Improve make_subplanTargetList to avoid including Vars unnecessarily. · 1bc16a94
      Tom Lane 提交于
      If a Var was used only in a GROUP BY expression, the previous
      implementation would include the Var by itself (as well as the expression)
      in the generated targetlist.  This wouldn't affect the efficiency of the
      scan/join part of the plan at all, but it could result in passing
      unnecessarily-wide rows through sorting and grouping steps.  It turns out
      to take only a little more code, and not noticeably more time, to generate
      a tlist without such redundancy, so let's do that.  Per a recent gripe from
      HarmeekSingh Bedi.
      1bc16a94
  27. 14 7月, 2011 1 次提交
  28. 13 7月, 2011 1 次提交
    • T
      Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window. · c1d9579d
      Tom Lane 提交于
      Regular aggregate functions in combination with, or within the arguments
      of, window functions are OK per spec; they have the semantics that the
      aggregate output rows are computed and then we run the window functions
      over that row set.  (Thus, this combination is not really useful unless
      there's a GROUP BY so that more than one aggregate output row is possible.)
      The case without GROUP BY could fail, as recently reported by Jeff Davis,
      because sloppy construction of the Agg node's targetlist resulted in extra
      references to possibly-ungrouped Vars appearing outside the aggregate
      function calls themselves.  See the added regression test case for an
      example.
      
      Fixing this requires modifying the API of flatten_tlist and its underlying
      function pull_var_clause.  I chose to make pull_var_clause's API for
      aggregates identical to what it was already doing for placeholders, since
      the useful behaviors turn out to be the same (error, report node as-is, or
      recurse into it).  I also tightened the error checking in this area a bit:
      if it was ever valid to see an uplevel Var, Aggref, or PlaceHolderVar here,
      that was a long time ago, so complain instead of ignoring them.
      
      Backpatch into 9.1.  The failure exists in 8.4 and 9.0 as well, but seeing
      that it only occurs in a basically-useless corner case, it doesn't seem
      worth the risks of changing a function API in a minor release.  There might
      be third-party code using pull_var_clause.
      c1d9579d
  29. 05 7月, 2011 1 次提交
  30. 10 6月, 2011 1 次提交
  31. 25 4月, 2011 1 次提交
    • T
      Improve cost estimation for aggregates and window functions. · e6a30a8c
      Tom Lane 提交于
      The previous coding failed to account properly for the costs of evaluating
      the input expressions of aggregates and window functions, as seen in a
      recent gripe from Claudio Freire.  (I said at the time that it wasn't
      counting these costs at all; but on closer inspection, it was effectively
      charging these costs once per output tuple.  That is completely wrong for
      aggregates, and not exactly right for window functions either.)
      
      There was also a hard-wired assumption that aggregates and window functions
      had procost 1.0, which is now fixed to respect the actual cataloged costs.
      
      The costing of WindowAgg is still pretty bogus, since it doesn't try to
      estimate the effects of spilling data to disk, but that seems like a
      separate issue.
      e6a30a8c
  32. 21 4月, 2011 1 次提交
    • T
      Make plan_cluster_use_sort cope with no IndexOptInfo for the target index. · 5b8e4429
      Tom Lane 提交于
      The original coding assumed that such a case represents caller error, but
      actually get_relation_info will omit generating an IndexOptInfo for any
      index it thinks is unsafe to use.  Therefore, handle this case by returning
      "true" to indicate that a seqscan-and-sort is the preferred way to
      implement the CLUSTER operation.  New bug in 9.1, no backpatch needed.
      Per bug #5985 from Daniel Grace.
      5b8e4429
  33. 10 4月, 2011 1 次提交
  34. 22 3月, 2011 1 次提交
    • T
      Reimplement planner's handling of MIN/MAX aggregate optimization (again). · 8df08c84
      Tom Lane 提交于
      Instead of playing cute games with pathkeys, just build a direct
      representation of the intended sub-select, and feed it through
      query_planner to get a Path for the index access.  This is a bit slower
      than 9.1's previous method, since we'll duplicate most of the overhead of
      query_planner; but since the whole optimization only applies to rather
      simple single-table queries, that probably won't be much of a problem in
      practice.  The advantage is that we get to do the right thing when there's
      a partial index that needs the implicit IS NOT NULL clause to be usable.
      Also, although this makes planagg.c be a bit more closely tied to the
      ordering of operations in grouping_planner, we can get rid of some coupling
      to lower-level parts of the planner.  Per complaint from Marti Raudsepp.
      8df08c84
  35. 26 2月, 2011 1 次提交
    • T
      Support data-modifying commands (INSERT/UPDATE/DELETE) in WITH. · 389af951
      Tom Lane 提交于
      This patch implements data-modifying WITH queries according to the
      semantics that the updates all happen with the same command counter value,
      and in an unspecified order.  Therefore one WITH clause can't see the
      effects of another, nor can the outer query see the effects other than
      through the RETURNING values.  And attempts to do conflicting updates will
      have unpredictable results.  We'll need to document all that.
      
      This commit just fixes the code; documentation updates are waiting on
      author.
      
      Marko Tiikkaja and Hitoshi Harada
      389af951
  36. 23 2月, 2011 1 次提交
    • T
      Add a relkind field to RangeTblEntry to avoid some syscache lookups. · bdca82f4
      Tom Lane 提交于
      The recent additions for FDW support required checking foreign-table-ness
      in several places in the parse/plan chain.  While it's not clear whether
      that would really result in a noticeable slowdown, it seems best to avoid
      any performance risk by keeping a copy of the relation's relkind in
      RangeTblEntry.  That might have some other uses later, anyway.
      Per discussion.
      bdca82f4
  37. 20 2月, 2011 1 次提交
  38. 10 2月, 2011 1 次提交
    • T
      Fix improper matching of resjunk column names for FOR UPDATE in subselect. · e617f0d7
      Tom Lane 提交于
      Flattening of subquery range tables during setrefs.c could lead to the
      rangetable indexes in PlanRowMark nodes not matching up with the column
      names previously assigned to the corresponding resjunk ctid (resp. tableoid
      or wholerow) columns.  Typical symptom would be either a "cannot extract
      system attribute from virtual tuple" error or an Assert failure.  This
      wasn't a problem before 9.0 because we didn't support FOR UPDATE below the
      top query level, and so the final flattening could never renumber an RTE
      that was relevant to FOR UPDATE.  Fix by using a plan-tree-wide unique
      number for each PlanRowMark to label the associated resjunk columns, so
      that the number need not change during flattening.
      
      Per report from David Johnston (though I'm darned if I can see how this got
      past initial testing of the relevant code).  Back-patch to 9.0.
      e617f0d7
  39. 14 1月, 2011 1 次提交
    • T
      Revert incorrect memory-conservation hack in inheritance_planner(). · f0f36045
      Tom Lane 提交于
      This reverts commit d1001a78 of 2010-12-05,
      which was broken as reported by Jeff Davis.  The problem is that the
      individual planning steps may have side-effects on substructures of
      PlannerGlobal, not only the current PlannerInfo root.  Arranging to keep
      all such side effects in the main planning context is probably possible,
      but it would change this from a quick local hack into a wide-ranging and
      rather fragile endeavor.  Which it's not worth.
      f0f36045
  40. 13 1月, 2011 1 次提交
    • T
      Fix PlanRowMark/ExecRowMark structures to handle inheritance correctly. · d487afbb
      Tom Lane 提交于
      In an inherited UPDATE/DELETE, each target table has its own subplan,
      because it might have a column set different from other targets.  This
      means that the resjunk columns we add to support EvalPlanQual might be
      at different physical column numbers in each subplan.  The EvalPlanQual
      rewrite I did for 9.0 failed to account for this, resulting in possible
      misbehavior or even crashes during concurrent updates to the same row,
      as seen in a recent report from Gordon Shannon.  Revise the data structure
      so that we track resjunk column numbers separately for each subplan.
      
      I also chose to move responsibility for identifying the physical column
      numbers back to executor startup, instead of assuming that numbers derived
      during preprocess_targetlist would stay valid throughout subsequent
      massaging of the plan.  That's a bit slower, so we might want to consider
      undoing it someday; but it would complicate the patch considerably and
      didn't seem justifiable in a bug fix that has to be back-patched to 9.0.
      d487afbb