1. 07 6月, 2011 1 次提交
    • T
      Fix rewriter to cope (more or less) with CTEs in the query being rewritten. · fc1286d3
      Tom Lane 提交于
      Since the original implementation of CTEs only allowed them in SELECT
      queries, the rule rewriter did not expect to find any CTEs in statements
      being rewritten by ON INSERT/UPDATE/DELETE rules.  We had dealt with this
      to some extent but the code was still several bricks shy of a load, as
      illustrated in bug #6051 from Jehan-Guillaume de Rorthais.
      
      In particular, we have to be able to copy CTEs from the original query's
      cteList into that of a rule action, in case the rule action references the
      CTE (which it pretty much always will).  This also implies we were doing
      things in the wrong order in RewriteQuery: we have to recursively rewrite
      the CTE queries before expanding the main query, so that we have the
      rewritten queries available to copy.
      
      There are unpleasant limitations yet to resolve here, but at least we now
      throw understandable FEATURE_NOT_SUPPORTED errors for them instead of just
      failing with bizarre implementation-dependent errors.  In particular, we
      can't handle propagating the same CTE into multiple post-rewrite queries
      (because then the CTE would be evaluated multiple times), and we can't cope
      with conflicts between CTE names in the original query and in the rule
      actions.
      fc1286d3
  2. 10 4月, 2011 1 次提交
  3. 26 3月, 2011 1 次提交
    • T
      Pass collation to makeConst() instead of looking it up internally. · bfa4440c
      Tom Lane 提交于
      In nearly all cases, the caller already knows the correct collation, and
      in a number of places, the value the caller has handy is more correct than
      the default for the type would be.  (In particular, this patch makes it
      significantly less likely that eval_const_expressions will result in
      changing the exposed collation of an expression.)  So an internal lookup
      is both expensive and wrong.
      bfa4440c
  4. 26 2月, 2011 1 次提交
    • T
      Support data-modifying commands (INSERT/UPDATE/DELETE) in WITH. · 389af951
      Tom Lane 提交于
      This patch implements data-modifying WITH queries according to the
      semantics that the updates all happen with the same command counter value,
      and in an unspecified order.  Therefore one WITH clause can't see the
      effects of another, nor can the outer query see the effects other than
      through the RETURNING values.  And attempts to do conflicting updates will
      have unpredictable results.  We'll need to document all that.
      
      This commit just fixes the code; documentation updates are waiting on
      author.
      
      Marko Tiikkaja and Hitoshi Harada
      389af951
  5. 23 2月, 2011 1 次提交
    • T
      Add a relkind field to RangeTblEntry to avoid some syscache lookups. · bdca82f4
      Tom Lane 提交于
      The recent additions for FDW support required checking foreign-table-ness
      in several places in the parse/plan chain.  While it's not clear whether
      that would really result in a noticeable slowdown, it seems best to avoid
      any performance risk by keeping a copy of the relation's relkind in
      RangeTblEntry.  That might have some other uses later, anyway.
      Per discussion.
      bdca82f4
  6. 20 2月, 2011 1 次提交
  7. 09 2月, 2011 1 次提交
    • P
      Per-column collation support · 414c5a2e
      Peter Eisentraut 提交于
      This adds collation support for columns and domains, a COLLATE clause
      to override it per expression, and B-tree index support.
      
      Peter Eisentraut
      reviewed by Pavel Stehule, Itagaki Takahiro, Robert Haas, Noah Misch
      414c5a2e
  8. 02 1月, 2011 1 次提交
  9. 20 10月, 2010 1 次提交
    • T
      Fix incorrect generation of whole-row variables in planner. · 6e74a91b
      Tom Lane 提交于
      A couple of places in the planner need to generate whole-row Vars, and were
      cutting corners by setting vartype = RECORDOID in the Vars, even in cases
      where there's an identifiable named composite type for the RTE being
      referenced.  While we mostly got away with this, it failed when there was
      also a parser-generated whole-row reference to the same RTE, because the
      two Vars weren't equal() due to the difference in vartype.  Fix by
      providing a subroutine the planner can call to generate whole-row Vars
      the same way the parser does.
      
      Per bug #5716 from Andrew Tipton.  Back-patch to 9.0 where one of the bogus
      calls was introduced (the other one is new in HEAD).
      6e74a91b
  10. 11 10月, 2010 1 次提交
    • T
      Support triggers on views. · 2ec993a7
      Tom Lane 提交于
      This patch adds the SQL-standard concept of an INSTEAD OF trigger, which
      is fired instead of performing a physical insert/update/delete.  The
      trigger function is passed the entire old and/or new rows of the view,
      and must figure out what to do to the underlying tables to implement
      the update.  So this feature can be used to implement updatable views
      using trigger programming style rather than rule hacking.
      
      In passing, this patch corrects the names of some columns in the
      information_schema.triggers view.  It seems the SQL committee renamed
      them somewhere between SQL:99 and SQL:2003.
      
      Dean Rasheed, reviewed by Bernd Helmle; some additional hacking by me.
      2ec993a7
  11. 21 9月, 2010 1 次提交
  12. 26 2月, 2010 1 次提交
  13. 03 1月, 2010 1 次提交
  14. 06 11月, 2009 1 次提交
  15. 29 10月, 2009 1 次提交
  16. 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
  17. 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
  18. 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
  19. 11 6月, 2009 1 次提交
  20. 27 1月, 2009 1 次提交
  21. 23 1月, 2009 2 次提交
  22. 02 1月, 2009 1 次提交
  23. 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
  24. 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
  25. 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
  26. 26 8月, 2008 1 次提交
  27. 02 1月, 2008 1 次提交
  28. 16 11月, 2007 2 次提交
  29. 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
  30. 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
  31. 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
  32. 02 3月, 2007 1 次提交
  33. 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
  34. 06 1月, 2007 1 次提交
  35. 07 10月, 2006 1 次提交
  36. 04 10月, 2006 1 次提交
  37. 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