1. 22 12月, 2011 1 次提交
    • R
      Improve behavior of concurrent CLUSTER. · cbe24a6d
      Robert Haas 提交于
      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
  2. 20 12月, 2011 2 次提交
    • P
      Add support for privileges on types · 72920557
      Peter Eisentraut 提交于
      This adds support for the more or less SQL-conforming USAGE privilege
      on types and domains.  The intent is to be able restrict which users
      can create dependencies on types, which restricts the way in which
      owners can alter types.
      
      reviewed by Yeb Havinga
      72920557
    • A
      Allow CHECK constraints to be declared ONLY · 61d81bd2
      Alvaro Herrera 提交于
      This makes them enforceable only on the parent table, not on children
      tables.  This is useful in various situations, per discussion involving
      people bitten by the restrictive behavior introduced in 8.4.
      
      Message-Id:
      8762mp93iw.fsf@comcast.net
      CAFaPBrSMMpubkGf4zcRL_YL-AERUbYF_-ZNNYfb3CVwwEqc9TQ@mail.gmail.com
      
      Authors: Nikhil Sontakke, Alex Hunsaker
      Reviewed by Robert Haas and myself
      61d81bd2
  3. 16 12月, 2011 2 次提交
    • R
      Improve behavior of concurrent ALTER <relation> .. SET SCHEMA. · 1da5c119
      Robert Haas 提交于
      If the referrent of a name changes while we're waiting for the lock,
      we must recheck permissons.  We also now check the relkind before
      locking, since it's easy to do that long the way.
      
      Patch by me; review by Noah Misch.
      1da5c119
    • R
      Improve behavior of concurrent rename statements. · 74a1d4fe
      Robert Haas 提交于
      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
  4. 07 12月, 2011 1 次提交
  5. 30 11月, 2011 1 次提交
    • R
      Improve table locking behavior in the face of current DDL. · 2ad36c4e
      Robert Haas 提交于
      In the previous coding, callers were faced with an awkward choice:
      look up the name, do permissions checks, and then lock the table; or
      look up the name, lock the table, and then do permissions checks.
      The first choice was wrong because the results of the name lookup
      and permissions checks might be out-of-date by the time the table
      lock was acquired, while the second allowed a user with no privileges
      to interfere with access to a table by users who do have privileges
      (e.g. if a malicious backend queues up for an AccessExclusiveLock on
      a table on which AccessShareLock is already held, further attempts
      to access the table will be blocked until the AccessExclusiveLock
      is obtained and the malicious backend's transaction rolls back).
      
      To fix, allow callers of RangeVarGetRelid() to pass a callback which
      gets executed after performing the name lookup but before acquiring
      the relation lock.  If the name lookup is retried (because
      invalidation messages are received), the callback will be re-executed
      as well, so we get the best of both worlds.  RangeVarGetRelid() is
      renamed to RangeVarGetRelidExtended(); callers not wishing to supply
      a callback can continue to invoke it as RangeVarGetRelid(), which is
      now a macro.  Since the only one caller that uses nowait = true now
      passes a callback anyway, the RangeVarGetRelid() macro defaults nowait
      as well.  The callback can also be used for supplemental locking - for
      example, REINDEX INDEX needs to acquire the table lock before the index
      lock to reduce deadlock possibilities.
      
      There's a lot more work to be done here to fix all the cases where this
      can be a problem, but this commit provides the general infrastructure
      and fixes the following specific cases: REINDEX INDEX, REINDEX TABLE,
      LOCK TABLE, and and DROP TABLE/INDEX/SEQUENCE/VIEW/FOREIGN TABLE.
      
      Per discussion with Noah Misch and Alvaro Herrera.
      2ad36c4e
  6. 27 10月, 2011 2 次提交
    • T
      Change FK trigger naming convention to fix self-referential FKs. · 1e3b21dd
      Tom Lane 提交于
      Use names like "RI_ConstraintTrigger_a_NNNN" for FK action triggers and
      "RI_ConstraintTrigger_c_NNNN" for FK check triggers.  This ensures the
      action trigger fires first in self-referential cases where the very same
      row update fires both an action and a check trigger.  This change provides
      a non-probabilistic solution for bug #6268, at the risk that it could break
      client code that is making assumptions about the exact names assigned to
      auto-generated FK triggers.  Hence, change this in HEAD only.  No need for
      forced initdb since old triggers continue to work fine.
      1e3b21dd
    • T
      Change FK trigger creation order to better support self-referential FKs. · 58958726
      Tom Lane 提交于
      When a foreign-key constraint references another column of the same table,
      row updates will queue both the PK's ON UPDATE action and the FK's CHECK
      action in the same event.  The ON UPDATE action must execute first, else
      the CHECK will check a non-final state of the row and possibly throw an
      inappropriate error, as seen in bug #6268 from Roman Lytovchenko.
      
      Now, the firing order of multiple triggers for the same event is determined
      by the sort order of their pg_trigger.tgnames, and the auto-generated names
      we use for FK triggers are "RI_ConstraintTrigger_NNNN" where NNNN is the
      trigger OID.  So most of the time the firing order is the same as creation
      order, and so rearranging the creation order fixes it.
      
      This patch will fail to fix the problem if the OID counter wraps around or
      adds a decimal digit (eg, from 99999 to 100000) while we are creating the
      triggers for an FK constraint.  Given the small odds of that, and the low
      usage of self-referential FKs, we'll live with that solution in the back
      branches.  A better fix is to change the auto-generated names for FK
      triggers, but it seems unwise to do that in stable branches because there
      may be client code that depends on the naming convention.  We'll fix it
      that way in HEAD in a separate patch.
      
      Back-patch to all supported branches, since this bug has existed for a long
      time.
      58958726
  7. 10 10月, 2011 1 次提交
    • R
      Fix ALTER TABLE ONLY .. DROP CONSTRAINT. · c0f03aae
      Robert Haas 提交于
      When I consolidated two copies of the HOT-chain search logic in commit
      4da99ea4, I introduced a behavior
      change: the old code wouldn't necessarily traverse the entire chain,
      if the most recently returned tuple were updated while the HOT chain
      traversal is in progress.  The new behavior seems more correct, but
      unfortunately, the code here relies on a scan with SnapshotNow failing
      to see its own updates.  That seems pretty shaky even with the old HOT
      chain traversal behavior, since there's no guarantee that these
      updates will always be HOT, but it's trivial to broke a failure with
      the new HOT search logic.  Fix by updating just the first matching
      pg_constraint tuple, rather than all of them, since there should be
      only one anyway.  But since nobody has reproduced this failure on older
      versions, no back-patch for now.
      
      Report and test case by Alex Hunsaker; tablecmds.c changes by me.
      c0f03aae
  8. 03 9月, 2011 1 次提交
    • T
      Teach ANALYZE to clear pg_class.relhassubclass when appropriate. · 5b562644
      Tom Lane 提交于
      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
  9. 06 8月, 2011 1 次提交
  10. 18 7月, 2011 1 次提交
  11. 09 7月, 2011 1 次提交
    • R
      Try to acquire relation locks in RangeVarGetRelid. · 4240e429
      Robert Haas 提交于
      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
  12. 08 7月, 2011 1 次提交
  13. 05 7月, 2011 1 次提交
  14. 04 7月, 2011 2 次提交
    • S
      Reset ALTER TABLE lock levels to AccessExclusiveLock in all cases. · 2c3d9db5
      Simon Riggs 提交于
      Locks on inheritance parent remain at lower level, as they were before.
      Remove entry from 9.1 release notes.
      2c3d9db5
    • R
      Fix bugs in relpersistence handling during table creation. · 5da79169
      Robert Haas 提交于
      Unlike the relistemp field which it replaced, relpersistence must be
      set correctly quite early during the table creation process, as we
      rely on it quite early on for a number of purposes, including security
      checks.  Normally, this is set based on whether the user enters CREATE
      TABLE, CREATE UNLOGGED TABLE, or CREATE TEMPORARY TABLE, but a
      relation may also be made implicitly temporary by creating it in
      pg_temp.  This patch fixes the handling of that case, and also
      disables creation of unlogged tables in temporary tablespace (such
      table indeed skip WAL-logging, but we reject an explicit
      specification) and creation of relations in the temporary schemas of
      other sessions (which is not very sensible, and didn't work right
      anyway).
      
      Report by Amit Khandekar.
      5da79169
  15. 30 6月, 2011 1 次提交
    • A
      Enable CHECK constraints to be declared NOT VALID · 89779524
      Alvaro Herrera 提交于
      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
  16. 22 6月, 2011 2 次提交
  17. 16 6月, 2011 1 次提交
    • T
      Rework parsing of ConstraintAttributeSpec to improve NOT VALID handling. · e1ccaff6
      Tom Lane 提交于
      The initial commit of the ALTER TABLE ADD FOREIGN KEY NOT VALID feature
      failed to support labeling such constraints as deferrable.  The best fix
      for this seems to be to fold NOT VALID into ConstraintAttributeSpec.
      That's a bit more general than the documented syntax, but it allows
      better-targeted syntax error messages.
      
      In addition, do some mostly-but-not-entirely-cosmetic code review for
      the whole NOT VALID patch.
      e1ccaff6
  18. 10 6月, 2011 1 次提交
  19. 08 6月, 2011 1 次提交
    • H
      Make DDL operations play nicely with Serializable Snapshot Isolation. · 8f9622bb
      Heikki Linnakangas 提交于
      Truncating or dropping a table is treated like deletion of all tuples, and
      check for conflicts accordingly. If a table is clustered or rewritten by
      ALTER TABLE, all predicate locks on the heap are promoted to relation-level
      locks, because the tuple or page ids of any existing tuples will change and
      won't be valid after rewriting the table. Arguably ALTER TABLE should be
      treated like a mass-UPDATE of every row, but if you e.g change the datatype
      of a column, you could also argue that it's just a change to the physical
      layout, not a logical change. Reindexing promotes all locks on the index to
      relation-level lock on the heap.
      
      Kevin Grittner, with a lot of cosmetic changes by me.
      8f9622bb
  20. 03 6月, 2011 1 次提交
  21. 28 5月, 2011 1 次提交
  22. 26 4月, 2011 2 次提交
    • T
      Remove incorrect HINT for use of ALTER FOREIGN TABLE on the wrong relkind. · 6dab96ab
      Tom Lane 提交于
      Per discussion, removing the hint seems better than correcting it because
      the adjacent analogous cases in RenameRelation don't have any hints, and
      nobody seems to have missed 'em.
      
      Shigeru Hanada
      6dab96ab
    • R
      Refactor broken CREATE TABLE IF NOT EXISTS support. · 68ef051f
      Robert Haas 提交于
      Per bug #5988, reported by Marko Tiikkaja, and further analyzed by Tom
      Lane, the previous coding was broken in several respects: even if the
      target table already existed, a subsequent CREATE TABLE IF NOT EXISTS
      might try to add additional constraints or sequences-for-serial
      specified in the new CREATE TABLE statement.
      
      In passing, this also fixes a minor information leak: it's no longer
      possible to figure out whether a schema to which you don't have CREATE
      access contains a sequence named like "x_y_seq" by attempting to create a
      table in that schema called "x" with a serial column called "y".
      
      Some more refactoring of this code in the future might be warranted,
      but that will need to wait for a later major release.
      68ef051f
  23. 23 4月, 2011 1 次提交
    • T
      Make a code-cleanup pass over the collations patch. · 9e9b9ac7
      Tom Lane 提交于
      This patch is almost entirely cosmetic --- mostly cleaning up a lot of
      neglected comments, and fixing code layout problems in places where the
      patch made lines too long and then pgindent did weird things with that.
      I did find a bug-of-omission in equalTupleDescs().
      9e9b9ac7
  24. 21 4月, 2011 3 次提交
    • R
      Allow ALTER TYPE .. ADD ATTRIBUTE .. CASCADE to recurse to descendants. · a0e8df52
      Robert Haas 提交于
      Without this, adding an attribute to a typed table with an inheritance
      child fails, which is surprising.
      
      Noah Misch, with minor changes by me.
      a0e8df52
    • R
      Typo fix. · 0babcdf6
      Robert Haas 提交于
      0babcdf6
    • R
      Allow ALTER TABLE name {OF type | NOT OF}. · 68739ba8
      Robert Haas 提交于
      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
  25. 18 4月, 2011 1 次提交
  26. 17 4月, 2011 1 次提交
    • T
      Simplify reindex_relation's API. · 2d3320d3
      Tom Lane 提交于
      For what seem entirely historical reasons, a bitmask "flags" argument was
      recently added to reindex_relation without subsuming its existing boolean
      argument into that bitmask.  This seems a bit bizarre, so fold them
      together.
      2d3320d3
  27. 14 4月, 2011 2 次提交
    • R
      Remove obsolete comment. · 0c80b57d
      Robert Haas 提交于
      The lock level for adding a parent table is now ShareUpdateExclusiveLock;
      see commit fbcf4b92.  This comment didn't
      get updated to match, but it doesn't seem important to mention this detail
      here, so rather than updating it now, just take it out.
      0c80b57d
    • R
      Fix toast table creation. · 39a68e5c
      Robert Haas 提交于
      Instead of using slightly-too-clever heuristics to decide when we must
      create a TOAST table, just check whether one is needed every time the
      table is altered.  Checking whether a toast table is needed is cheap
      enough that we needn't worry about doing it on every ALTER TABLE command,
      and the previous coding is apparently prone to accidental breakage:
      commit 04e17bae broken ALTER TABLE ..
      SET STORAGE, which moved some actions from AT_PASS_COL_ATTRS to
      AT_PASS_MISC, and commit 6c572399 broke
      ALTER TABLE .. ADD COLUMN by changing the way that adding columns
      recurses into child tables.
      
      Noah Misch, with one comment change by me
      39a68e5c
  28. 12 4月, 2011 1 次提交
  29. 10 4月, 2011 2 次提交
  30. 09 4月, 2011 1 次提交