1. 23 2月, 2007 1 次提交
    • T
      Turn the rangetable used by the executor into a flat list, and avoid storing · eab6b8b2
      Tom Lane 提交于
      useless substructure for its RangeTblEntry nodes.  (I chose to keep using the
      same struct node type and just zero out the link fields for unneeded info,
      rather than making a separate ExecRangeTblEntry type --- it seemed too
      fragile to have two different rangetable representations.)
      
      Along the way, put subplans into a list in the toplevel PlannedStmt node,
      and have SubPlan nodes refer to them by list index instead of direct pointers.
      Vadim wanted to do that years ago, but I never understood what he was on about
      until now.  It makes things a *whole* lot more robust, because we can stop
      worrying about duplicate processing of subplans during expression tree
      traversals.  That's been a constant source of bugs, and it's finally gone.
      
      There are some consequent simplifications yet to be made, like not using
      a separate EState for subplans in the executor, but I'll tackle that later.
      eab6b8b2
  2. 22 1月, 2007 1 次提交
    • T
      Add COST and ROWS options to CREATE/ALTER FUNCTION, plus underlying pg_proc · 5a7471c3
      Tom Lane 提交于
      columns procost and prorows, to allow simple user adjustment of the estimated
      cost of a function call, as well as control of the estimated number of rows
      returned by a set-returning function.  We might eventually wish to extend this
      to allow function-specific estimation routines, but there seems to be
      consensus that we should try a simple constant estimate first.  In particular
      this provides a relatively simple way to control the order in which different
      WHERE clauses are applied in a plan node, which is a Good Thing in view of the
      fact that the recent EquivalenceClass planner rewrite made that much less
      predictable than before.
      5a7471c3
  3. 21 1月, 2007 1 次提交
    • T
      Refactor planner's pathkeys data structure to create a separate, explicit · f41803bb
      Tom Lane 提交于
      representation of equivalence classes of variables.  This is an extensive
      rewrite, but it brings a number of benefits:
      * planner no longer fails in the presence of "incomplete" operator families
      that don't offer operators for every possible combination of datatypes.
      * avoid generating and then discarding redundant equality clauses.
      * remove bogus assumption that derived equalities always use operators
      named "=".
      * mergejoins can work with a variety of sort orders (e.g., descending) now,
      instead of tying each mergejoinable operator to exactly one sort order.
      * better recognition of redundant sort columns.
      * can make use of equalities appearing underneath an outer join.
      f41803bb
  4. 11 1月, 2007 1 次提交
    • T
      Change the planner-to-executor API so that the planner tells the executor · a191a169
      Tom Lane 提交于
      which comparison operators to use for plan nodes involving tuple comparison
      (Agg, Group, Unique, SetOp).  Formerly the executor looked up the default
      equality operator for the datatype, which was really pretty shaky, since it's
      possible that the data being fed to the node is sorted according to some
      nondefault operator class that could have an incompatible idea of equality.
      The planner knows what it has sorted by and therefore can provide the right
      equality operator to use.  Also, this change moves a couple of catalog lookups
      out of the executor and into the planner, which should help startup time for
      pre-planned queries by some small amount.  Modify the planner to remove some
      other cavalier assumptions about always being able to use the default
      operators.  Also add "nulls first/last" info to the Plan node for a mergejoin
      --- neither the executor nor the planner can cope yet, but at least the API is
      in place.
      a191a169
  5. 06 1月, 2007 1 次提交
  6. 12 8月, 2006 1 次提交
  7. 26 7月, 2006 1 次提交
  8. 02 7月, 2006 1 次提交
    • T
      Revise the planner's handling of "pseudoconstant" WHERE clauses, that is · cffd89ca
      Tom Lane 提交于
      clauses containing no variables and no volatile functions.  Such a clause
      can be used as a one-time qual in a gating Result plan node, to suppress
      plan execution entirely when it is false.  Even when the clause is true,
      putting it in a gating node wins by avoiding repeated evaluation of the
      clause.  In previous PG releases, query_planner() would do this for
      pseudoconstant clauses appearing at the top level of the jointree, but
      there was no ability to generate a gating Result deeper in the plan tree.
      To fix it, get rid of the special case in query_planner(), and instead
      process pseudoconstant clauses through the normal RestrictInfo qual
      distribution mechanism.  When a pseudoconstant clause is found attached to
      a path node in create_plan(), pull it out and generate a gating Result at
      that point.  This requires special-casing pseudoconstants in selectivity
      estimation and cost_qual_eval, but on the whole it's pretty clean.
      It probably even makes the planner a bit faster than before for the normal
      case of no pseudoconstants, since removing pull_constant_clauses saves one
      useless traversal of the qual tree.  Per gripe from Phil Frost.
      cffd89ca
  9. 05 3月, 2006 1 次提交
  10. 20 12月, 2005 1 次提交
  11. 15 10月, 2005 1 次提交
  12. 29 9月, 2005 1 次提交
  13. 28 8月, 2005 1 次提交
    • T
      Change the division of labor between grouping_planner and query_planner · 4e5fbb34
      Tom Lane 提交于
      so that the latter estimates the number of groups that grouping will
      produce.  This is needed because it is primarily query_planner that
      makes the decision between fast-start and fast-finish plans, and in the
      original coding it was unable to make more than a crude rule-of-thumb
      choice when the query involved grouping.  This revision helps us make
      saner choices for queries like SELECT ... GROUP BY ... LIMIT, as in a
      recent example from Mark Kirkwood.  Also move the responsibility for
      canonicalizing sort_pathkeys and group_pathkeys into query_planner;
      this information has to be available anyway to support the first change,
      and doing it this way lets us get rid of compare_noncanonical_pathkeys
      entirely.
      4e5fbb34
  14. 19 8月, 2005 1 次提交
    • T
      Fix up LIMIT/OFFSET planning so that we cope with non-constant LIMIT · dfdf07aa
      Tom Lane 提交于
      or OFFSET clauses by using estimate_expression_value().  The main advantage
      of this is that if the expression is a Param and we have a value for the
      Param, we'll use that value rather than defaulting.  Also, fix some
      thinkos in the logic for combining LIMIT/OFFSET with an externally
      supplied tuple fraction (this covers cases like EXISTS(...LIMIT...)).
      And make sure the results of all this are shown by EXPLAIN.  Per a
      gripe from Merlin Moncure.
      dfdf07aa
  15. 06 6月, 2005 1 次提交
    • T
      Remove planner's private fields from Query struct, and put them into · 9ab4d981
      Tom Lane 提交于
      a new PlannerInfo struct, which is passed around instead of the bare
      Query in all the planning code.  This commit is essentially just a
      code-beautification exercise, but it does open the door to making
      larger changes to the planner data structures without having to muck
      with the widely-known Query struct.
      9ab4d981
  16. 23 5月, 2005 1 次提交
    • T
      Teach the planner to remove SubqueryScan nodes from the plan if they · e2159f38
      Tom Lane 提交于
      aren't doing anything useful (ie, neither selection nor projection).
      Also, extend to SubqueryScan the hacks already in place to avoid
      unnecessary ExecProject calls when the result would just be the same
      tuple the subquery already delivered.  This saves some overhead in
      UNION and other set operations, as well as avoiding overhead for
      unflatten-able subqueries.  Per example from Sokolov Yura.
      e2159f38
  17. 25 4月, 2005 2 次提交
  18. 12 4月, 2005 2 次提交
  19. 11 3月, 2005 1 次提交
    • T
      Make the behavior of HAVING without GROUP BY conform to the SQL spec. · 595ed2a8
      Tom Lane 提交于
      Formerly, if such a clause contained no aggregate functions we mistakenly
      treated it as equivalent to WHERE.  Per spec it must cause the query to
      be treated as a grouped query of a single group, the same as appearance
      of aggregate functions would do.  Also, the HAVING filter must execute
      after aggregate function computation even if it itself contains no
      aggregate functions.
      595ed2a8
  20. 01 1月, 2005 1 次提交
    • P
      · 2ff50159
      PostgreSQL Daemon 提交于
      Tag appropriate files for rc3
      
      Also performed an initial run through of upgrading our Copyright date to
      extend to 2005 ... first run here was very simple ... change everything
      where: grep 1996-2004 && the word 'Copyright' ... scanned through the
      generated list with 'less' first, and after, to make sure that I only
      picked up the right entries ...
      2ff50159
  21. 29 8月, 2004 1 次提交
  22. 18 1月, 2004 1 次提交
    • T
      When testing whether a sub-plan can do projection, use a general-purpose · 6bdfde9a
      Tom Lane 提交于
      check instead of hardwiring assumptions that only certain plan node types
      can appear at the places where we are testing.  This was always a pretty
      fragile assumption, and it turns out to be broken in 7.4 for certain cases
      involving IN-subselect tests that need type coercion.
      Also, modify code that builds finished Plan tree so that node types that
      don't do projection always copy their input node's targetlist, rather than
      having the tlist passed in from the caller.  The old method makes it too
      easy to write broken code that thinks it can modify the tlist when it
      cannot.
      6bdfde9a
  23. 30 11月, 2003 1 次提交
    • P
      · 55b11325
      PostgreSQL Daemon 提交于
      make sure the $Id tags are converted to $PostgreSQL as well ...
      55b11325
  24. 09 8月, 2003 1 次提交
  25. 04 8月, 2003 2 次提交
  26. 30 6月, 2003 1 次提交
    • T
      Restructure building of join relation targetlists so that a join plan · 835bb975
      Tom Lane 提交于
      node emits only those vars that are actually needed above it in the
      plan tree.  (There were comments in the code suggesting that this was
      done at some point in the dim past, but for a long time we have just
      made join nodes emit everything that either input emitted.)  Aside from
      being marginally more efficient, this fixes the problem noted by Peter
      Eisentraut where a join above an IN-implemented-as-join might fail,
      because the subplan targetlist constructed in the latter case didn't
      meet the expectation of including everything.
      Along the way, fix some places that were O(N^2) in the targetlist
      length.  This is not all the trouble spots for wide queries by any
      means, but it's a step forward.
      835bb975
  27. 29 6月, 2003 1 次提交
    • T
      Support expressions of the form 'scalar op ANY (array)' and · bee21792
      Tom Lane 提交于
      'scalar op ALL (array)', where the operator is applied between the
      lefthand scalar and each element of the array.  The operator must
      yield boolean; the result of the construct is the OR or AND of the
      per-element results, respectively.
      
      Original coding by Joe Conway, after an idea of Peter's.  Rewritten
      by Tom to keep the implementation strictly separate from subqueries.
      bee21792
  28. 06 5月, 2003 1 次提交
    • T
      Implement feature of new FE/BE protocol whereby RowDescription identifies · 2cf57c8f
      Tom Lane 提交于
      the column by table OID and column number, if it's a simple column
      reference.  Along the way, get rid of reskey/reskeyop fields in Resdoms.
      Turns out that representation was not convenient for either the planner
      or the executor; we can make the planner deliver exactly what the
      executor wants with no more effort.
      initdb forced due to change in stored rule representation.
      2cf57c8f
  29. 10 3月, 2003 1 次提交
    • T
      Restructure parsetree representation of DECLARE CURSOR: now it's a · aa83bc04
      Tom Lane 提交于
      utility statement (DeclareCursorStmt) with a SELECT query dangling from
      it, rather than a SELECT query with a few unusual fields in it.  Add
      code to determine whether a planned query can safely be run backwards.
      If DECLARE CURSOR specifies SCROLL, ensure that the plan can be run
      backwards by adding a Materialize plan node if it can't.  Without SCROLL,
      you get an error if you try to fetch backwards from a cursor that can't
      handle it.  (There is still some discussion about what the exact
      behavior should be, but this is necessary infrastructure in any case.)
      Along the way, make EXPLAIN DECLARE CURSOR work.
      aa83bc04
  30. 24 1月, 2003 1 次提交
    • T
      Modify planner's implied-equality-deduction code so that when a set · f5e83662
      Tom Lane 提交于
      of known-equal expressions includes any constant expressions (including
      Params from outer queries), we actively suppress any 'var = var'
      clauses that are or could be deduced from the set, generating only the
      deducible 'var = const' clauses instead.  The idea here is to push down
      the restrictions implied by the equality set to base relations whenever
      possible.  Once we have applied the 'var = const' clauses, the 'var = var'
      clauses are redundant, and should be suppressed both to save work at
      execution and to avoid double-counting restrictivity.
      f5e83662
  31. 21 1月, 2003 1 次提交
    • T
      IN clauses appearing at top level of WHERE can now be handled as joins. · bdfbfde1
      Tom Lane 提交于
      There are two implementation techniques: the executor understands a new
      JOIN_IN jointype, which emits at most one matching row per left-hand row,
      or the result of the IN's sub-select can be fed through a DISTINCT filter
      and then joined as an ordinary relation.
      Along the way, some minor code cleanup in the optimizer; notably, break
      out most of the jointree-rearrangement preprocessing in planner.c and
      put it in a new file prep/prepjointree.c.
      bdfbfde1
  32. 16 1月, 2003 2 次提交
    • T
      Now that switch_outer processing no longer relies on being run after · cde9f852
      Tom Lane 提交于
      join_references(), it's practical to consolidate all join_references()
      processing into the set_plan_references traversal in setrefs.c.  This
      seems considerably cleaner than the old way where we did it for join
      quals in createplan.c and for targetlists in setrefs.c.
      cde9f852
    • T
      Allow merge and hash joins to occur on arbitrary expressions (anything not · de97072e
      Tom Lane 提交于
      containing a volatile function), rather than only on 'Var = Var' clauses
      as before.  This makes it practical to do flatten_join_alias_vars at the
      start of planning, which in turn eliminates a bunch of klugery inside the
      planner to deal with alias vars.  As a free side effect, we now detect
      implied equality of non-Var expressions; for example in
      	SELECT ... WHERE a.x = b.y and b.y = 42
      we will deduce a.x = 42 and use that as a restriction qual on a.  Also,
      we can remove the restriction introduced 12/5/02 to prevent pullup of
      subqueries whose targetlists contain sublinks.
      Still TODO: make statistical estimation routines in selfuncs.c and costsize.c
      smarter about expressions that are more complex than plain Vars.  The need
      for this is considerably greater now that we have to be able to estimate
      the suitability of merge and hash join techniques on such expressions.
      de97072e
  33. 12 12月, 2002 1 次提交
    • T
      Phase 2 of read-only-plans project: restructure expression-tree nodes · a0bf885f
      Tom Lane 提交于
      so that all executable expression nodes inherit from a common supertype
      Expr.  This is somewhat of an exercise in code purity rather than any
      real functional advance, but getting rid of the extra Oper or Func node
      formerly used in each operator or function call should provide at least
      a little space and speed improvement.
      initdb forced by changes in stored-rules representation.
      a0bf885f
  34. 21 11月, 2002 1 次提交
  35. 20 11月, 2002 1 次提交
  36. 06 11月, 2002 1 次提交
    • T
      First phase of implementing hash-based grouping/aggregation. An AGG plan · f6dba10e
      Tom Lane 提交于
      node now does its own grouping of the input rows, and has no need for a
      preceding GROUP node in the plan pipeline.  This allows elimination of
      the misnamed tuplePerGroup option for GROUP, and actually saves more code
      in nodeGroup.c than it costs in nodeAgg.c, as well as being presumably
      faster.  Restructure the API of query_planner so that we do not commit to
      using a sorted or unsorted plan in query_planner; instead grouping_planner
      makes the decision.  (Right now it isn't any smarter than query_planner
      was, but that will change as soon as it has the option to select a hash-
      based aggregation step.)  Despite all the hackery, no initdb needed since
      only in-memory node types changed.
      f6dba10e