1. 13 Mar, 2007 1 commit
    • Tom Lane's avatar
      First phase of plan-invalidation project: create a plan cache management · b9527e98
      Tom Lane authored
      module and teach PREPARE and protocol-level prepared statements to use it.
      In service of this, rearrange utility-statement processing so that parse
      analysis does not assume table schemas can't change before execution for
      utility statements (necessary because we don't attempt to re-acquire locks
      for utility statements when reusing a stored plan).  This requires some
      refactoring of the ProcessUtility API, but it ends up cleaner anyway,
      for instance we can get rid of the QueryContext global.
      
      Still to do: fix up SPI and related code to use the plan cache; I'm tempted to
      try to make SQL functions use it too.  Also, there are at least some aspects
      of system state that we want to ensure remain the same during a replan as in
      the original processing; search_path certainly ought to behave that way for
      instance, and perhaps there are others.
      b9527e98
  2. 23 Feb, 2007 1 commit
    • Tom Lane's avatar
      Now that plans have flat rangetable lists, it's a lot easier to get EXPLAIN to · 655aa5b3
      Tom Lane authored
      drill down into subplan targetlists to print the referent expression for an
      OUTER or INNER var in an upper plan node.  Hence, make it do that always, and
      banish the old hack of showing "?columnN?" when things got too complicated.
      
      Along the way, fix an EXPLAIN bug I introduced by suppressing subqueries from
      execution-time range tables: get_name_for_var_field() assumed it could look at
      rte->subquery to find out the real type of a RECORD var.  That doesn't work
      anymore, but instead we can look at the input plan of the SubqueryScan plan
      node.
      655aa5b3
  3. 22 Feb, 2007 2 commits
    • Tom Lane's avatar
      Change Agg and Group nodes so that Vars contained in their targetlists · cc77005d
      Tom Lane authored
      and quals have varno OUTER, rather than zero, to indicate a reference to
      an output of their lefttree subplan.  This is consistent with the way
      that every other upper-level node type does it, and allows some simplifications
      in setrefs.c and EXPLAIN.
      cc77005d
    • Tom Lane's avatar
      Turn the rangetable used by the executor into a flat list, and avoid storing · eab6b8b2
      Tom Lane authored
      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
  4. 20 Feb, 2007 1 commit
    • Tom Lane's avatar
      Remove the Query structure from the executor's API. This allows us to stop · 9cbd0c15
      Tom Lane authored
      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
  5. 19 Feb, 2007 1 commit
  6. 14 Feb, 2007 1 commit
    • Tom Lane's avatar
      Fix up foreign-key mechanism so that there is a sound semantic basis for the · 7bddca34
      Tom Lane authored
      equality checks it applies, instead of a random dependence on whatever
      operators might be named "=".  The equality operators will now be selected
      from the opfamily of the unique index that the FK constraint depends on to
      enforce uniqueness of the referenced columns; therefore they are certain to be
      consistent with that index's notion of equality.  Among other things this
      should fix the problem noted awhile back that pg_dump may fail for foreign-key
      constraints on user-defined types when the required operators aren't in the
      search path.  This also means that the former warning condition about "foreign
      key constraint will require costly sequential scans" is gone: if the
      comparison condition isn't indexable then we'll reject the constraint
      entirely. All per past discussions.
      
      Along the way, make the RI triggers look into pg_constraint for their
      information, instead of using pg_trigger.tgargs; and get rid of the always
      error-prone fixed-size string buffers in ri_triggers.c in favor of building up
      the RI queries in StringInfo buffers.
      
      initdb forced due to columns added to pg_constraint and pg_trigger.
      7bddca34
  7. 05 Jan, 2007 1 commit
  8. 04 Oct, 2006 1 commit
  9. 06 Sep, 2006 1 commit
    • Tom Lane's avatar
      Change processing of extended-Query mode so that an unnamed statement · 5983a1aa
      Tom Lane authored
      that has parameters is always planned afresh for each Bind command,
      treating the parameter values as constants in the planner.  This removes
      the performance penalty formerly often paid for using out-of-line
      parameters --- with this definition, the planner can do constant folding,
      LIKE optimization, etc.  After a suggestion by Andrew@supernews.
      5983a1aa
  10. 02 Aug, 2006 1 commit
  11. 14 Jul, 2006 1 commit
  12. 13 Jul, 2006 1 commit
  13. 08 Apr, 2006 1 commit
    • Tom Lane's avatar
      Fix EXPLAIN so that it can drill down through multiple levels of subplan · c6e81aee
      Tom Lane authored
      when trying to locate the referent of a RECORD variable.  This fixes the
      'record type has not been registered' failure reported by Stefan
      Kaltenbrunner about a month ago.  A side effect of the way I chose to
      fix it is that most variable references in join conditions will now be
      properly labeled with the variable's source table name, instead of the
      not-too-helpful 'outer' or 'inner' we used to use.
      c6e81aee
  14. 05 Mar, 2006 1 commit
  15. 01 Mar, 2006 1 commit
    • Neil Conway's avatar
      Attached is a patch that replaces a bunch of places where StringInfos · 0d9742f9
      Neil Conway authored
      are unnecessarily allocated on the heap rather than the stack. If the
      StringInfo doesn't outlive the stack frame in which it is created,
      there is no need to allocate it on the heap via makeStringInfo() --
      stack allocation is faster.  While it's not a big deal unless the
      code is in a critical path, I don't see a reason not to save a few
      cycles -- using stack allocation is not less readable.
      
      I also cleaned up a bit of code along the way: moved variable
      declarations into a more tightly-enclosing scope where possible,
      fixed some pointless copying of strings in dblink, etc.
      0d9742f9
  16. 28 Feb, 2006 1 commit
    • Tom Lane's avatar
      Extend the ExecInitNode API so that plan nodes receive a set of flag · 2c0ef977
      Tom Lane authored
      bits indicating which optional capabilities can actually be exercised
      at runtime.  This will allow Sort and Material nodes, and perhaps later
      other nodes, to avoid unnecessary overhead in common cases.
      This commit just adds the infrastructure and arranges to pass the correct
      flag values down to plan nodes; none of the actual optimizations are here
      yet.  I'm committing this separately in case anyone wants to measure the
      added overhead.  (It should be negligible.)
      
      Simon Riggs and Tom Lane
      2c0ef977
  17. 05 Feb, 2006 1 commit
    • Tom Lane's avatar
      Improve my initial, rather hacky implementation of joins to append · 336a6491
      Tom Lane authored
      relations: fix the executor so that we can have an Append plan on the
      inside of a nestloop and still pass down outer index keys to index scans
      within the Append, then generate such plans as if they were regular
      inner indexscans.  This avoids the need to evaluate the outer relation
      multiple times.
      336a6491
  18. 29 Nov, 2005 1 commit
  19. 26 Nov, 2005 1 commit
  20. 22 Nov, 2005 1 commit
  21. 21 Oct, 2005 1 commit
    • Tom Lane's avatar
      Fix EXPLAIN ANALYZE bug noted by Wiebe Cazemier: although we were · 9fc24f2b
      Tom Lane authored
      properly advancing the CommandCounter between multiple sub-queries
      generated by rules, we forgot to update the snapshot being used, so
      that the successive sub-queries didn't actually see each others'
      results.  This is still not *exactly* like the semantics of normal
      execution of the same queries, in that we don't take new transaction
      snapshots and hence don't see changes from concurrently committed
      commands, but I think that's OK and probably even preferable for
      EXPLAIN ANALYZE.
      9fc24f2b
  22. 15 Oct, 2005 1 commit
  23. 04 Jun, 2005 1 commit
  24. 03 Jun, 2005 1 commit
    • Tom Lane's avatar
      Revise handling of dropped columns in JOIN alias lists to avoid a · ba420024
      Tom Lane authored
      performance problem pointed out by phil@vodafone: to wit, we were
      spending O(N^2) time to check dropped-ness in an N-deep join tree,
      even in the case where the tree was freshly constructed and couldn't
      possibly mention any dropped columns.  Instead of recursing in
      get_rte_attribute_is_dropped(), change the data structure definition:
      the joinaliasvars list of a JOIN RTE must have a NULL Const instead
      of a Var at any position that references a now-dropped column.  This
      costs nothing during normal parse-rewrite-plan path, and instead we
      have a linear-time update to make when loading a stored rule that
      might contain now-dropped columns.  While at it, move the responsibility
      for acquring locks on relations referenced by rules into this separate
      function (which I therefore chose to call AcquireRewriteLocks).
      This saves effort --- namely, duplicated lock grabs in parser and rewriter
      --- in the normal path at a cost of one extra non-locked heap_open()
      in the stored-rule path; seems a good tradeoff.  A fringe benefit is
      that it is now *much* clearer that we acquire lock on relations referenced
      in rules before we make any rewriter decisions based on their properties.
      (I don't know of any bug of that ilk, but it wasn't exactly clear before.)
      ba420024
  25. 25 Apr, 2005 1 commit
    • Tom Lane's avatar
      Remove support for OR'd indexscans internal to a single IndexScan plan · 5b051852
      Tom Lane authored
      node, as this behavior is now better done as a bitmap OR indexscan.
      This allows considerable simplification in nodeIndexscan.c itself as
      well as several planner modules concerned with indexscan plan generation.
      Also we can improve the sharing of code between regular and bitmap
      indexscans, since they are now working with nigh-identical Plan nodes.
      5b051852
  26. 22 Apr, 2005 1 commit
    • Tom Lane's avatar
      First cut at planner support for bitmap index scans. Lots to do yet, · bc843d39
      Tom Lane authored
      but the code is basically working.  Along the way, rewrite the entire
      approach to processing OR index conditions, and make it work in join
      cases for the first time ever.  orindxpath.c is now basically obsolete,
      but I left it in for the time being to allow easy comparison testing
      against the old implementation.
      bc843d39
  27. 19 Apr, 2005 1 commit
    • Tom Lane's avatar
      Create executor and planner-backend support for decoupled heap and index · 4a8c5d03
      Tom Lane authored
      scans, using in-memory tuple ID bitmaps as the intermediary.  The planner
      frontend (path creation and cost estimation) is not there yet, so none
      of this code can be executed.  I have tested it using some hacked planner
      code that is far too ugly to see the light of day, however.  Committing
      now so that the bulk of the infrastructure changes go in before the tree
      drifts under me.
      4a8c5d03
  28. 16 Apr, 2005 1 commit
  29. 25 Mar, 2005 1 commit
    • Tom Lane's avatar
      Improve EXPLAIN ANALYZE to show the time spent in each trigger when · adb1a6e9
      Tom Lane authored
      executing a statement that fires triggers.  Formerly this time was
      included in "Total runtime" but not otherwise accounted for.
      As a side benefit, we avoid re-opening relations when firing non-deferred
      AFTER triggers, because the trigger code can re-use the main executor's
      ResultRelInfo data structure.
      adb1a6e9
  30. 20 Mar, 2005 1 commit
  31. 31 Dec, 2004 1 commit
    • PostgreSQL Daemon's avatar
      · 2ff50159
      PostgreSQL Daemon authored
      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
  32. 12 Dec, 2004 1 commit
  33. 30 Sep, 2004 1 commit
  34. 13 Sep, 2004 1 commit
    • Tom Lane's avatar
      Redesign query-snapshot timing so that volatile functions in READ COMMITTED · b2c40712
      Tom Lane authored
      mode see a fresh snapshot for each command in the function, rather than
      using the latest interactive command's snapshot.  Also, suppress fresh
      snapshots as well as CommandCounterIncrement inside STABLE and IMMUTABLE
      functions, instead using the snapshot taken for the most closely nested
      regular query.  (This behavior is only sane for read-only functions, so
      the patch also enforces that such functions contain only SELECT commands.)
      As per my proposal of 6-Sep-2004; I note that I floated essentially the
      same proposal on 19-Jun-2002, but that discussion tailed off without any
      action.  Since 8.0 seems like the right place to be taking possibly
      nontrivial backwards compatibility hits, let's get it done now.
      b2c40712
  35. 10 Sep, 2004 1 commit
    • Tom Lane's avatar
      Fire non-deferred AFTER triggers immediately upon query completion, · b339d1ff
      Tom Lane authored
      rather than when returning to the idle loop.  This makes no particular
      difference for interactively-issued queries, but it makes a big difference
      for queries issued within functions: trigger execution now occurs before
      the calling function is allowed to proceed.  This responds to numerous
      complaints about nonintuitive behavior of foreign key checking, such as
      http://archives.postgresql.org/pgsql-bugs/2004-09/msg00020.php, and
      appears to be required by the SQL99 spec.
      Also take the opportunity to simplify the data structures used for the
      pending-trigger list, rename them for more clarity, and squeeze out a
      bit of space.
      b339d1ff
  36. 29 Aug, 2004 2 commits
  37. 11 Jun, 2004 1 commit
    • Tom Lane's avatar
      When using extended-query protocol, postpone planning of unnamed statements · 7643bed5
      Tom Lane authored
      until Bind is received, so that actual parameter values are visible to the
      planner.  Make use of the parameter values for estimation purposes (but
      don't fold them into the actual plan).  This buys back most of the
      potential loss of plan quality that ensues from using out-of-line
      parameters instead of putting literal values right into the query text.
      
      This patch creates a notion of constant-folding expressions 'for
      estimation purposes only', in which case we can be more aggressive than
      the normal eval_const_expressions() logic can be.  Right now the only
      difference in behavior is inserting bound values for Params, but it will
      be interesting to look at other possibilities.  One that we've seen
      come up repeatedly is reducing now() and related functions to current
      values, so that queries like ... WHERE timestampcol > now() - '1 day'
      have some chance of being planned effectively.
      
      Oliver Jowett, with some kibitzing from Tom Lane.
      7643bed5
  38. 26 May, 2004 1 commit
    • Neil Conway's avatar
      Reimplement the linked list data structure used throughout the backend. · d0b4399d
      Neil Conway authored
      In the past, we used a 'Lispy' linked list implementation: a "list" was
      merely a pointer to the head node of the list. The problem with that
      design is that it makes lappend() and length() linear time. This patch
      fixes that problem (and others) by maintaining a count of the list
      length and a pointer to the tail node along with each head node pointer.
      A "list" is now a pointer to a structure containing some meta-data
      about the list; the head and tail pointers in that structure refer
      to ListCell structures that maintain the actual linked list of nodes.
      
      The function names of the list API have also been changed to, I hope,
      be more logically consistent. By default, the old function names are
      still available; they will be disabled-by-default once the rest of
      the tree has been updated to use the new API names.
      d0b4399d