Skip to content
Snippets Groups Projects
  1. Apr 06, 2012
    • Tom Lane's avatar
      Allow statistics to be collected for foreign tables. · 263d9de6
      Tom Lane authored
      ANALYZE now accepts foreign tables and allows the table's FDW to control
      how the sample rows are collected.  (But only manual ANALYZEs will touch
      foreign tables, for the moment, since among other things it's not very
      clear how to handle remote permissions checks in an auto-analyze.)
      
      contrib/file_fdw is extended to support this.
      
      Etsuro Fujita, reviewed by Shigeru Hanada, some further tweaking by me.
      263d9de6
  2. Apr 03, 2012
  3. Mar 20, 2012
    • Tom Lane's avatar
      Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. · 9dbf2b7d
      Tom Lane authored
      Making this operation look like a utility statement seems generally a good
      idea, and particularly so in light of the desire to provide command
      triggers for utility statements.  The original choice of representing it as
      SELECT with an IntoClause appendage had metastasized into rather a lot of
      places, unfortunately, so that this patch is a great deal more complicated
      than one might at first expect.
      
      In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
      subcommands required restructuring some EXPLAIN-related APIs.  Add-on code
      that calls ExplainOnePlan or ExplainOneUtility, or uses
      ExplainOneQuery_hook, will need adjustment.
      
      Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
      which formerly were accepted though undocumented, are no longer accepted.
      The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
      The CREATE RULE case doesn't seem to have much real-world use (since the
      rule would work only once before failing with "table already exists"),
      so we'll not bother with that one.
      
      Both SELECT INTO and CREATE TABLE AS still return a command tag of
      "SELECT nnnn".  There was some discussion of returning "CREATE TABLE nnnn",
      but for the moment backwards compatibility wins the day.
      
      Andres Freund and Tom Lane
      9dbf2b7d
  4. Mar 10, 2012
  5. Mar 04, 2012
    • Tom Lane's avatar
      Collect and use element-frequency statistics for arrays. · 0e5e167a
      Tom Lane authored
      This patch improves selectivity estimation for the array <@, &&, and @>
      (containment and overlaps) operators.  It enables collection of statistics
      about individual array element values by ANALYZE, and introduces
      operator-specific estimators that use these stats.  In addition,
      ScalarArrayOpExpr constructs of the forms "const = ANY/ALL (array_column)"
      and "const <> ANY/ALL (array_column)" are estimated by treating them as
      variants of the containment operators.
      
      Since we still collect scalar-style stats about the array values as a
      whole, the pg_stats view is expanded to show both these stats and the
      array-style stats in separate columns.  This creates an incompatible change
      in how stats for tsvector columns are displayed in pg_stats: the stats
      about lexemes are now displayed in the array-related columns instead of the
      original scalar-related columns.
      
      There are a few loose ends here, notably that it'd be nice to be able to
      suppress either the scalar-style stats or the array-element stats for
      columns for which they're not useful.  But the patch is in good enough
      shape to commit for wider testing.
      
      Alexander Korotkov, reviewed by Noah Misch and Nathan Boley
      0e5e167a
  6. Feb 26, 2012
    • Peter Eisentraut's avatar
      Remove useless const qualifier · 66f0cf7d
      Peter Eisentraut authored
      Claiming that the typevar argument to DefineCompositeType() is const
      was a plain lie.  A similar case in DefineVirtualRelation() was
      already changed in passing in commit 1575fbcb.  Also clean up the now
      unnecessary casts that used to cast away the const.
      66f0cf7d
  7. Feb 22, 2012
  8. Feb 07, 2012
  9. Jan 27, 2012
  10. Jan 25, 2012
    • Alvaro Herrera's avatar
      Add pg_trigger_depth() function · 74ab96a4
      Alvaro Herrera authored
      This reports the depth level of triggers currently in execution, or zero
      if not called from inside a trigger.
      
      No catversion bump in this patch, but you have to initdb if you want
      access to the new function.
      
      Author: Kevin Grittner
      74ab96a4
  11. Jan 07, 2012
    • Robert Haas's avatar
      Improve behavior of concurrent ALTER TABLE, and do some refactoring. · 1489e2f2
      Robert Haas authored
      ALTER TABLE (and ALTER VIEW, ALTER SEQUENCE, etc.) now use a
      RangeVarGetRelid callback to check permissions before acquiring a table
      lock.  We also now use the same callback for all forms of ALTER TABLE,
      rather than having separate, almost-identical callbacks for ALTER TABLE
      .. SET SCHEMA and ALTER TABLE .. RENAME, and no callback at all for
      everything else.
      
      I went ahead and changed the code so that no form of ALTER TABLE works
      on foreign tables; you must use ALTER FOREIGN TABLE instead.  In 9.1,
      it was possible to use ALTER TABLE .. SET SCHEMA or ALTER TABLE ..
      RENAME on a foreign table, but not any other form of ALTER TABLE, which
      did not seem terribly useful or consistent.
      
      Patch by me; review by Noah Misch.
      1489e2f2
  12. Jan 05, 2012
  13. Jan 02, 2012
  14. Dec 22, 2011
    • Peter Eisentraut's avatar
      Add ALTER DOMAIN ... RENAME · f90dd280
      Peter Eisentraut authored
      You could already rename domains using ALTER TYPE, but with this new
      command it is more consistent with how other commands treat domains as
      a subcategory of types.
      f90dd280
  15. Dec 21, 2011
    • Robert Haas's avatar
      Improve behavior of concurrent CLUSTER. · cbe24a6d
      Robert Haas authored
      In the previous coding, a user could queue up for an AccessExclusiveLock
      on a table they did not have permission to cluster, thus potentially
      interfering with access by authorized users who got stuck waiting behind
      the AccessExclusiveLock.  This approach avoids that.  cluster() has the
      same permissions-checking requirements as REINDEX TABLE, so this commit
      moves the now-shared callback to tablecmds.c and renames it, per
      discussion with Noah Misch.
      cbe24a6d
  16. Dec 16, 2011
    • Robert Haas's avatar
      Improve behavior of concurrent rename statements. · 74a1d4fe
      Robert Haas authored
      Previously, renaming a table, sequence, view, index, foreign table,
      column, or trigger checked permissions before locking the object, which
      meant that if permissions were revoked during the lock wait, we would
      still allow the operation.  Similarly, if the original object is dropped
      and a new one with the same name is created, the operation will be allowed
      if we had permissions on the old object; the permissions on the new
      object don't matter.  All this is now fixed.
      
      Along the way, attempting to rename a trigger on a foreign table now gives
      the same error message as trying to create one there in the first place
      (i.e. that it's not a table or view) rather than simply stating that no
      trigger by that name exists.
      
      Patch by me; review by Noah Misch.
      74a1d4fe
  17. Dec 09, 2011
  18. Nov 18, 2011
    • Robert Haas's avatar
      Further consolidation of DROP statement handling. · fc6d1006
      Robert Haas authored
      This gets rid of an impressive amount of duplicative code, with only
      minimal behavior changes.  DROP FOREIGN DATA WRAPPER now requires object
      ownership rather than superuser privileges, matching the documentation
      we already have.  We also eliminate the historical warning about dropping
      a built-in function as unuseful.  All operations are now performed in the
      same order for all object types handled by dropcmds.c.
      
      KaiGai Kohei, with minor revisions by me
      fc6d1006
  19. Nov 17, 2011
    • Robert Haas's avatar
      Remove ancient downcasing code from procedural language operations. · 67dc4eed
      Robert Haas authored
      A very long time ago, language names were specified as literals rather
      than identifiers, so this code was added to do case-folding.  But that
      style has ben deprecated for many years so this isn't needed any more.
      Language names will still be downcased when specified as unquoted
      identifiers, but quoted identifiers or the old style using string
      literals will be left as-is.
      67dc4eed
  20. Nov 03, 2011
  21. Oct 20, 2011
  22. Oct 14, 2011
    • Tom Lane's avatar
      Measure the number of all-visible pages for use in index-only scan costing. · e6858e66
      Tom Lane authored
      Add a column pg_class.relallvisible to remember the number of pages that
      were all-visible according to the visibility map as of the last VACUUM
      (or ANALYZE, or some other operations that update pg_class.relpages).
      Use relallvisible/relpages, instead of an arbitrary constant, to estimate
      how many heap page fetches can be avoided during an index-only scan.
      
      This is pretty primitive and will no doubt see refinements once we've
      acquired more field experience with the index-only scan mechanism, but
      it's way better than using a constant.
      
      Note: I had to adjust an underspecified query in the window.sql regression
      test, because it was changing answers when the plan changed to use an
      index-only scan.  Some of the adjacent tests perhaps should be adjusted
      as well, but I didn't do that here.
      e6858e66
  23. Sep 16, 2011
    • Tom Lane's avatar
      Redesign the plancache mechanism for more flexibility and efficiency. · e6faf910
      Tom Lane authored
      Rewrite plancache.c so that a "cached plan" (which is rather a misnomer
      at this point) can support generation of custom, parameter-value-dependent
      plans, and can make an intelligent choice between using custom plans and
      the traditional generic-plan approach.  The specific choice algorithm
      implemented here can probably be improved in future, but this commit is
      all about getting the mechanism in place, not the policy.
      
      In addition, restructure the API to greatly reduce the amount of extraneous
      data copying needed.  The main compromise needed to make that possible was
      to split the initial creation of a CachedPlanSource into two steps.  It's
      worth noting in particular that SPI_saveplan is now deprecated in favor of
      SPI_keepplan, which accomplishes the same end result with zero data
      copying, and no need to then spend even more cycles throwing away the
      original SPIPlan.  The risk of long-term memory leaks while manipulating
      SPIPlans has also been greatly reduced.  Most of this improvement is based
      on use of the recently-added MemoryContextSetParent primitive.
      e6faf910
  24. Sep 09, 2011
    • Tom Lane's avatar
      Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h. · a7801b62
      Tom Lane authored
      As per my recent proposal, this refactors things so that these typedefs and
      macros are available in a header that can be included in frontend-ish code.
      I also changed various headers that were undesirably including
      utils/timestamp.h to include datatype/timestamp.h instead.  Unsurprisingly,
      this showed that half the system was getting utils/timestamp.h by way of
      xlog.h.
      
      No actual code changes here, just header refactoring.
      a7801b62
  25. Sep 04, 2011
    • Tom Lane's avatar
      Clean up the #include mess a little. · 1609797c
      Tom Lane authored
      walsender.h should depend on xlog.h, not vice versa.  (Actually, the
      inclusion was circular until a couple hours ago, which was even sillier;
      but Bruce broke it in the expedient rather than logically correct
      direction.)  Because of that poor decision, plus blind application of
      pgrminclude, we had a situation where half the system was depending on
      xlog.h to include such unrelated stuff as array.h and guc.h.  Clean up
      the header inclusion, and manually revert a lot of what pgrminclude had
      done so things build again.
      
      This episode reinforces my feeling that pgrminclude should not be run
      without adult supervision.  Inclusion changes in header files in particular
      need to be reviewed with great care.  More generally, it'd be good if we
      had a clearer notion of module layering to dictate which headers can sanely
      include which others ... but that's a big task for another day.
      1609797c
  26. Sep 02, 2011
    • Tom Lane's avatar
      Teach ANALYZE to clear pg_class.relhassubclass when appropriate. · 5b562644
      Tom Lane authored
      In the past, relhassubclass always remained true if a relation had ever had
      child relations, even if the last subclass was long gone.  While this had
      only marginal performance implications in most cases, it was annoying, and
      I'm now considering some planner changes that would raise the cost of a
      false positive.  It was previously impractical to fix this because of race
      condition concerns.  However, given the recent change that made tablecmds.c
      take ShareExclusiveLock on relations that are gaining a child (commit
      fbcf4b92), we can now allow ANALYZE to
      clear the flag when it's no longer relevant.  There is no additional
      locking cost to do so, since ANALYZE takes ShareExclusiveLock anyway.
      5b562644
  27. Sep 01, 2011
  28. Aug 23, 2011
  29. Jul 20, 2011
    • Robert Haas's avatar
      Support SECURITY LABEL on databases, tablespaces, and roles. · 463f2625
      Robert Haas authored
      This requires a new shared catalog, pg_shseclabel.
      
      Along the way, fix the security_label regression tests so that they
      don't monkey with the labels of any pre-existing objects.  This is
      unlikely to matter in practice, since only the label for the "dummy"
      provider was being manipulated.  But this way still seems cleaner.
      
      KaiGai Kohei, with fairly extensive hacking by me.
      463f2625
  30. Jul 18, 2011
  31. Jul 09, 2011
    • Robert Haas's avatar
      Try to acquire relation locks in RangeVarGetRelid. · 4240e429
      Robert Haas authored
      In the previous coding, we would look up a relation in RangeVarGetRelid,
      lock the resulting OID, and then AcceptInvalidationMessages().  While
      this was sufficient to ensure that we noticed any changes to the
      relation definition before building the relcache entry, it didn't
      handle the possibility that the name we looked up no longer referenced
      the same OID.  This was particularly problematic in the case where a
      table had been dropped and recreated: we'd latch on to the entry for
      the old relation and fail later on.  Now, we acquire the relation lock
      inside RangeVarGetRelid, and retry the name lookup if we notice that
      invalidation messages have been processed meanwhile.  Many operations
      that would previously have failed with an error in the presence of
      concurrent DDL will now succeed.
      
      There is a good deal of work remaining to be done here: many callers
      of RangeVarGetRelid still pass NoLock for one reason or another.  In
      addition, nothing in this patch guards against the possibility that
      the meaning of an unqualified name might change due to the creation
      of a relation in a schema earlier in the user's search path than the
      one where it was previously found.  Furthermore, there's nothing at
      all here to guard against similar race conditions for non-relations.
      For all that, it's a start.
      
      Noah Misch and Robert Haas
      4240e429
  32. Jun 30, 2011
    • Alvaro Herrera's avatar
      Enable CHECK constraints to be declared NOT VALID · 89779524
      Alvaro Herrera authored
      This means that they can initially be added to a large existing table
      without checking its initial contents, but new tuples must comply to
      them; a separate pass invoked by ALTER TABLE / VALIDATE can verify
      existing data and ensure it complies with the constraint, at which point
      it is marked validated and becomes a normal part of the table ecosystem.
      
      An non-validated CHECK constraint is ignored in the planner for
      constraint_exclusion purposes; when validated, cached plans are
      recomputed so that partitioning starts working right away.
      
      This patch also enables domains to have unvalidated CHECK constraints
      attached to them as well by way of ALTER DOMAIN / ADD CONSTRAINT / NOT
      VALID, which can later be validated with ALTER DOMAIN / VALIDATE
      CONSTRAINT.
      
      Thanks to Thom Brown, Dean Rasheed and Jaime Casanova for the various
      reviews, and Robert Hass for documentation wording improvement
      suggestions.
      
      This patch was sponsored by Enova Financial.
      89779524
  33. May 30, 2011
    • Tom Lane's avatar
      Fix VACUUM so that it always updates pg_class.reltuples/relpages. · b4b6923e
      Tom Lane authored
      When we added the ability for vacuum to skip heap pages by consulting the
      visibility map, we made it just not update the reltuples/relpages
      statistics if it skipped any pages.  But this could leave us with extremely
      out-of-date stats for a table that contains any unchanging areas,
      especially for TOAST tables which never get processed by ANALYZE.  In
      particular this could result in autovacuum making poor decisions about when
      to process the table, as in recent report from Florian Helmberger.  And in
      general it's a bad idea to not update the stats at all.  Instead, use the
      previous values of reltuples/relpages as an estimate of the tuple density
      in unvisited pages.  This approach results in a "moving average" estimate
      of reltuples, which should converge to the correct value over multiple
      VACUUM and ANALYZE cycles even when individual measurements aren't very
      good.
      
      This new method for updating reltuples is used by both VACUUM and ANALYZE,
      with the result that we no longer need the grotty interconnections that
      caused ANALYZE to not update the stats depending on what had happened
      in the parent VACUUM command.
      
      Also, fix the logic for skipping all-visible pages during VACUUM so that it
      looks ahead rather than behind to decide what to do, as per a suggestion
      from Greg Stark.  This eliminates useless scanning of all-visible pages at
      the start of the relation or just after a not-all-visible page.  In
      particular, the first few pages of the relation will not be invariably
      included in the scanned pages, which seems to help in not overweighting
      them in the reltuples estimate.
      
      Back-patch to 8.4, where the visibility map was introduced.
      b4b6923e
  34. Apr 21, 2011
    • Robert Haas's avatar
      Allow ALTER TABLE name {OF type | NOT OF}. · 68739ba8
      Robert Haas authored
      This syntax allows a standalone table to be made into a typed table,
      or a typed table to be made standalone.  This is possibly a mildly
      useful feature in its own right, but the real motivation for this
      change is that we need it to make pg_upgrade work with typed tables.
      This doesn't actually fix that problem, but it's necessary
      infrastructure.
      
      Noah Misch
      68739ba8
  35. Apr 10, 2011
  36. Apr 07, 2011
    • Tom Lane's avatar
      Revise the API for GUC variable assign hooks. · 2594cf0e
      Tom Lane authored
      The previous functions of assign hooks are now split between check hooks
      and assign hooks, where the former can fail but the latter shouldn't.
      Aside from being conceptually clearer, this approach exposes the
      "canonicalized" form of the variable value to guc.c without having to do
      an actual assignment.  And that lets us fix the problem recently noted by
      Bernd Helmle that the auto-tune patch for wal_buffers resulted in bogus
      log messages about "parameter "wal_buffers" cannot be changed without
      restarting the server".  There may be some speed advantage too, because
      this design lets hook functions avoid re-parsing variable values when
      restoring a previous state after a rollback (they can store a pre-parsed
      representation of the value instead).  This patch also resolves a
      longstanding annoyance about custom error messages from variable assign
      hooks: they should modify, not appear separately from, guc.c's own message
      about "invalid parameter value".
      2594cf0e
  37. Mar 12, 2011
    • Tom Lane's avatar
      Make all comparisons done for/with statistics use the default collation. · 696d1f7f
      Tom Lane authored
      While this will give wrong answers when estimating selectivity for a
      comparison operator that's using a non-default collation, the estimation
      error probably won't be large; and anyway the former approach created
      estimation errors of its own by trying to use a histogram that might have
      been computed with some other collation.  So we'll adopt this simplified
      approach for now and perhaps improve it sometime in the future.
      
      This patch incorporates changes from Andres Freund to make sure that
      selfuncs.c passes a valid collation OID to any datatype-specific function
      it calls, in case that function wants collation information.  Said OID will
      now always be DEFAULT_COLLATION_OID, but at least we won't get errors.
      696d1f7f
  38. Feb 22, 2011
    • Tom Lane's avatar
      Fix dangling-pointer problem in before-row update trigger processing. · a210be77
      Tom Lane authored
      ExecUpdate checked for whether ExecBRUpdateTriggers had returned a new
      tuple value by seeing if the returned tuple was pointer-equal to the old
      one.  But the "old one" was in estate->es_junkFilter's result slot, which
      would be scribbled on if we had done an EvalPlanQual update in response to
      a concurrent update of the target tuple; therefore we were comparing a
      dangling pointer to a live one.  Given the right set of circumstances we
      could get a false match, resulting in not forcing the tuple to be stored in
      the slot we thought it was stored in.  In the case reported by Maxim Boguk
      in bug #5798, this led to "cannot extract system attribute from virtual
      tuple" failures when trying to do "RETURNING ctid".  I believe there is a
      very-low-probability chance of more serious errors, such as generating
      incorrect index entries based on the original rather than the
      trigger-modified version of the row.
      
      In HEAD, change all of ExecBRInsertTriggers, ExecIRInsertTriggers,
      ExecBRUpdateTriggers, and ExecIRUpdateTriggers so that they continue to
      have similar APIs.  In the back branches I just changed
      ExecBRUpdateTriggers, since there is no bug in the ExecBRInsertTriggers
      case.
      a210be77
  39. Feb 20, 2011
    • Tom Lane's avatar
      Add contrib/file_fdw foreign-data wrapper for reading files via COPY. · 7c5d0ae7
      Tom Lane authored
      This is both very useful in its own right, and an important test case
      for the core FDW support.
      
      This commit includes a small refactoring of copy.c to expose its option
      checking code as a separately callable function.  The original patch
      submission duplicated hundreds of lines of that code, which seemed pretty
      unmaintainable.
      
      Shigeru Hanada, reviewed by Itagaki Takahiro and Tom Lane
      7c5d0ae7
    • Tom Lane's avatar
      Implement an API to let foreign-data wrappers actually be functional. · bb742407
      Tom Lane authored
      This commit provides the core code and documentation needed.  A contrib
      module test case will follow shortly.
      
      Shigeru Hanada, Jan Urbanski, Heikki Linnakangas
      bb742407
Loading