1. 26 Oct, 2009 1 commit
    • Tom Lane's avatar
      Re-implement EvalPlanQual processing to improve its performance and eliminate · 9f2ee8f2
      Tom Lane authored
      a lot of strange behaviors that occurred in join cases.  We now identify the
      "current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
      UPDATE/SHARE queries.  If an EvalPlanQual recheck is necessary, we jam the
      appropriate row into each scan node in the rechecking plan, forcing it to emit
      only that one row.  The former behavior could rescan the whole of each joined
      relation for each recheck, which was terrible for performance, and what's much
      worse could result in duplicated output tuples.
      
      Also, the original implementation of EvalPlanQual could not re-use the recheck
      execution tree --- it had to go through a full executor init and shutdown for
      every row to be tested.  To avoid this overhead, I've associated a special
      runtime Param with each LockRows or ModifyTable plan node, and arranged to
      make every scan node below such a node depend on that Param.  Thus, by
      signaling a change in that Param, the EPQ machinery can just rescan the
      already-built test plan.
      
      This patch also adds a prohibition on set-returning functions in the
      targetlist of SELECT FOR UPDATE/SHARE.  This is needed to avoid the
      duplicate-output-tuple problem.  It seems fairly reasonable since the
      other restrictions on SELECT FOR UPDATE are meant to ensure that there
      is a unique correspondence between source tuples and result tuples,
      which an output SRF destroys as much as anything else does.
      9f2ee8f2
  2. 12 Oct, 2009 1 commit
    • Tom Lane's avatar
      Move the handling of SELECT FOR UPDATE locking and rechecking out of · 0adaf4cb
      Tom Lane authored
      execMain.c and into a new plan node type LockRows.  Like the recent change
      to put table updating into a ModifyTable plan node, this increases planning
      flexibility by allowing the operations to occur below the top level of the
      plan tree.  It's necessary in any case to restore the previous behavior of
      having FOR UPDATE locking occur before ModifyTable does.
      
      This partially refactors EvalPlanQual to allow multiple rows-under-test
      to be inserted into the EPQ machinery before starting an EPQ test query.
      That isn't sufficient to fix EPQ's general bogosity in the face of plans
      that return multiple rows per test row, though.  Since this patch is
      mostly about getting some plan node infrastructure in place and not about
      fixing ten-year-old bugs, I will leave EPQ improvements for another day.
      
      Another behavioral change that we could now think about is doing FOR UPDATE
      before LIMIT, but that too seems like it should be treated as a followon
      patch.
      0adaf4cb
  3. 10 Oct, 2009 1 commit
    • Tom Lane's avatar
      Split the processing of INSERT/UPDATE/DELETE operations out of execMain.c. · 8a5849b7
      Tom Lane authored
      They are now handled by a new plan node type called ModifyTable, which is
      placed at the top of the plan tree.  In itself this change doesn't do much,
      except perhaps make the handling of RETURNING lists and inherited UPDATEs a
      tad less klugy.  But it is necessary preparation for the intended extension of
      allowing RETURNING queries inside WITH.
      
      Marko Tiikkaja
      8a5849b7
  4. 08 Oct, 2009 1 commit
    • Tom Lane's avatar
      Remove very ancient tuple-counting infrastructure (IncrRetrieved() and · c970292a
      Tom Lane authored
      friends).  This code has all been ifdef'd out for many years, and doesn't
      seem to have any prospect of becoming any more useful in the future.
      EXPLAIN ANALYZE is what people use in practice, and I think if we did want
      process-wide counters we'd be more likely to put in dtrace events for that
      than try to resurrect this code.  Get rid of it so as to have one less detail
      to worry about while refactoring execMain.c.
      c970292a
  5. 05 Oct, 2009 1 commit
    • Tom Lane's avatar
      Create an ALTER DEFAULT PRIVILEGES command, which allows users to adjust · 249724cb
      Tom Lane authored
      the privileges that will be applied to subsequently-created objects.
      
      Such adjustments are always per owning role, and can be restricted to objects
      created in particular schemas too.  A notable benefit is that users can
      override the traditional default privilege settings, eg, the PUBLIC EXECUTE
      privilege traditionally granted by default for functions.
      
      Petr Jelinek
      249724cb
  6. 27 Sep, 2009 1 commit
    • Tom Lane's avatar
      Replace the array-style TupleTable data structure with a simple List of · f92e8a4b
      Tom Lane authored
      TupleTableSlot nodes.  This eliminates the need to count in advance
      how many Slots will be needed, which seems more than worth the small
      increase in the amount of palloc traffic during executor startup.
      
      The ExecCountSlots infrastructure is now all dead code, but I'll remove it
      in a separate commit for clarity.
      
      Per a comment from Robert Haas.
      f92e8a4b
  7. 26 Sep, 2009 1 commit
    • Tom Lane's avatar
      Extend the BKI infrastructure to allow system catalogs to be given · 49856352
      Tom Lane authored
      hand-assigned rowtype OIDs, even when they are not "bootstrapped" catalogs
      that have handmade type rows in pg_type.h.  Give pg_database such an OID.
      Restore the availability of C macros for the rowtype OIDs of the bootstrapped
      catalogs.  (These macros are now in the individual catalogs' .h files,
      though, not in pg_type.h.)
      
      This commit doesn't do anything especially useful by itself, but it's
      necessary infrastructure for reverting some ill-considered changes in
      relcache.c.
      49856352
  8. 29 Jul, 2009 1 commit
    • Tom Lane's avatar
      Support deferrable uniqueness constraints. · 25d9bf2e
      Tom Lane authored
      The current implementation fires an AFTER ROW trigger for each tuple that
      looks like it might be non-unique according to the index contents at the
      time of insertion.  This works well as long as there aren't many conflicts,
      but won't scale to massive unique-key reassignments.  Improving that case
      is a TODO item.
      
      Dean Rasheed
      25d9bf2e
  9. 11 Jun, 2009 2 commits
  10. 07 May, 2009 1 commit
    • Tom Lane's avatar
      Add an option to AlterTableCreateToastTable() to allow its caller to force · 1e06ed1a
      Tom Lane authored
      a toast table to be built, even if the sum-of-column-widths calculation
      indicates one isn't needed.  This is needed by pg_migrator because if the
      old table has a toast table, we have to migrate over the toast table since
      it might contain some live data, even though subsequent column drops could
      mean that no recently-added rows could require toasting.
      1e06ed1a
  11. 08 Feb, 2009 1 commit
    • Tom Lane's avatar
      Ensure that INSERT ... SELECT into a table with OIDs never copies row OIDs · 3d02cae3
      Tom Lane authored
      from the source table.  This could never happen anyway before 8.4 because
      the executor invariably applied a "junk filter" to rows due to be inserted;
      but now that we skip doing that when it's not necessary, the case can occur.
      Problem noted 2008-11-27 by KaiGai Kohei, though I misunderstood what he
      was on about at the time (the opacity of the patch he proposed didn't help).
      3d02cae3
  12. 02 Feb, 2009 1 commit
  13. 22 Jan, 2009 1 commit
  14. 01 Jan, 2009 1 commit
  15. 30 Nov, 2008 1 commit
    • Tom Lane's avatar
      Clean up the API for DestReceiver objects by eliminating the assumption · c1f30733
      Tom Lane authored
      that a Portal is a useful and sufficient additional argument for
      CreateDestReceiver --- it just isn't, in most cases.  Instead formalize
      the approach of passing any needed parameters to the receiver separately.
      
      One unexpected benefit of this change is that we can declare typedef Portal
      in a less surprising location.
      
      This patch is just code rearrangement and doesn't change any functionality.
      I'll tackle the HOLD-cursor-vs-toast problem in a follow-on patch.
      c1f30733
  16. 19 Nov, 2008 1 commit
    • Tom Lane's avatar
      Some infrastructure changes for the upcoming auto-explain contrib module: · cd35e9d7
      Tom Lane authored
      * Refactor explain.c slightly to export a convenient-to-use subroutine
      for printing EXPLAIN results.
      
      * Provide hooks for plugins to get control at ExecutorStart and ExecutorEnd
      as well as ExecutorRun.
      
      * Add some minimal support for tracking the total runtime of ExecutorRun.
      This code won't actually do anything unless a plugin prods it to.
      
      * Change the API of the DefineCustomXXXVariable functions to allow nonzero
      "flags" to be specified for a custom GUC variable.  While at it, also make
      the "bootstrap" default value for custom GUCs be explicitly specified as a
      parameter to these functions.  This is to eliminate confusion over where the
      default comes from, as has been expressed in the past by some users of the
      custom-variable facility.
      
      * Refactor GUC code a bit to ensure that a custom variable gets initialized to
      something valid (like its default value) even if the placeholder value was
      invalid.
      cd35e9d7
  17. 16 Nov, 2008 1 commit
    • Tom Lane's avatar
      Modify UPDATE/DELETE WHERE CURRENT OF to use the FOR UPDATE infrastructure to · 18004101
      Tom Lane authored
      locate the target row, if the cursor was declared with FOR UPDATE or FOR
      SHARE.  This approach is more flexible and reliable than digging through the
      plan tree; for instance it can cope with join cursors.  But we still provide
      the old code for use with non-FOR-UPDATE cursors.  Per gripe from Robert Haas.
      18004101
  18. 15 Nov, 2008 1 commit
    • Tom Lane's avatar
      Make SELECT FOR UPDATE/SHARE work on inheritance trees, by having the plan · 0656ed3d
      Tom Lane authored
      return the tableoid as well as the ctid for any FOR UPDATE targets that
      have child tables.  All child tables are listed in the ExecRowMark list,
      but the executor just skips the ones that didn't produce the current row.
      
      Curiously, this longstanding restriction doesn't seem to have been documented
      anywhere; so no doc changes.
      0656ed3d
  19. 06 Nov, 2008 1 commit
  20. 31 Oct, 2008 1 commit
  21. 25 Aug, 2008 1 commit
  22. 08 Aug, 2008 1 commit
    • Tom Lane's avatar
      Install checks in executor startup to ensure that the tuples produced by an · 30fd8ec7
      Tom Lane authored
      INSERT or UPDATE will match the target table's current rowtype.  In pre-8.3
      releases inconsistency can arise with stale cached plans, as reported by
      Merlin Moncure.  (We patched the equivalent hazard on the SELECT side in Feb
      2007; I'm not sure why we thought there was no risk on the insertion side.)
      In 8.3 and HEAD this problem should be impossible due to plan cache
      invalidation management, but it seems prudent to make the check anyway.
      
      Back-patch as far as 8.0.  7.x versions lack ALTER COLUMN TYPE, so there
      seems no way to abuse a stale plan comparably.
      30fd8ec7
  23. 26 Jul, 2008 1 commit
    • Tom Lane's avatar
      As noted by Andrew Gierth, there's really no need any more to force a junk · a77eaa6a
      Tom Lane authored
      filter to be used when INSERT or SELECT INTO has a plan that returns raw
      disk tuples.  The virtual-tuple-slot optimizations that were put in place
      awhile ago mean that ExecInsert has to do ExecMaterializeSlot, and that
      already copies the tuple if it's raw (and does so more efficiently than
      a junk filter, too).  So get rid of that logic.  This in turn means that
      we can throw away ExecMayReturnRawTuples, which wasn't used for any other
      purpose, and was always a kluge anyway.
      
      In passing, move a couple of SELECT-INTO-specific fields out of EState
      and into the private state of the SELECT INTO DestReceiver, as was foreseen
      in an old comment there.  Also make intorel_receive use ExecMaterializeSlot
      not ExecCopySlotTuple, for consistency with ExecInsert and to possibly save
      a tuple copy step in some cases.
      a77eaa6a
  24. 18 Jul, 2008 1 commit
  25. 12 May, 2008 2 commits
    • Alvaro Herrera's avatar
      Improve snapshot manager by keeping explicit track of snapshots. · 5da9da71
      Alvaro Herrera authored
      There are two ways to track a snapshot: there's the "registered" list, which
      is used for arbitrary long-lived snapshots; and there's the "active stack",
      which is used for the snapshot that is considered "active" at any time.
      This also allows users of snapshots to stop worrying about snapshot memory
      allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot
      assignment.  This is all done automatically now.
      
      As a consequence, this allows us to reset MyProc->xmin when there are no
      more snapshots registered in the current backend, reducing the impact that
      long-running transactions have on VACUUM.
      5da9da71
    • Alvaro Herrera's avatar
      Restructure some header files a bit, in particular heapam.h, by removing some · f8c4d7db
      Alvaro Herrera authored
      unnecessary #include lines in it.  Also, move some tuple routine prototypes and
      macros to htup.h, which allows removal of heapam.h inclusion from some .c
      files.
      
      For this to work, a new header file access/sysattr.h needed to be created,
      initially containing attribute numbers of system columns, for pg_dump usage.
      
      While at it, make contrib ltree, intarray and hstore header files more
      consistent with our header style.
      f8c4d7db
  26. 09 May, 2008 1 commit
    • Tom Lane's avatar
      Change the rules for inherited CHECK constraints to be essentially the same · cd902b33
      Tom Lane authored
      as those for inherited columns; that is, it's no longer allowed for a child
      table to not have a check constraint matching one that exists on a parent.
      This satisfies the principle of least surprise (rows selected from the parent
      will always appear to meet its check constraints) and eliminates some
      longstanding bogosity in pg_dump, which formerly had to guess about whether
      check constraints were really inherited or not.
      
      The implementation involves adding conislocal and coninhcount columns to
      pg_constraint (paralleling attislocal and attinhcount in pg_attribute)
      and refactoring various ALTER TABLE actions to be more like those for
      columns.
      
      Alex Hunsaker, Nikhil Sontakke, Tom Lane
      cd902b33
  27. 21 Apr, 2008 1 commit
    • Tom Lane's avatar
      Fix a couple of places in execMain that erroneously assumed that SELECT FOR · f593f623
      Tom Lane authored
      UPDATE/SHARE couldn't occur as a subquery in a query with a non-SELECT
      top-level operation.  Symptoms included outright failure (as in report from
      Mark Mielke) and silently neglecting to take the requested row locks.
      
      Back-patch to 8.3, because the visible failure in the INSERT ... SELECT case
      is a regression from 8.2.  I'm a bit hesitant to back-patch further given the
      lack of field complaints.
      f593f623
  28. 28 Mar, 2008 1 commit
  29. 26 Mar, 2008 1 commit
  30. 07 Feb, 2008 1 commit
    • Tom Lane's avatar
      Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted · b7fe5f70
      Tom Lane authored
      tablespace permissions failures when copying an index that is in the
      database's default tablespace.  A side-effect of the change is that explicitly
      specifying the default tablespace no longer triggers a permissions check;
      this is not how it was done in pre-8.3 releases but is argued to be more
      consistent.  Per bug #3921 from Andrew Gilligan.  (Note: I argued in the
      subsequent discussion that maybe LIKE shouldn't copy index tablespaces
      at all, but since no one indicated agreement with that idea, I've refrained
      from doing it.)
      b7fe5f70
  31. 01 Jan, 2008 1 commit
  32. 30 Nov, 2007 1 commit
    • Tom Lane's avatar
      Avoid incrementing the CommandCounter when CommandCounterIncrement is called · 895a94de
      Tom Lane authored
      but no database changes have been made since the last CommandCounterIncrement.
      This should result in a significant improvement in the number of "commands"
      that can typically be performed within a transaction before hitting the 2^32
      CommandId size limit.  In particular this buys back (and more) the possible
      adverse consequences of my previous patch to fix plan caching behavior.
      
      The implementation requires tracking whether the current CommandCounter
      value has been "used" to mark any tuples.  CommandCounter values stored into
      snapshots are presumed not to be used for this purpose.  This requires some
      small executor changes, since the executor used to conflate the curcid of
      the snapshot it was using with the command ID to mark output tuples with.
      Separating these concepts allows some small simplifications in executor APIs.
      
      Something for the TODO list: look into having CommandCounterIncrement not do
      AcceptInvalidationMessages.  It seems fairly bogus to be doing it there,
      but exactly where to do it instead isn't clear, and I'm disinclined to mess
      with asynchronous behavior during late beta.
      895a94de
  33. 15 Nov, 2007 2 commits
  34. 20 Sep, 2007 1 commit
    • Tom Lane's avatar
      HOT updates. When we update a tuple without changing any of its indexed · 282d2a03
      Tom Lane authored
      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
  35. 07 Sep, 2007 1 commit
    • Tom Lane's avatar
      Don't take ProcArrayLock while exiting a transaction that has no XID; there is · 0a51e707
      Tom Lane authored
      no need for serialization against snapshot-taking because the xact doesn't
      affect anyone else's snapshot anyway.  Per discussion.  Also, move various
      info about the interlocking of transactions and snapshots out of code comments
      and into a hopefully-more-cohesive discussion in access/transam/README.
      
      Also, remove a couple of now-obsolete comments about having to force some WAL
      to be written to persuade RecordTransactionCommit to do its thing.
      0a51e707
  36. 15 Aug, 2007 1 commit
    • Tom Lane's avatar
      Arrange to cache a ResultRelInfo in the executor's EState for relations that · 817946bb
      Tom Lane authored
      are not one of the query's defined result relations, but nonetheless have
      triggers fired against them while the query is active.  This was formerly
      impossible but can now occur because of my recent patch to fix the firing
      order for RI triggers.  Caching a ResultRelInfo avoids duplicating work by
      repeatedly opening and closing the same relation, and also allows EXPLAIN
      ANALYZE to "see" and report on these extra triggers.  Use the same mechanism
      to cache open relations when firing deferred triggers at transaction shutdown;
      this replaces the former one-element-cache strategy used in that case, and
      should improve performance a bit when there are deferred triggers on a number
      of relations.
      817946bb
  37. 11 Jun, 2007 1 commit
    • Tom Lane's avatar
      Support UPDATE/DELETE WHERE CURRENT OF cursor_name, per SQL standard. · 6808f1b1
      Tom Lane authored
      Along the way, allow FOR UPDATE in non-WITH-HOLD cursors; there may once
      have been a reason to disallow that, but it seems to work now, and it's
      really rather necessary if you want to select a row via a cursor and then
      update it in a concurrent-safe fashion.
      
      Original patch by Arul Shaji, rather heavily editorialized by Tom Lane.
      6808f1b1