Skip to content

Commit 765cbfd

Browse files
committed
Refactor ALTER some-obj RENAME implementation
Remove duplicate implementations of catalog munging and miscellaneous privilege checks. Instead rely on already existing data in objectaddress.c to do the work. Author: KaiGai Kohei, changes by me Reviewed by: Robert Haas, Álvaro Herrera, Dimitri Fontaine
1 parent 8f0d8f4 commit 765cbfd

19 files changed

+348
-851
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ typedef struct
8080
Oid class_oid; /* oid of catalog */
8181
Oid oid_index_oid; /* oid of index on system oid column */
8282
int oid_catcache_id; /* id of catcache on system oid column */
83-
int name_catcache_id; /* id of catcache on (name,namespace) */
83+
int name_catcache_id; /* id of catcache on (name,namespace),
84+
* or (name) if the object does not
85+
* live in a namespace */
8486
AttrNumber attnum_name; /* attnum of name field */
8587
AttrNumber attnum_namespace; /* attnum of namespace field */
8688
AttrNumber attnum_owner; /* attnum of owner field */

src/backend/commands/aggregatecmds.c

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -226,66 +226,3 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
226226
transTypeId, /* transition data type */
227227
initval); /* initial condition */
228228
}
229-
230-
231-
/*
232-
* RenameAggregate
233-
* Rename an aggregate.
234-
*/
235-
Oid
236-
RenameAggregate(List *name, List *args, const char *newname)
237-
{
238-
Oid procOid;
239-
Oid namespaceOid;
240-
HeapTuple tup;
241-
Form_pg_proc procForm;
242-
Relation rel;
243-
AclResult aclresult;
244-
245-
rel = heap_open(ProcedureRelationId, RowExclusiveLock);
246-
247-
/* Look up function and make sure it's an aggregate */
248-
procOid = LookupAggNameTypeNames(name, args, false);
249-
250-
tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
251-
if (!HeapTupleIsValid(tup)) /* should not happen */
252-
elog(ERROR, "cache lookup failed for function %u", procOid);
253-
procForm = (Form_pg_proc) GETSTRUCT(tup);
254-
255-
namespaceOid = procForm->pronamespace;
256-
257-
/* make sure the new name doesn't exist */
258-
if (SearchSysCacheExists3(PROCNAMEARGSNSP,
259-
CStringGetDatum(newname),
260-
PointerGetDatum(&procForm->proargtypes),
261-
ObjectIdGetDatum(namespaceOid)))
262-
ereport(ERROR,
263-
(errcode(ERRCODE_DUPLICATE_FUNCTION),
264-
errmsg("function %s already exists in schema \"%s\"",
265-
funcname_signature_string(newname,
266-
procForm->pronargs,
267-
NIL,
268-
procForm->proargtypes.values),
269-
get_namespace_name(namespaceOid))));
270-
271-
/* must be owner */
272-
if (!pg_proc_ownercheck(procOid, GetUserId()))
273-
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
274-
NameListToString(name));
275-
276-
/* must have CREATE privilege on namespace */
277-
aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
278-
if (aclresult != ACLCHECK_OK)
279-
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
280-
get_namespace_name(namespaceOid));
281-
282-
/* rename */
283-
namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
284-
simple_heap_update(rel, &tup->t_self, tup);
285-
CatalogUpdateIndexes(rel, tup);
286-
287-
heap_close(rel, NoLock);
288-
heap_freetuple(tup);
289-
290-
return procOid;
291-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy