1. 28 10月, 2009 2 次提交
    • T
      When FOR UPDATE/SHARE is used with LIMIT, put the LockRows plan node · 46e3a16b
      Tom Lane 提交于
      underneath the Limit node, not atop it.  This fixes the old problem that such
      a query might unexpectedly return fewer rows than the LIMIT says, due to
      LockRows discarding updated rows.
      
      There is a related problem that LockRows might destroy the sort ordering
      produced by earlier steps; but fixing that by pushing LockRows below Sort
      would create serious performance problems that are unjustified in many
      real-world applications, as well as potential deadlock problems from locking
      many more rows than expected.  Instead, keep the present semantics of applying
      FOR UPDATE after ORDER BY within a single query level; but allow the user to
      specify the other way by writing FOR UPDATE in a sub-select.  To make that
      work, track whether FOR UPDATE appeared explicitly in sub-selects or got
      pushed down from the parent, and don't flatten a sub-select that contained an
      explicit FOR UPDATE.
      46e3a16b
    • T
      Make FOR UPDATE/SHARE in the primary query not propagate into WITH queries; · 61e53282
      Tom Lane 提交于
      for example in
        WITH w AS (SELECT * FROM foo) SELECT * FROM w, bar ... FOR UPDATE
      the FOR UPDATE will now affect bar but not foo.  This is more useful and
      consistent than the original 8.4 behavior, which tried to propagate FOR UPDATE
      into the WITH query but always failed due to assorted implementation
      restrictions.  Even though we are in process of removing those restrictions,
      it seems correct on philosophical grounds to not let the outer query's
      FOR UPDATE affect the WITH query.
      
      In passing, fix isLockedRel which frequently got things wrong in
      nested-subquery cases: "FOR UPDATE OF foo" applies to an alias foo in the
      current query level, not subqueries.  This has been broken for a long time,
      but it doesn't seem worth back-patching further than 8.4 because the actual
      consequences are minimal.  At worst the parser would sometimes get
      RowShareLock on a relation when it should be AccessShareLock or vice versa.
      That would only make a difference if someone were using ExclusiveLock
      concurrently, which no standard operation does, and anyway FOR UPDATE
      doesn't result in visible changes so it's not clear that the someone would
      notice any problem.  Between that and the fact that FOR UPDATE barely works
      with subqueries at all in existing releases, I'm not excited about worrying
      about it.
      61e53282
  2. 26 10月, 2009 1 次提交
    • T
      Re-implement EvalPlanQual processing to improve its performance and eliminate · 9f2ee8f2
      Tom Lane 提交于
      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
  3. 03 9月, 2009 1 次提交
    • T
      Fix subquery pullup to wrap a PlaceHolderVar around the entire RowExpr · 57c9dff9
      Tom Lane 提交于
      that's generated for a whole-row Var referencing the subquery, when the
      subquery is in the nullable side of an outer join.  The previous coding
      instead put PlaceHolderVars around the elements of the RowExpr.  The effect
      was that when the outer join made the subquery outputs go to null, the
      whole-row Var produced ROW(NULL,NULL,...) rather than just NULL.  There
      are arguments afoot about whether those things ought to be semantically
      indistinguishable, but for the moment they are not entirely so, and the
      planner needs to take care that its machinations preserve the difference.
      Per bug #5025.
      
      Making this feasible required refactoring ResolveNew() to allow more caller
      control over what is substituted for a Var.  I chose to make ResolveNew()
      a wrapper around a new general-purpose function replace_rte_variables().
      I also fixed the ancient bogosity that ResolveNew might fail to set
      a query's hasSubLinks field after inserting a SubLink in it.  Although
      all current callers make sure that happens anyway, we've had bugs of that
      sort before, and it seemed like a good time to install a proper solution.
      
      Back-patch to 8.4.  The problem can be demonstrated clear back to 8.0,
      but the fix would be too invasive in earlier branches; not to mention
      that people may be depending on the subtly-incorrect behavior.  The
      8.4 series is new enough that fixing this probably won't cause complaints,
      but it might in older branches.  Also, 8.4 shows the incorrect behavior
      in more cases than older branches do, because it is able to flatten
      subqueries in more cases.
      57c9dff9
  4. 11 6月, 2009 1 次提交
  5. 27 1月, 2009 1 次提交
  6. 23 1月, 2009 2 次提交
  7. 02 1月, 2009 1 次提交
  8. 05 10月, 2008 1 次提交
    • T
      Implement SQL-standard WITH clauses, including WITH RECURSIVE. · 44d5be0e
      Tom Lane 提交于
      There are some unimplemented aspects: recursive queries must use UNION ALL
      (should allow UNION too), and we don't have SEARCH or CYCLE clauses.
      These might or might not get done for 8.4, but even without them it's a
      pretty useful feature.
      
      There are also a couple of small loose ends and definitional quibbles,
      which I'll send a memo about to pgsql-hackers shortly.  But let's land
      the patch now so we can get on with other development.
      
      Yoshiyuki Asaba, with lots of help from Tatsuo Ishii and Tom Lane
      44d5be0e
  9. 25 9月, 2008 1 次提交
    • T
      Fix more problems with rewriter failing to set Query.hasSubLinks when inserting · 96a25d39
      Tom Lane 提交于
      a SubLink expression into a rule query.  We missed cases where the original
      query contained a sub-SELECT in a function in FROM, a multi-row VALUES list,
      or a RETURNING list.  Per bug #4434 from Dean Rasheed and subsequent
      investigation.
      
      Back-patch to 8.1; older releases don't have the issue because they didn't
      try to be smart about setting hasSubLinks only when needed.
      96a25d39
  10. 29 8月, 2008 1 次提交
    • T
      Extend the parser location infrastructure to include a location field in · a2794623
      Tom Lane 提交于
      most node types used in expression trees (both before and after parse
      analysis).  This allows us to place an error cursor in many situations
      where we formerly could not, because the information wasn't available
      beyond the very first level of parse analysis.  There's a fair amount
      of work still to be done to persuade individual ereport() calls to actually
      include an error location, but this gets the initdb-forcing part of the
      work out of the way; and the situation is already markedly better than
      before for complaints about unimplementable implicit casts, such as
      CASE and UNION constructs with incompatible alternative data types.
      Per my proposal of a few days ago.
      a2794623
  11. 26 8月, 2008 1 次提交
  12. 02 1月, 2008 1 次提交
  13. 16 11月, 2007 2 次提交
  14. 07 9月, 2007 1 次提交
    • T
      Make eval_const_expressions() preserve typmod when simplifying something like · f8942f4a
      Tom Lane 提交于
      null::char(3) to a simple Const node.  (It already worked for non-null values,
      but not when we skipped evaluation of a strict coercion function.)  This
      prevents loss of typmod knowledge in situations such as exhibited in bug
      #3598.  Unfortunately there seems no good way to fix that bug in 8.1 and 8.2,
      because they simply don't carry a typmod for a plain Const node.
      
      In passing I made all the other callers of makeNullConst supply "real" typmod
      values too, though I think it probably doesn't matter anywhere else.
      f8942f4a
  15. 20 3月, 2007 1 次提交
    • J
      Changes pg_trigger and extend pg_rewrite in order to allow triggers and · 0fe16500
      Jan Wieck 提交于
      rules to be defined with different, per session controllable, behaviors
      for replication purposes.
      
      This will allow replication systems like Slony-I and, as has been stated
      on pgsql-hackers, other products to control the firing mechanism of
      triggers and rewrite rules without modifying the system catalog directly.
      
      The firing mechanisms are controlled by a new superuser-only GUC
      variable, session_replication_role, together with a change to
      pg_trigger.tgenabled and a new column pg_rewrite.ev_enabled. Both
      columns are a single char data type now (tgenabled was a bool before).
      The possible values in these attributes are:
      
           'O' - Trigger/Rule fires when session_replication_role is "origin"
                 (default) or "local". This is the default behavior.
      
           'D' - Trigger/Rule is disabled and fires never
      
           'A' - Trigger/Rule fires always regardless of the setting of
                 session_replication_role
      
           'R' - Trigger/Rule fires when session_replication_role is "replica"
      
      The GUC variable can only be changed as long as the system does not have
      any cached query plans. This will prevent changing the session role and
      accidentally executing stored procedures or functions that have plans
      cached that expand to the wrong query set due to differences in the rule
      firing semantics.
      
      The SQL syntax for changing a triggers/rules firing semantics is
      
           ALTER TABLE <tabname> <when> TRIGGER|RULE <name>;
      
           <when> ::= ENABLE | ENABLE ALWAYS | ENABLE REPLICA | DISABLE
      
      psql's \d command as well as pg_dump are extended in a backward
      compatible fashion.
      
      Jan
      0fe16500
  16. 17 3月, 2007 1 次提交
    • T
      Fix up the remaining places where the expression node structure would lose · 0f4ff460
      Tom Lane 提交于
      available information about the typmod of an expression; namely, Const,
      ArrayRef, ArrayExpr, and EXPR and ARRAY SubLinks.  In the ArrayExpr and
      SubLink cases it wasn't really the data structure's fault, but exprTypmod()
      being lazy.  This seems like a good idea in view of the expected increase in
      typmod usage from Teodor's work to allow user-defined types to have typmods.
      In particular this responds to the concerns we had about eliminating the
      special-purpose hack that exprTypmod() used to have for BPCHAR Consts.
      We can now tell whether or not such a Const has been cast to a specific
      length, and report or display properly if so.
      
      initdb forced due to changes in stored rules.
      0f4ff460
  17. 02 3月, 2007 1 次提交
  18. 02 2月, 2007 1 次提交
    • B
      Wording cleanup for error messages. Also change can't -> cannot. · 8b4ff8b6
      Bruce Momjian 提交于
      Standard English uses "may", "can", and "might" in different ways:
      
              may - permission, "You may borrow my rake."
      
              can - ability, "I can lift that log."
      
              might - possibility, "It might rain today."
      
      Unfortunately, in conversational English, their use is often mixed, as
      in, "You may use this variable to do X", when in fact, "can" is a better
      choice.  Similarly, "It may crash" is better stated, "It might crash".
      8b4ff8b6
  19. 06 1月, 2007 1 次提交
  20. 07 10月, 2006 1 次提交
  21. 04 10月, 2006 1 次提交
  22. 03 9月, 2006 1 次提交
    • T
      Apply a simple solution to the problem of making INSERT/UPDATE/DELETE · 917bbebf
      Tom Lane 提交于
      RETURNING play nice with views/rules.  To wit, have the rule rewriter
      rewrite any RETURNING clause found in a rule to produce what the rule's
      triggering query asked for in its RETURNING clause, in particular drop
      the RETURNING clause if no RETURNING in the triggering query.  This
      leaves the responsibility for knowing how to produce the view's output
      columns on the rule author, without requiring any fundamental changes
      in rule semantics such as adding new rule event types would do.  The
      initial implementation constrains things to ensure that there is
      exactly one, unconditionally invoked RETURNING clause among the rules
      for an event --- later we might be able to relax that, but for a post
      feature freeze fix it seems better to minimize how much invention we do.
      Per gripe from Jaime Casanova.
      917bbebf
  23. 02 8月, 2006 1 次提交
  24. 14 7月, 2006 1 次提交
  25. 01 5月, 2006 1 次提交
  26. 06 4月, 2006 1 次提交
    • T
      Fix a bunch of problems with domains by making them use special input functions · 7fdb4305
      Tom Lane 提交于
      that apply the necessary domain constraint checks immediately.  This fixes
      cases where domain constraints went unchecked for statement parameters,
      PL function local variables and results, etc.  We can also eliminate existing
      special cases for domains in places that had gotten it right, eg COPY.
      
      Also, allow domains over domains (base of a domain is another domain type).
      This almost worked before, but was disallowed because the original patch
      hadn't gotten it quite right.
      7fdb4305
  27. 05 3月, 2006 1 次提交
  28. 24 11月, 2005 1 次提交
  29. 23 11月, 2005 1 次提交
  30. 15 10月, 2005 1 次提交
  31. 02 8月, 2005 1 次提交
  32. 29 7月, 2005 1 次提交
  33. 28 6月, 2005 1 次提交
    • T
      Replace pg_shadow and pg_group by new role-capable catalogs pg_authid · 7762619e
      Tom Lane 提交于
      and pg_auth_members.  There are still many loose ends to finish in this
      patch (no documentation, no regression tests, no pg_dump support for
      instance).  But I'm going to commit it now anyway so that Alvaro can
      make some progress on shared dependencies.  The catalog changes should
      be pretty much done.
      7762619e
  34. 05 6月, 2005 1 次提交
  35. 04 6月, 2005 1 次提交
    • T
      Revise handling of dropped columns in JOIN alias lists to avoid a · ba420024
      Tom Lane 提交于
      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
  36. 30 5月, 2005 1 次提交
  37. 29 4月, 2005 1 次提交
    • T
      Implement sharable row-level locks, and use them for foreign key references · bedb78d3
      Tom Lane 提交于
      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