1. 31 Jul, 2007 1 commit
  2. 27 Jul, 2007 1 commit
  3. 27 Feb, 2007 1 commit
    • Tom Lane's avatar
      Get rid of the separate EState for subplans, and just let them share the · c7ff7663
      Tom Lane authored
      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
  4. 22 Feb, 2007 1 commit
    • 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
  5. 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
  6. 06 Feb, 2007 1 commit
    • Tom Lane's avatar
      Remove typmod checking from the recent security-related patches. It turns · a8c3f161
      Tom Lane authored
      out that ExecEvalVar and friends don't necessarily have access to a tuple
      descriptor with correct typmod: it definitely can contain -1, and possibly
      might contain other values that are different from the Var's value.
      Arguably this should be cleaned up someday, but it's not a simple change,
      and in any case typmod discrepancies don't pose a security hazard.
      Per reports from numerous people :-(
      
      I'm not entirely sure whether the failure can occur in 8.0 --- the simple
      test cases reported so far don't trigger it there.  But back-patch the
      change all the way anyway.
      a8c3f161
  7. 02 Feb, 2007 1 commit
    • Tom Lane's avatar
      Repair failure to check that a table is still compatible with a previously · 5413eef8
      Tom Lane authored
      made query plan.  Use of ALTER COLUMN TYPE creates a hazard for cached
      query plans: they could contain Vars that claim a column has a different
      type than it now has.  Fix this by checking during plan startup that Vars
      at relation scan level match the current relation tuple descriptor.  Since
      at that point we already have at least AccessShareLock, we can be sure the
      column type will not change underneath us later in the query.  However,
      since a backend's locks do not conflict against itself, there is still a
      hole for an attacker to exploit: he could try to execute ALTER COLUMN TYPE
      while a query is in progress in the current backend.  Seal that hole by
      rejecting ALTER TABLE whenever the target relation is already open in
      the current backend.
      
      This is a significant security hole: not only can one trivially crash the
      backend, but with appropriate misuse of pass-by-reference datatypes it is
      possible to read out arbitrary locations in the server process's memory,
      which could allow retrieving database content the user should not be able
      to see.  Our thanks to Jeff Trout for the initial report.
      
      Security: CVE-2007-0556
      5413eef8
  8. 05 Jan, 2007 1 commit
  9. 26 Dec, 2006 1 commit
    • Tom Lane's avatar
      Fix failure due to accessing an already-freed tuple descriptor in a plan · 0cbc5b1e
      Tom Lane authored
      involving HashAggregate over SubqueryScan (this is the known case, there
      may well be more).  The bug is only latent in releases before 8.2 since they
      didn't try to access tupletable slots' descriptors during ExecDropTupleTable.
      The least bogus fix seems to be to make subqueries share the parent query's
      memory context, so that tupdescs they create will have the same lifespan as
      those of the parent query.  There are comments in the code envisioning going
      even further by not having a separate child EState at all, but that will
      require rethinking executor access to range tables, which I don't want to
      tackle right now.  Per bug report from Jean-Pierre Pelletier.
      0cbc5b1e
  10. 04 Oct, 2006 1 commit
  11. 04 Aug, 2006 1 commit
    • Tom Lane's avatar
      Fix domain_in() bug exhibited by Darcy Buskermolen. The idea of an EState · c6848986
      Tom Lane authored
      that's shorter-lived than the expression state being evaluated in it really
      doesn't work :-( --- we end up with fn_extra caches getting deleted while
      still in use.  Rather than abandon the notion of caching expression state
      across domain_in calls altogether, I chose to make domain_in a bit cozier
      with ExprContext.  All we really need for evaluating variable-free
      expressions is an ExprContext, not an EState, so I invented the notion of a
      "standalone" ExprContext.  domain_in can prevent resource leakages by doing
      a ReScanExprContext on this rather than having to free it entirely; so we
      can make the ExprContext have the same lifespan (and particularly the same
      per_query memory context) as the expression state structs.
      c6848986
  12. 31 Jul, 2006 1 commit
    • Tom Lane's avatar
      Change the relation_open protocol so that we obtain lock on a relation · 09d3670d
      Tom Lane authored
      (table or index) before trying to open its relcache entry.  This fixes
      race conditions in which someone else commits a change to the relation's
      catalog entries while we are in process of doing relcache load.  Problems
      of that ilk have been reported sporadically for years, but it was not
      really practical to fix until recently --- for instance, the recent
      addition of WAL-log support for in-place updates helped.
      
      Along the way, remove pg_am.amconcurrent: all AMs are now expected to support
      concurrent update.
      09d3670d
  13. 14 Jul, 2006 1 commit
  14. 11 Jul, 2006 1 commit
  15. 16 Jun, 2006 1 commit
    • Tom Lane's avatar
      Fix problems with cached tuple descriptors disappearing while still in use · 06e10abc
      Tom Lane authored
      by creating a reference-count mechanism, similar to what we did a long time
      ago for catcache entries.  The back branches have an ugly solution involving
      lots of extra copies, but this way is more efficient.  Reference counting is
      only applied to tupdescs that are actually in caches --- there seems no need
      to use it for tupdescs that are generated in the executor, since they'll go
      away during plan shutdown by virtue of being in the per-query memory context.
      Neil Conway and Tom Lane
      06e10abc
  16. 30 Apr, 2006 1 commit
  17. 05 Mar, 2006 1 commit
  18. 14 Jan, 2006 1 commit
    • Tom Lane's avatar
      Some minor code cleanup, falling out from the removal of rtree. SK_NEGATE · f7ea9312
      Tom Lane authored
      isn't being used anywhere anymore, and there seems no point in a generic
      index_keytest() routine when two out of three remaining access methods
      aren't using it.  Also, add a comment documenting a convention for
      letting access methods define private flag bits in ScanKey sk_flags.
      There are no such flags at the moment but I'm thinking about changing
      btree's handling of "required keys" to use flag bits in the keys
      rather than a count of required key positions.  Also, if some AM did
      still want SK_NEGATE then it would be reasonable to treat it as a private
      flag bit.
      f7ea9312
  19. 03 Dec, 2005 1 commit
    • Tom Lane's avatar
      Tweak indexscan machinery to avoid taking an AccessShareLock on an index · a98871b7
      Tom Lane authored
      if we already have a stronger lock due to the index's table being the
      update target table of the query.  Same optimization I applied earlier
      at the table level.  There doesn't seem to be much interest in the more
      radical idea of not locking indexes at all, so do what we can ...
      a98871b7
  20. 02 Dec, 2005 1 commit
  21. 23 Nov, 2005 1 commit
    • Tom Lane's avatar
      Get rid of ExecAssignResultTypeFromOuterPlan() and make all plan node types · 4dd2048a
      Tom Lane authored
      generate their output tuple descriptors from their target lists (ie, using
      ExecAssignResultTypeFromTL()).  We long ago fixed things so that all node
      types have minimally valid tlists, so there's no longer any good reason to
      have two different ways of doing it.  This change is needed to fix bug
      reported by Hayden James: the fix of 2005-11-03 to emit the correct column
      names after optimizing away a SubqueryScan node didn't work if the new
      top-level plan node used ExecAssignResultTypeFromOuterPlan to generate its
      tupdesc, since the next plan node down won't have the correct column labels.
      4dd2048a
  22. 22 Nov, 2005 1 commit
  23. 14 Nov, 2005 1 commit
    • Tom Lane's avatar
      Prevent ExecInsert() and ExecUpdate() from scribbling on the result tuple · 76ce39e3
      Tom Lane authored
      slot of the topmost plan node when a trigger returns a modified tuple.
      These appear to be the only places where a plan node's caller did not
      treat the result slot as read-only, which is an assumption that nodeUnique
      makes as of 8.1.  Fixes trigger-vs-DISTINCT bug reported by Frank van Vugt.
      76ce39e3
  24. 15 Oct, 2005 1 commit
  25. 01 Aug, 2005 1 commit
  26. 20 Jun, 2005 1 commit
  27. 28 Apr, 2005 1 commit
    • Tom Lane's avatar
      Implement sharable row-level locks, and use them for foreign key references · bedb78d3
      Tom Lane authored
      to eliminate unnecessary deadlocks.  This commit adds SELECT ... FOR SHARE
      paralleling SELECT ... FOR UPDATE.  The implementation uses a new SLRU
      data structure (managed much like pg_subtrans) to represent multiple-
      transaction-ID sets.  When more than one transaction is holding a shared
      lock on a particular row, we create a MultiXactId representing that set
      of transactions and store its ID in the row's XMAX.  This scheme allows
      an effectively unlimited number of row locks, just as we did before,
      while not costing any extra overhead except when a shared lock actually
      has to be shared.   Still TODO: use the regular lock manager to control
      the grant order when multiple backends are waiting for a row lock.
      
      Alvaro Herrera and Tom Lane.
      bedb78d3
  28. 23 Apr, 2005 1 commit
    • Tom Lane's avatar
      Remove explicit FreeExprContext calls during plan node shutdown. The · 9b5b9616
      Tom Lane authored
      ExprContexts will be freed anyway when FreeExecutorState() is reached,
      and letting that routine do the work is more efficient because it will
      automatically free the ExprContexts in reverse creation order.  The
      existing coding was effectively freeing them in exactly the worst
      possible order, resulting in O(N^2) behavior inside list_delete_ptr,
      which becomes highly visible in cases with a few thousand plan nodes.
      
      ExecFreeExprContext is now effectively a no-op and could be removed,
      but I left it in place in case we ever want to put it back to use.
      9b5b9616
  29. 14 Apr, 2005 1 commit
  30. 06 Apr, 2005 1 commit
    • Tom Lane's avatar
      Merge Resdom nodes into TargetEntry nodes to simplify code and save a · ad161bcc
      Tom Lane authored
      few palloc's.  I also chose to eliminate the restype and restypmod fields
      entirely, since they are redundant with information stored in the node's
      contained expression; re-examining the expression at need seems simpler
      and more reliable than trying to keep restype/restypmod up to date.
      
      initdb forced due to change in contents of stored rules.
      ad161bcc
  31. 21 Mar, 2005 1 commit
    • Tom Lane's avatar
      Convert index-related tuple handling routines from char 'n'/' ' to bool · ee4ddac1
      Tom Lane authored
      convention for isnull flags.  Also, remove the useless InsertIndexResult
      return struct from index AM aminsert calls --- there is no reason for
      the caller to know where in the index the tuple was inserted, and we
      were wasting a palloc cycle per insert to deliver this uninteresting
      value (plus nontrivial complexity in some AMs).
      I forced initdb because of the change in the signature of the aminsert
      routines, even though nothing really looks at those pg_proc entries...
      ee4ddac1
  32. 16 Mar, 2005 1 commit
    • Tom Lane's avatar
      Revise TupleTableSlot code to avoid unnecessary construction and disassembly · f97aebd1
      Tom Lane authored
      of tuples when passing data up through multiple plan nodes.  A slot can now
      hold either a normal "physical" HeapTuple, or a "virtual" tuple consisting
      of Datum/isnull arrays.  Upper plan levels can usually just copy the Datum
      arrays, avoiding heap_formtuple() and possible subsequent nocachegetattr()
      calls to extract the data again.  This work extends Atsushi Ogawa's earlier
      patch, which provided the key idea of adding Datum arrays to TupleTableSlots.
      (I believe however that something like this was foreseen way back in Berkeley
      days --- see the old comment on ExecProject.)  A test case involving many
      levels of join of fairly wide tables (about 80 columns altogether) showed
      about 3x overall speedup, though simple queries will probably not be
      helped very much.
      
      I have also duplicated some code in heaptuple.c in order to provide versions
      of heap_formtuple and friends that use "bool" arrays to indicate null
      attributes, instead of the old convention of "char" arrays containing either
      'n' or ' '.  This provides a better match to the convention used by
      ExecEvalExpr.  While I have not made a concerted effort to get rid of uses
      of the old routines, I think they should be deprecated and eventually removed.
      f97aebd1
  33. 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
  34. 30 Sep, 2004 1 commit
  35. 11 Sep, 2004 1 commit
    • Tom Lane's avatar
      Renumber SnapshotNow and the other special snapshot codes so that · 493f7260
      Tom Lane authored
      ((Snapshot) NULL) can no longer be confused with a valid snapshot,
      as per my recent suggestion.  Define a macro InvalidSnapshot for 0.
      Use InvalidSnapshot instead of SnapshotAny as the do-nothing special
      case for heap_update and heap_delete crosschecks; this seems a little
      cleaner even though the behavior is really the same.
      493f7260
  36. 29 Aug, 2004 2 commits
  37. 30 May, 2004 1 commit
  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
  39. 17 Mar, 2004 1 commit
    • Tom Lane's avatar
      Reimplement CASE val WHEN compval1 THEN ... WHEN compval2 THEN ... END · 55f7c330
      Tom Lane authored
      so that the 'val' is computed only once, per recent discussion.  The
      speedup is not much when 'val' is just a simple variable, but could be
      significant for larger expressions.  More importantly this avoids issues
      with multiple evaluations of a volatile 'val', and it allows the CASE
      expression to be reverse-listed in its original form by ruleutils.c.
      55f7c330