diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2015-03-03 14:10:50 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2015-03-03 14:10:50 -0300 |
commit | a2e35b53c39b2a27d3e332dc7c506539c306fd44 (patch) | |
tree | 1f4cd33208d33f4a8b3159b0d3757109c67d4b14 /src/backend/commands/view.c | |
parent | 6f9d79904748c26a58991942dc6719db558f77b0 (diff) | |
download | postgresql-a2e35b53c39b2a27d3e332dc7c506539c306fd44.tar.gz postgresql-a2e35b53c39b2a27d3e332dc7c506539c306fd44.zip |
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
Diffstat (limited to 'src/backend/commands/view.c')
-rw-r--r-- | src/backend/commands/view.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index 7358723bded..6f2a749756c 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -65,7 +65,7 @@ validateWithCheckOption(char *value) * work harder. *--------------------------------------------------------------------- */ -static Oid +static ObjectAddress DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, List *options) { @@ -143,6 +143,7 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, TupleDesc descriptor; List *atcmds = NIL; AlterTableCmd *atcmd; + ObjectAddress address; /* Relation is already locked, but we must build a relcache entry. */ rel = relation_open(viewOid, NoLock); @@ -208,16 +209,18 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, /* OK, let's do it. */ AlterTableInternal(viewOid, atcmds, true); + ObjectAddressSet(address, RelationRelationId, viewOid); + /* * Seems okay, so return the OID of the pre-existing view. */ relation_close(rel, NoLock); /* keep the lock! */ - return viewOid; + return address; } else { - Oid relid; + ObjectAddress address; /* * now set the parameters for keys/inheritance etc. All of these are @@ -237,9 +240,9 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, * existing view, so we don't need more code to complain if "replace" * is false). */ - relid = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid); - Assert(relid != InvalidOid); - return relid; + address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL); + Assert(address.objectId != InvalidOid); + return address; } } @@ -388,14 +391,14 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) * DefineView * Execute a CREATE VIEW command. */ -Oid +ObjectAddress DefineView(ViewStmt *stmt, const char *queryString) { Query *viewParse; - Oid viewOid; RangeVar *view; ListCell *cell; bool check_option; + ObjectAddress address; /* * Run parse analysis to convert the raw parse tree to a Query. Note this @@ -533,7 +536,7 @@ DefineView(ViewStmt *stmt, const char *queryString) * NOTE: if it already exists and replace is false, the xact will be * aborted. */ - viewOid = DefineVirtualRelation(view, viewParse->targetList, + address = DefineVirtualRelation(view, viewParse->targetList, stmt->replace, stmt->options); /* @@ -543,9 +546,9 @@ DefineView(ViewStmt *stmt, const char *queryString) */ CommandCounterIncrement(); - StoreViewQuery(viewOid, viewParse, stmt->replace); + StoreViewQuery(address.objectId, viewParse, stmt->replace); - return viewOid; + return address; } /* |