1. 16 10月, 2008 1 次提交
    • T
      Fix SPI_getvalue and SPI_getbinval to range-check the given attribute number · bcf188a2
      Tom Lane 提交于
      according to the TupleDesc's natts, not the number of physical columns in the
      tuple.  The previous coding would do the wrong thing in cases where natts is
      different from the tuple's column count: either incorrectly report error when
      it should just treat the column as null, or actually crash due to indexing off
      the end of the TupleDesc's attribute array.  (The second case is probably not
      possible in modern PG versions, due to more careful handling of inheritance
      cases than we once had.  But it's still a clear lack of robustness here.)
      
      The incorrect error indication is ignored by all callers within the core PG
      distribution, so this bug has no symptoms visible within the core code, but
      it might well be an issue for add-on packages.  So patch all the way back.
      bcf188a2
  2. 16 9月, 2008 1 次提交
    • T
      Fix caching of foreign-key-checking queries so that when a replan is needed, · 1cd93560
      Tom Lane 提交于
      we regenerate the SQL query text not merely the plan derived from it.  This
      is needed to handle contingencies such as renaming of a table or column
      used in an FK.  Pre-8.3, such cases worked despite the lack of replanning
      (because the cached plan needn't actually change), so this is a regression.
      Per bug #4417 from Benjamin Bihler.
      1cd93560
  3. 19 7月, 2008 1 次提交
    • T
      Adjust things so that the query_string of a cached plan and the sourceText of · a1c69235
      Tom Lane 提交于
      a portal are never NULL, but reliably provide the source text of the query.
      It turns out that there was only one place that was really taking a short-cut,
      which was the 'EXECUTE' utility statement.  That doesn't seem like a
      sufficiently critical performance hotspot to justify not offering a guarantee
      of validity of the portal source text.  Fix it to copy the source text over
      from the cached plan.  Add Asserts in the places that set up cached plans and
      portals to reject null source strings, and simplify a bunch of places that
      formerly needed to guard against nulls.
      
      There may be a few places that cons up statements for execution without
      having any source text at all; I found one such in ConvertTriggerToFK().
      It seems sufficient to inject a phony source string in such a case,
      for instance
              ProcessUtility((Node *) atstmt,
                             "(generated ALTER TABLE ADD FOREIGN KEY command)",
                             NULL, false, None_Receiver, NULL);
      
      We should take a second look at the usage of debug_query_string,
      particularly the recently added current_query() SQL function.
      
      ITAGAKI Takahiro and Tom Lane
      a1c69235
  4. 02 6月, 2008 1 次提交
    • T
      Refactor SPI_cursor_open/SPI_cursor_open_with_args so that the latter sets · 6a9fffcd
      Tom Lane 提交于
      the PARAM_FLAG_CONST flag on the parameters that are passed into the portal,
      while the former's behavior is unchanged.  This should only affect the case
      where the portal is executing an EXPLAIN; it will cause the generated plan to
      look more like what would be generated if the portal were actually executing
      the command being explained.  Per gripe from Pavel.
      6a9fffcd
  5. 13 5月, 2008 1 次提交
    • A
      Improve snapshot manager by keeping explicit track of snapshots. · 5da9da71
      Alvaro Herrera 提交于
      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
  6. 12 5月, 2008 1 次提交
    • A
      Restructure some header files a bit, in particular heapam.h, by removing some · f8c4d7db
      Alvaro Herrera 提交于
      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
  7. 03 4月, 2008 1 次提交
    • T
      Revert my bad decision of about a year ago to make PortalDefineQuery · 1591fcbe
      Tom Lane 提交于
      responsible for copying the query string into the new Portal.  Such copying
      is unnecessary in the common code path through exec_simple_query, and in
      this case it can be enormously expensive because the string might contain
      a large number of individual commands; we were copying the entire, long
      string for each command, resulting in O(N^2) behavior for N commands.
      (This is the cause of bug #4079.)  A second problem with it is that
      PortalDefineQuery really can't risk error, because if it elog's before
      having set up the Portal, we will leak the plancache refcount that the
      caller is trying to hand off to the portal.  So go back to the design in
      which the caller is responsible for making sure everything is copied into
      the portal if necessary.
      1591fcbe
  8. 01 4月, 2008 1 次提交
    • T
      Add SPI-level support for executing SQL commands with one-time-use plans, · d5466e38
      Tom Lane 提交于
      that is commands that have out-of-line parameters but the plan is prepared
      assuming that the parameter values are constants.  This is needed for the
      plpgsql EXECUTE USING patch, but will probably have use elsewhere.
      
      This commit includes the SPI functions and documentation, but no callers
      nor regression tests.  The upcoming EXECUTE USING patch will provide
      regression-test coverage.  I thought committing this separately made
      sense since it's logically a distinct feature.
      d5466e38
  9. 27 3月, 2008 2 次提交
  10. 21 3月, 2008 1 次提交
  11. 12 2月, 2008 1 次提交
    • T
      Fix SPI_cursor_open() and SPI_is_cursor_plan() to push the SPI stack before · 745e6eda
      Tom Lane 提交于
      doing anything interesting, such as calling RevalidateCachedPlan().  The
      necessity of this is demonstrated by an example from Willem Buitendyk:
      during a replan, the planner might try to evaluate SPI-using functions,
      and so we'd better be in a clean SPI context.
      
      A small downside of this fix is that these two functions will now fail
      outright if called when not inside a SPI-using procedure (ie, a
      SPI_connect/SPI_finish pair).  The documentation never promised or suggested
      that that would work, though; and they are normally used in concert with
      other functions, mainly SPI_prepare, that always have failed in such a case.
      So the odds of breaking something seem pretty low.
      
      In passing, make SPI_is_cursor_plan's error handling convention clearer,
      and fix documentation's erroneous claim that SPI_cursor_open would
      return NULL on error.
      
      Before 8.3 these functions could not invoke replanning, so there is probably
      no need for back-patching.
      745e6eda
  12. 02 1月, 2008 1 次提交
  13. 01 12月, 2007 2 次提交
    • T
      Avoid incrementing the CommandCounter when CommandCounterIncrement is called · 895a94de
      Tom Lane 提交于
      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
    • T
      Repair bug that allowed RevalidateCachedPlan to attempt to rebuild a cached · f0f18c70
      Tom Lane 提交于
      plan before the effects of DDL executed in an immediately prior SPI operation
      had been absorbed.  Per report from Chris Wood.
      
      This patch has an unpleasant side effect of causing the number of
      CommandCounterIncrement()s done by a typical plpgsql function to
      approximately double.  Amelioration of the consequences of that
      will be undertaken in a separate patch.
      f0f18c70
  14. 16 11月, 2007 1 次提交
  15. 25 10月, 2007 2 次提交
    • T
      Tweak new error messages to match the actual syntax of DECLARE CURSOR. · fcc20bd4
      Tom Lane 提交于
      (Last night I copied-and-pasted from the WITH HOLD case, but that's
      wrong because of the bizarrely irregular syntax specified by the standard.)
      fcc20bd4
    • T
      Disallow scrolling of FOR UPDATE/FOR SHARE cursors, so as to avoid problems · 048efc25
      Tom Lane 提交于
      in corner cases such as re-fetching a just-deleted row.  We may be able to
      relax this someday, but let's find out how many people really care before
      we invest a lot of work in it.  Per report from Heikki and subsequent
      discussion.
      
      While in the neighborhood, make the combination of INSENSITIVE and FOR UPDATE
      throw an error, since they are semantically incompatible.  (Up to now we've
      accepted but just ignored the INSENSITIVE option of DECLARE CURSOR.)
      048efc25
  16. 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
  17. 16 8月, 2007 1 次提交
    • T
      Repair problems occurring when multiple RI updates have to be done to the same · 9cb84097
      Tom Lane 提交于
      row within one query: we were firing check triggers before all the updates
      were done, leading to bogus failures.  Fix by making the triggers queued by
      an RI update go at the end of the outer query's trigger event list, thereby
      effectively making the processing "breadth-first".  This was indeed how it
      worked pre-8.0, so the bug does not occur in the 7.x branches.
      Per report from Pavel Stehule.
      9cb84097
  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. 17 4月, 2007 2 次提交
  20. 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
  21. 26 3月, 2007 2 次提交
  22. 17 3月, 2007 1 次提交
  23. 16 3月, 2007 1 次提交
    • T
      Make use of plancache module for SPI plans. In particular, since plpgsql · 95f6d2d2
      Tom Lane 提交于
      uses SPI plans, this finally fixes the ancient gotcha that you can't
      drop and recreate a temp table used by a plpgsql function.
      
      Along the way, clean up SPI's API a little bit by declaring SPI plan
      pointers as "SPIPlanPtr" instead of "void *".  This is cosmetic but
      helps to forestall simple programming mistakes.  (I have changed some
      but not all of the callers to match; there are still some "void *"'s
      in contrib and the PL's.  This is intentional so that we can see if
      anyone's compiler complains about it.)
      95f6d2d2
  24. 13 3月, 2007 1 次提交
    • T
      First phase of plan-invalidation project: create a plan cache management · b9527e98
      Tom Lane 提交于
      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
  25. 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
  26. 10 1月, 2007 1 次提交
  27. 06 1月, 2007 1 次提交
  28. 27 12月, 2006 1 次提交
    • T
      Repair bug #2836: SPI_execute_plan returned zero if none of the querytrees · fccf99f0
      Tom Lane 提交于
      were marked canSetTag.  While it's certainly correct to return the result
      of the last one that is marked canSetTag, it's less clear what to do when
      none of them are.  Since plpgsql will complain if zero is returned, the
      8.2.0 behavior isn't good.  I've fixed it to restore the prior behavior of
      returning the physically last query's result code when there are no
      canSetTag queries.
      fccf99f0
  29. 08 12月, 2006 1 次提交
  30. 22 11月, 2006 1 次提交
  31. 04 10月, 2006 1 次提交
  32. 08 9月, 2006 1 次提交
    • T
      Clean up logging for extended-query-protocol operations, as per my recent · 893632be
      Tom Lane 提交于
      proposal.  Parameter logging works even for binary-format parameters, and
      logging overhead is avoided when disabled.
      
      log_statement = all output for the src/test/examples/testlibpq3.c example
      now looks like
      
      LOG:  statement: execute <unnamed>: SELECT * FROM test1 WHERE t = $1
      DETAIL:  parameters: $1 = 'joe''s place'
      LOG:  statement: execute <unnamed>: SELECT * FROM test1 WHERE i = $1::int4
      DETAIL:  parameters: $1 = '2'
      
      and log_min_duration_statement = 0 results in
      
      LOG:  duration: 2.431 ms  parse <unnamed>: SELECT * FROM test1 WHERE t = $1
      LOG:  duration: 2.335 ms  bind <unnamed> to <unnamed>: SELECT * FROM test1 WHERE t = $1
      DETAIL:  parameters: $1 = 'joe''s place'
      LOG:  duration: 0.394 ms  execute <unnamed>: SELECT * FROM test1 WHERE t = $1
      DETAIL:  parameters: $1 = 'joe''s place'
      LOG:  duration: 1.251 ms  parse <unnamed>: SELECT * FROM test1 WHERE i = $1::int4
      LOG:  duration: 0.566 ms  bind <unnamed> to <unnamed>: SELECT * FROM test1 WHERE i = $1::int4
      DETAIL:  parameters: $1 = '2'
      LOG:  duration: 0.173 ms  execute <unnamed>: SELECT * FROM test1 WHERE i = $1::int4
      DETAIL:  parameters: $1 = '2'
      
      (This example demonstrates the folly of ignoring parse/bind steps for duration
      logging purposes, BTW.)
      
      Along the way, create a less ad-hoc mechanism for determining which commands
      are logged by log_statement = mod and log_statement = ddl.  The former coding
      was actually missing quite a few things that look like ddl to me, and it
      did not handle EXECUTE or extended query protocol correctly at all.
      
      This commit does not do anything about the question of whether log_duration
      should be removed or made less redundant with log_min_duration_statement.
      893632be
  33. 07 9月, 2006 1 次提交
    • T
      Change processing of extended-Query mode so that an unnamed statement · 5983a1aa
      Tom Lane 提交于
      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
  34. 03 9月, 2006 2 次提交