diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c index e2aef05c0ff..5bec1380e6b 100644 --- a/src/backend/catalog/pg_shdepend.c +++ b/src/backend/catalog/pg_shdepend.c @@ -31,6 +31,8 @@ #include "catalog/pg_proc.h" #include "catalog/pg_shdepend.h" #include "catalog/pg_tablespace.h" +#include "catalog/pg_ts_config.h" +#include "catalog/pg_ts_dict.h" #include "catalog/pg_type.h" #include "commands/conversioncmds.h" #include "commands/defrem.h" @@ -1381,6 +1383,14 @@ shdepReassignOwned(List *roleids, Oid newrole) AlterOpFamilyOwner_oid(sdepForm->objid, newrole); break; + case TSConfigRelationId: + AlterTSConfigurationOwner_oid(sdepForm->objid, newrole); + break; + + case TSDictionaryRelationId: + AlterTSDictionaryOwner_oid(sdepForm->objid, newrole); + break; + default: elog(ERROR, "unexpected classid %d", sdepForm->classid); break; diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c index 5339e1783c4..fd39191a592 100644 --- a/src/backend/commands/tsearchcmds.c +++ b/src/backend/commands/tsearchcmds.c @@ -843,22 +843,16 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt) } /* - * ALTER TEXT SEARCH DICTIONARY OWNER + * Internal routine for changing the owner of a text search dictionary */ -void -AlterTSDictionaryOwner(List *name, Oid newOwnerId) +static void +AlterTSDictionaryOwner_internal(Relation rel, Oid dictId, Oid newOwnerId) { HeapTuple tup; - Relation rel; - Oid dictId; Oid namespaceOid; AclResult aclresult; Form_pg_ts_dict form; - rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); - - dictId = TSDictionaryGetDictid(name, false); - tup = SearchSysCacheCopy(TSDICTOID, ObjectIdGetDatum(dictId), 0, 0, 0); @@ -878,7 +872,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId) /* must be owner */ if (!pg_ts_dict_ownercheck(dictId, GetUserId())) aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY, - NameListToString(name)); + NameStr(form->dictname)); /* Must be able to become new owner */ check_is_member_of_role(GetUserId(), newOwnerId); @@ -900,10 +894,41 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId) newOwnerId); } - heap_close(rel, NoLock); heap_freetuple(tup); } +/* + * ALTER TEXT SEARCH DICTIONARY OWNER + */ +void +AlterTSDictionaryOwner(List *name, Oid newOwnerId) +{ + Relation rel; + Oid dictId; + + rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); + dictId = TSDictionaryGetDictid(name, false); + + AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId); + + heap_close(rel, NoLock); +} + +/* + * Change text search dictionary owner, by OID + */ +void +AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId) +{ + Relation rel; + + rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); + + AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId); + + heap_close(rel, NoLock); +} + /* ---------------------- TS Template commands -----------------------*/ /* @@ -1644,22 +1669,16 @@ RemoveTSConfigurationById(Oid cfgId) } /* - * ALTER TEXT SEARCH CONFIGURATION OWNER + * Internal routine for changing the owner of a text search configuration */ -void -AlterTSConfigurationOwner(List *name, Oid newOwnerId) +static void +AlterTSConfigurationOwner_internal(Relation rel, Oid cfgId, Oid newOwnerId) { HeapTuple tup; - Relation rel; - Oid cfgId; AclResult aclresult; Oid namespaceOid; Form_pg_ts_config form; - rel = heap_open(TSConfigRelationId, RowExclusiveLock); - - cfgId = TSConfigGetCfgid(name, false); - tup = SearchSysCacheCopy(TSCONFIGOID, ObjectIdGetDatum(cfgId), 0, 0, 0); @@ -1679,7 +1698,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId) /* must be owner */ if (!pg_ts_config_ownercheck(cfgId, GetUserId())) aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION, - NameListToString(name)); + NameStr(form->cfgname)); /* Must be able to become new owner */ check_is_member_of_role(GetUserId(), newOwnerId); @@ -1701,10 +1720,39 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId) newOwnerId); } - heap_close(rel, NoLock); heap_freetuple(tup); } +/* + * ALTER TEXT SEARCH CONFIGURATION OWNER + */ +void +AlterTSConfigurationOwner(List *name, Oid newOwnerId) +{ + Relation rel; + Oid cfgId; + + rel = heap_open(TSConfigRelationId, RowExclusiveLock); + cfgId = TSConfigGetCfgid(name, false); + + AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId); + + heap_close(rel, NoLock); +} + +void +AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId) +{ + Relation rel; + + rel = heap_open(TSConfigRelationId, RowExclusiveLock); + + AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId); + + heap_close(rel, NoLock); +} + + /* * ALTER TEXT SEARCH CONFIGURATION - main entry point */ diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index 9b7936d1d90..85b98b7294f 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -104,6 +104,7 @@ extern void RemoveTSDictionaries(DropStmt *drop); extern void RemoveTSDictionaryById(Oid dictId); extern void AlterTSDictionary(AlterTSDictionaryStmt *stmt); extern void AlterTSDictionaryOwner(List *name, Oid newOwnerId); +extern void AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId); extern void DefineTSTemplate(List *names, List *parameters); extern void RenameTSTemplate(List *oldname, const char *newname); @@ -116,6 +117,7 @@ extern void RemoveTSConfigurations(DropStmt *stmt); extern void RemoveTSConfigurationById(Oid cfgId); extern void AlterTSConfiguration(AlterTSConfigurationStmt *stmt); extern void AlterTSConfigurationOwner(List *name, Oid newOwnerId); +extern void AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId); extern text *serialize_deflist(List *deflist); extern List *deserialize_deflist(Datum txt);