1. 27 1月, 2013 1 次提交
    • T
      Make LATERAL implicit for functions in FROM. · 2378d79a
      Tom Lane 提交于
      The SQL standard does not have general functions-in-FROM, but it does
      allow UNNEST() there (see the <collection derived table> production),
      and the semantics of that are defined to include lateral references.
      So spec compliance requires allowing lateral references within UNNEST()
      even without an explicit LATERAL keyword.  Rather than making UNNEST()
      a special case, it seems best to extend this flexibility to any
      function-in-FROM.  We'll still allow LATERAL to be written explicitly
      for clarity's sake, but it's now a noise word in this context.
      
      In theory this change could result in a change in behavior of existing
      queries, by allowing what had been an outer reference in a function-in-FROM
      to be captured by an earlier FROM-item at the same level.  However, all
      pre-9.3 PG releases have a bug that causes them to match variable
      references to earlier FROM-items in preference to outer references (and
      then throw an error).  So no previously-working query could contain the
      type of ambiguity that would risk a change of behavior.
      
      Per a suggestion from Andrew Gierth, though I didn't use his patch.
      2378d79a
  2. 08 8月, 2012 1 次提交
    • T
      Implement SQL-standard LATERAL subqueries. · 5ebaaa49
      Tom Lane 提交于
      This patch implements the standard syntax of LATERAL attached to a
      sub-SELECT in FROM, and also allows LATERAL attached to a function in FROM,
      since set-returning function calls are expected to be one of the principal
      use-cases.
      
      The main change here is a rewrite of the mechanism for keeping track of
      which relations are visible for column references while the FROM clause is
      being scanned.  The parser "namespace" lists are no longer lists of bare
      RTEs, but are lists of ParseNamespaceItem structs, which carry an RTE
      pointer as well as some visibility-controlling flags.  Aside from
      supporting LATERAL correctly, this lets us get rid of the ancient hacks
      that required rechecking subqueries and JOIN/ON and function-in-FROM
      expressions for invalid references after they were initially parsed.
      Invalid column references are now always correctly detected on sight.
      
      In passing, remove assorted parser error checks that are now dead code by
      virtue of our having gotten rid of add_missing_from, as well as some
      comments that are obsolete for the same reason.  (It was mainly
      add_missing_from that caused so much fudging here in the first place.)
      
      The planner support for this feature is very minimal, and will be improved
      in future patches.  It works well enough for testing purposes, though.
      
      catversion bump forced due to new field in RangeTblEntry.
      5ebaaa49
  3. 05 7月, 2012 1 次提交
  4. 27 6月, 2012 1 次提交
  5. 08 10月, 2011 1 次提交
    • T
      Support index-only scans using the visibility map to avoid heap fetches. · a2822fb9
      Tom Lane 提交于
      When a btree index contains all columns required by the query, and the
      visibility map shows that all tuples on a target heap page are
      visible-to-all, we don't need to fetch that heap page.  This patch depends
      on the previous patches that made the visibility map reliable.
      
      There's a fair amount left to do here, notably trying to figure out a less
      chintzy way of estimating the cost of an index-only scan, but the core
      functionality seems ready to commit.
      
      Robert Haas and Ibrar Ahmed, with some previous work by Heikki Linnakangas.
      a2822fb9
  6. 01 12月, 2010 1 次提交
    • T
      Prevent inlining a SQL function with multiple OUT parameters. · 225f0aa3
      Tom Lane 提交于
      There were corner cases in which the planner would attempt to inline such
      a function, which would result in a failure at runtime due to loss of
      information about exactly what the result record type is.  Fix by disabling
      inlining when the function's recorded result type is RECORD.  There might
      be some sub-cases where inlining could still be allowed, but this is a
      simple and backpatchable fix, so leave refinements for another day.
      Per bug #5777 from Nate Carson.
      
      Back-patch to all supported branches.  8.1 happens to avoid a core-dump
      here, but it still does the wrong thing.
      225f0aa3
  7. 13 7月, 2010 1 次提交
    • T
      Make NestLoop plan nodes pass outer-relation variables into their inner · 53e75768
      Tom Lane 提交于
      relation using the general PARAM_EXEC executor parameter mechanism, rather
      than the ad-hoc kluge of passing the outer tuple down through ExecReScan.
      The previous method was hard to understand and could never be extended to
      handle parameters coming from multiple join levels.  This patch doesn't
      change the set of possible plans nor have any significant performance effect,
      but it's necessary infrastructure for future generalization of the concept
      of an inner indexscan plan.
      
      ExecReScan's second parameter is now unused, so it's removed.
      53e75768
  8. 19 4月, 2010 1 次提交
    • R
      Add an 'enable_material' GUC. · 5b89ef38
      Robert Haas 提交于
      The logic for determining whether to materialize has been significantly
      overhauled for 9.0.  In case there should be any doubt about whether
      materialization is a win in any particular case, this should provide a
      convenient way of seeing what happens without it; but even with enable_material
      turned off, we still materialize in cases where it is required for
      correctness.
      
      Thanks to Tom Lane for the review.
      5b89ef38
  9. 14 12月, 2009 1 次提交
    • T
      Fix a bug introduced when set-returning SQL functions were made inline-able: · a620d500
      Tom Lane 提交于
      we have to cope with the possibility that the declared result rowtype contains
      dropped columns.  This fails in 8.4, as per bug #5240.
      
      While at it, be more paranoid about inserting binary coercions when inlining.
      The pre-8.4 code did not really need to worry about that because it could not
      inline at all in any case where an added coercion could change the behavior
      of the function's statement.  However, when inlining a SRF we allow sorting,
      grouping, and set-ops such as UNION.  In these cases, modifying one of the
      targetlist entries that the sort/group/setop depends on could conceivably
      change the behavior of the function's statement --- so don't inline when
      such a case applies.
      a620d500
  10. 08 10月, 2009 1 次提交
  11. 12 6月, 2009 1 次提交
    • T
      Fix things so that you can still do "select foo()" where foo is a SQL · 0c19f058
      Tom Lane 提交于
      function returning setof record.  This used to work, more or less
      accidentally, but I had broken it while extending the code to allow
      materialize-mode functions to be called in select lists.  Add a regression
      test case so it doesn't get broken again.  Per gripe from Greg Davidson.
      0c19f058
  12. 30 3月, 2009 1 次提交
    • T
      Fix an oversight in the support for storing/retrieving "minimal tuples" in · 793d5662
      Tom Lane 提交于
      TupleTableSlots.  We have functions for retrieving a minimal tuple from a slot
      after storing a regular tuple in it, or vice versa; but these were implemented
      by converting the internal storage from one format to the other.  The problem
      with that is it invalidates any pass-by-reference Datums that were already
      fetched from the slot, since they'll be pointing into the just-freed version
      of the tuple.  The known problem cases involve fetching both a whole-row
      variable and a pass-by-reference value from a slot that is fed from a
      tuplestore or tuplesort object.  The added regression tests illustrate some
      simple cases, but there may be other failure scenarios traceable to the same
      bug.  Note that the added tests probably only fail on unpatched code if it's
      built with --enable-cassert; otherwise the bug leads to fetching from freed
      memory, which will not have been overwritten without additional conditions.
      
      Fix by allowing a slot to contain both formats simultaneously; which turns out
      not to complicate the logic much at all, if anything it seems less contorted
      than before.
      
      Back-patch to 8.2, where minimal tuples were introduced.
      793d5662
  13. 01 11月, 2008 1 次提交
    • T
      Allow SQL-language functions to return the output of an INSERT/UPDATE/DELETE · 9b46abb7
      Tom Lane 提交于
      RETURNING clause, not just a SELECT as formerly.
      
      A side effect of this patch is that when a set-returning SQL function is used
      in a FROM clause, performance is improved because the output is collected into
      a tuplestore within the function, rather than using the less efficient
      value-per-call mechanism.
      9b46abb7
  14. 02 9月, 2008 1 次提交
  15. 18 7月, 2008 1 次提交
  16. 02 4月, 2007 1 次提交
  17. 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
  18. 28 2月, 2006 1 次提交
  19. 07 10月, 2005 1 次提交
    • T
      When a function not returning RECORD has a single OUT parameter, use · 9ea14ef5
      Tom Lane 提交于
      the parameter's name (if any) as the default column name for SELECT FROM
      the function, rather than the function name as previously.  I still think
      this is a bad idea, but I lost the argument.  Force decompilation of
      function RTEs to specify full aliases always, to reduce the odds of this
      decision breaking dumped views.
      9ea14ef5
  20. 23 8月, 2005 1 次提交
  21. 24 7月, 2005 1 次提交
  22. 22 4月, 2005 1 次提交
  23. 01 4月, 2005 1 次提交
  24. 27 7月, 2003 1 次提交
    • B
      > Joe Conway <mail@joeconway.com> writes: · 38fb906f
      Bruce Momjian 提交于
      >>ISTM that "source" is worth knowing.
      >
      > Hm, possibly.  Any other opinions?
      
      This version has the seven fields I proposed, including "source". Here's
      an example that shows why I think it's valuable:
      
      regression=# \x
      Expanded display is on.
      regression=# select * from pg_settings where name = 'enable_seqscan';
      -[ RECORD 1 ]-----------
      name    | enable_seqscan
      setting | on
      context | user
      vartype | bool
      source  | default
      min_val |
      max_val |
      
      regression=# update pg_settings set setting = 'off' where name =
      'enable_seqscan';
      -[ RECORD 1 ]---
      set_config | off
      
      regression=# select * from pg_settings where name = 'enable_seqscan';
      -[ RECORD 1 ]-----------
      name    | enable_seqscan
      setting | off
      context | user
      vartype | bool
      source  | session
      min_val |
      max_val |
      
      regression=# alter user postgres set enable_seqscan to 'off';
      ALTER USER
      
      (log out and then back in again)
      
      regression=# \x
      Expanded display is on.
      regression=# select * from pg_settings where name = 'enable_seqscan';
      -[ RECORD 1 ]-----------
      name    | enable_seqscan
      setting | off
      context | user
      vartype | bool
      source  | user
      min_val |
      max_val |
      
      In the first case, enable_seqscan is set to its default value. After
      setting it to off, it is obvious that the value has been changed for the
      session only. In the third case, you can see that the value has been set
      specifically for the user.
      
      Joe Conway
      38fb906f
  25. 20 7月, 2003 1 次提交
  26. 14 2月, 2003 1 次提交
    • T
      Arrange to give error when a SetOp member statement refers to a variable · 18e8f06c
      Tom Lane 提交于
      of the containing query (which really can only happen in a rule context).
      Per example from Brandon Craig Rhodes.  Also, make the error message
      more specific for the similar case with sub-select in FROM.  The revised
      coding should be easier to adapt to SQL99's LATERAL(), when we get around
      to supporting that.
      18e8f06c
  27. 21 11月, 2002 1 次提交
  28. 31 8月, 2002 1 次提交
  29. 29 8月, 2002 1 次提交
  30. 06 8月, 2002 1 次提交
  31. 16 7月, 2002 1 次提交
    • T
      Add code to extract dependencies from an expression tree, and use it · 30ec3160
      Tom Lane 提交于
      to build dependencies for rules, constraint expressions, and default
      expressions.  Repair some problems in the original design of
      recursiveDeletion() exposed by more complex dependency sets.  Fix
      regression tests that were deleting things in illegal sequences.
      30ec3160
  32. 21 6月, 2002 1 次提交