diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2009-01-12 08:54:27 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2009-01-12 08:54:27 +0000 |
commit | ca8100f9eb7f02f410d1a45f2d5fee8373eace84 (patch) | |
tree | a0c0a386c23b028fc3b704f9fc0ee1da5c19349c /src/backend/commands/tablecmds.c | |
parent | b7b8f0b6096d2ab6e4f67980d19e478cf6fab629 (diff) |
Add ONLY support to LOCK and TRUNCATE. By default, these commands are now
recursive.
=> Note this incompatibility in the release notes.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f932b65e1f4..061d45c30ac 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.276 2009/01/01 17:23:39 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.277 2009/01/12 08:54:26 petere Exp $ * *------------------------------------------------------------------------- */ @@ -772,17 +772,41 @@ ExecuteTruncate(TruncateStmt *stmt) { RangeVar *rv = lfirst(cell); Relation rel; + bool recurse = interpretInhOption(rv->inhOpt); + Oid myrelid; rel = heap_openrv(rv, AccessExclusiveLock); + myrelid = RelationGetRelid(rel); /* don't throw error for "TRUNCATE foo, foo" */ - if (list_member_oid(relids, RelationGetRelid(rel))) + if (list_member_oid(relids, myrelid)) { heap_close(rel, AccessExclusiveLock); continue; } truncate_check_rel(rel); rels = lappend(rels, rel); - relids = lappend_oid(relids, RelationGetRelid(rel)); + relids = lappend_oid(relids, myrelid); + + if (recurse) + { + ListCell *child; + List *children; + + children = find_all_inheritors(myrelid); + + foreach(child, children) + { + Oid childrelid = lfirst_oid(child); + + if (list_member_oid(relids, childrelid)) + continue; + + rel = heap_open(childrelid, AccessExclusiveLock); + truncate_check_rel(rel); + rels = lappend(rels, rel); + relids = lappend_oid(relids, childrelid); + } + } } /* |