1. 04 8月, 2008 1 次提交
  2. 03 8月, 2008 1 次提交
    • T
      Rearrange the querytree representation of ORDER BY/GROUP BY/DISTINCT items · 95113047
      Tom Lane 提交于
      as per my recent proposal:
      
      1. Fold SortClause and GroupClause into a single node type SortGroupClause.
      We were already relying on them to be struct-equivalent, so using two node
      tags wasn't accomplishing much except to get in the way of comparing items
      with equal().
      
      2. Add an "eqop" field to SortGroupClause to carry the associated equality
      operator.  This is cheap for the parser to get at the same time it's looking
      up the sort operator, and storing it eliminates the need for repeated
      not-so-cheap lookups during planning.  In future this will also let us
      represent GROUP/DISTINCT operations on datatypes that have hash opclasses
      but no btree opclasses (ie, they have equality but no natural sort order).
      The previous representation simply didn't work for that, since its only
      indicator of comparison semantics was a sort operator.
      
      3. Add a hasDistinctOn boolean to struct Query to explicitly record whether
      the distinctClause came from DISTINCT or DISTINCT ON.  This allows removing
      some complicated and not 100% bulletproof code that attempted to figure
      that out from the distinctClause alone.
      
      This patch doesn't in itself create any new capability, but it's necessary
      infrastructure for future attempts to use hash-based grouping for DISTINCT
      and UNION/INTERSECT/EXCEPT.
      95113047
  3. 01 8月, 2008 1 次提交
    • T
      Fix parser so that we don't modify the user-written ORDER BY list in order · 63247bec
      Tom Lane 提交于
      to represent DISTINCT or DISTINCT ON.  This gets rid of a longstanding
      annoyance that a view or rule using SELECT DISTINCT will be dumped out
      with an overspecified ORDER BY list, and is one small step along the way
      to decoupling DISTINCT and ORDER BY enough so that hash-based implementation
      of DISTINCT will be possible.  In passing, improve transformDistinctClause
      so that it doesn't reject duplicate DISTINCT ON items, as was reported by
      Steve Midgley a couple weeks ago.
      63247bec
  4. 10 7月, 2008 1 次提交
    • T
      Tighten up SS_finalize_plan's computation of valid_params to exclude Params of · eaf1b5d3
      Tom Lane 提交于
      the current query level that aren't in fact output parameters of the current
      initPlans.  (This means, for example, output parameters of regular subplans.)
      To make this work correctly for output parameters coming from sibling
      initplans requires rejiggering the API of SS_finalize_plan just a bit:
      we need the siblings to be visible to it, rather than hidden as
      SS_make_initplan_from_plan had been doing.  This is really part of my response
      to bug #4290, but I concluded this part probably shouldn't be back-patched,
      since all that it's doing is to make a debugging cross-check tighter.
      eaf1b5d3
  5. 03 5月, 2008 1 次提交
  6. 18 4月, 2008 1 次提交
    • T
      Fix a couple of oversights associated with the "physical tlist" optimization: · 25e46a50
      Tom Lane 提交于
      we had several code paths where a physical tlist could be used for the input
      to a Sort node, which is a dumb idea because any unneeded table columns will
      increase the volume of data the sort has to push around.
      
      (Unfortunately the easy-looking fix of calling disuse_physical_tlist during
      make_sort_xxx doesn't work because in most cases we're already committed to
      the current input tlist --- it's been marked with sort column numbers, or
      we've built grouping column numbers using it, etc.  The tlist has to be
      selected properly at the calling level before we start constructing sort-col
      information.  This is easy enough to do, we were just failing to take the
      point into consideration.)
      
      Back-patch to 8.3.  I believe the problem probably exists clear back to 7.4
      when the physical tlist optimization was added, but I'm afraid to back-patch
      further than 8.3 without a great deal more study than I want to put into it.
      The code in this area has drifted a lot over time.  The real-world importance
      of these code paths is uncertain anyway --- I think in many cases we'd
      probably prefer hash-based methods.
      25e46a50
  7. 01 4月, 2008 1 次提交
    • T
      Fix an oversight I made in a cleanup patch over a year ago: · 6b73d7e5
      Tom Lane 提交于
      eval_const_expressions needs to be passed the PlannerInfo ("root") structure,
      because in some cases we want it to substitute values for Param nodes.
      (So "constant" is not so constant as all that ...)  This mistake partially
      disabled optimization of unnamed extended-Query statements in 8.3: in
      particular the LIKE-to-indexscan optimization would never be applied if the
      LIKE pattern was passed as a parameter, and constraint exclusion depending
      on a parameter value didn't work either.
      6b73d7e5
  8. 29 3月, 2008 1 次提交
  9. 28 3月, 2008 2 次提交
    • T
      Department of second thoughts: the rule that ORDER BY and DISTINCT are · 2e4094da
      Tom Lane 提交于
      useless for an ungrouped-aggregate query holds regardless of whether
      optimize_minmax_aggregates succeeds.  So we might as well apply the
      optimization in any case.
      
      I'll leave 8.3 as it was, since this version is a tad more invasive
      than my earlier patch.
      2e4094da
    • T
      When we have successfully optimized a MIN or MAX aggregate into an indexscan, · ff72280c
      Tom Lane 提交于
      the query result must be exactly one row (since we don't do this when there's
      any GROUP BY).  Therefore any ORDER BY or DISTINCT attached to the query is
      useless and can be dropped.  Aside from saving useless cycles, this protects
      us against problems with matching the hacked-up tlist entries to sort clauses,
      as seen in a bug report from Taiki Yamaguchi.  We might need to work harder
      if we ever try to optimize grouped queries with this approach, but this
      solution will do for now.
      ff72280c
  10. 19 3月, 2008 1 次提交
  11. 02 1月, 2008 1 次提交
  12. 16 11月, 2007 2 次提交
  13. 12 10月, 2007 1 次提交
    • T
      Fix the plan-invalidation mechanism to treat regclass constants that refer to · 82d8ab6f
      Tom Lane 提交于
      a relation as a reason to invalidate a plan when the relation changes.  This
      handles scenarios such as dropping/recreating a sequence that is referenced by
      nextval('seq') in a cached plan.  Rather than teach plancache.c all about
      digging through plan trees to find regclass Consts, we charge the planner's
      setrefs.c with making a list of the relation OIDs on which each plan depends.
      That way the list can be built cheaply during a plan tree traversal that has
      to happen anyway.  Per bug #3662 and subsequent discussion.
      82d8ab6f
  14. 21 9月, 2007 1 次提交
    • T
      HOT updates. When we update a tuple without changing any of its indexed · 282d2a03
      Tom Lane 提交于
      columns, and the new version can be stored on the same heap page, we no longer
      generate extra index entries for the new version.  Instead, index searches
      follow the HOT-chain links to ensure they find the correct tuple version.
      
      In addition, this patch introduces the ability to "prune" dead tuples on a
      per-page basis, without having to do a complete VACUUM pass to recover space.
      VACUUM is still needed to clean up dead index entries, however.
      
      Pavan Deolasee, with help from a bunch of other people.
      282d2a03
  15. 27 5月, 2007 1 次提交
    • T
      Repair two constraint-exclusion corner cases triggered by proving that an · cadb7833
      Tom Lane 提交于
      inheritance child of an UPDATE/DELETE target relation can be excluded by
      constraints.  I had rearranged some code in set_append_rel_pathlist() to
      avoid "useless" work when a child is excluded, but overdid it and left
      the child with no cheapest_path entry, causing possible failure later
      if the appendrel was involved in a join.  Also, it seems that the dummy
      plan generated by inheritance_planner() when all branches are excluded
      has to be a bit less dummy now than was required in 8.2.
      Per report from Jan Wieck.  Add his test case to the regression tests.
      cadb7833
  16. 26 5月, 2007 1 次提交
    • T
      Create hooks to let a loadable plugin monitor (or even replace) the planner · 604ffd28
      Tom Lane 提交于
      and/or create plans for hypothetical situations; in particular, investigate
      plans that would be generated using hypothetical indexes.  This is a
      heavily-rewritten version of the hooks proposed by Gurjeet Singh for his
      Index Advisor project.  In this formulation, the index advisor can be
      entirely a loadable module instead of requiring a significant part to be
      in the core backend, and plans can be generated for hypothetical indexes
      without requiring the creation and rolling-back of system catalog entries.
      
      The index advisor patch as-submitted is not compatible with these hooks,
      but it needs significant work anyway due to other 8.2-to-8.3 planner
      changes.  With these hooks in the core backend, development of the advisor
      can proceed as a pgfoundry project.
      604ffd28
  17. 04 5月, 2007 1 次提交
    • T
      Teach tuplesort.c about "top N" sorting, in which only the first N tuples · d26559db
      Tom Lane 提交于
      need be returned.  We keep a heap of the current best N tuples and sift-up
      new tuples into it as we scan the input.  For M input tuples this means
      only about M*log(N) comparisons instead of M*log(M), not to mention a lot
      less workspace when N is small --- avoiding spill-to-disk for large M
      is actually the most attractive thing about it.  Patch includes planner
      and executor support for invoking this facility in ORDER BY ... LIMIT
      queries.  Greg Stark, with some editorialization by moi.
      d26559db
  18. 28 4月, 2007 1 次提交
    • T
      Modify processing of DECLARE CURSOR and EXPLAIN so that they can resolve the · bbbe825f
      Tom Lane 提交于
      types of unspecified parameters when submitted via extended query protocol.
      This worked in 8.2 but I had broken it during plancache changes.  DECLARE
      CURSOR is now treated almost exactly like a plain SELECT through parse
      analysis, rewrite, and planning; only just before sending to the executor
      do we divert it away to ProcessUtility.  This requires a special-case check
      in a number of places, but practically all of them were already special-casing
      SELECT INTO, so it's not too ugly.  (Maybe it would be a good idea to merge
      the two by treating IntoClause as a form of utility statement?  Not going to
      worry about that now, though.)  That approach doesn't work for EXPLAIN,
      however, so for that I punted and used a klugy solution of running parse
      analysis an extra time if under extended query protocol.
      bbbe825f
  19. 16 4月, 2007 1 次提交
    • T
      Expose more cursor-related functionality in SPI: specifically, allow · 66888f74
      Tom Lane 提交于
      access to the planner's cursor-related planning options, and provide new
      FETCH/MOVE routines that allow access to the full power of those commands.
      Small refactoring of planner(), pg_plan_query(), and pg_plan_queries()
      APIs to make it convenient to pass the planning options down from SPI.
      
      This is the core-code portion of Pavel Stehule's patch for scrollable
      cursor support in plpgsql; I'll review and apply the plpgsql changes
      separately.
      66888f74
  20. 27 2月, 2007 1 次提交
    • T
      Get rid of the separate EState for subplans, and just let them share the · c7ff7663
      Tom Lane 提交于
      parent query's EState.  Now that there's a single flat rangetable for both
      the main plan and subplans, there's no need anymore for a separate EState,
      and removing it allows cleaning up some crufty code in nodeSubplan.c and
      nodeSubqueryscan.c.  Should be a tad faster too, although any difference
      will probably be hard to measure.  This is the last bit of subsidiary
      mop-up work from changing to a flat rangetable.
      c7ff7663
  21. 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
  22. 21 2月, 2007 1 次提交
    • T
      Remove the Query structure from the executor's API. This allows us to stop · 9cbd0c15
      Tom Lane 提交于
      storing mostly-redundant Query trees in prepared statements, portals, etc.
      To replace Query, a new node type called PlannedStmt is inserted by the
      planner at the top of a completed plan tree; this carries just the fields of
      Query that are still needed at runtime.  The statement lists kept in portals
      etc. now consist of intermixed PlannedStmt and bare utility-statement nodes
      --- no Query.  This incidentally allows us to remove some fields from Query
      and Plan nodes that shouldn't have been there in the first place.
      
      Still to do: simplify the execution-time range table; at the moment the
      range table passed to the executor still contains Query trees for subqueries.
      
      initdb forced due to change of stored rules.
      9cbd0c15
  23. 19 2月, 2007 1 次提交
    • T
      Get rid of some old and crufty global variables in the planner. When · 7c5e5439
      Tom Lane 提交于
      this code was last gone over, there wasn't really any alternative to
      globals because we didn't have the PlannerInfo struct being passed all
      through the planner code.  Now that we do, we can restructure things
      to avoid non-reentrancy.  I'm fooling with this because otherwise I'd
      have had to add another global variable for the planned compact
      range table list.
      7c5e5439
  24. 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
  25. 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
  26. 06 1月, 2007 1 次提交
  27. 04 10月, 2006 1 次提交
  28. 12 8月, 2006 1 次提交
  29. 06 8月, 2006 1 次提交
  30. 02 8月, 2006 1 次提交
  31. 27 7月, 2006 1 次提交
  32. 26 7月, 2006 1 次提交
  33. 14 7月, 2006 1 次提交
  34. 12 7月, 2006 1 次提交
  35. 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
  36. 29 6月, 2006 1 次提交
  37. 05 3月, 2006 1 次提交
  38. 04 2月, 2006 1 次提交
    • T
      Teach planner to convert simple UNION ALL subqueries into append relations, · 8b109ebf
      Tom Lane 提交于
      thereby sharing code with the inheritance case.  This puts the UNION-ALL-view
      approach to partitioned tables on par with inheritance, so far as constraint
      exclusion is concerned: it works either way.  (Still need to update the docs
      to say so.)  The definition of "simple UNION ALL" is a little simpler than
      I would like --- basically the union arms can only be SELECT * FROM foo
      --- but it's good enough for partitioned-table cases.
      8b109ebf