Refactor "ALTER some-obj SET SCHEMA" implementation

Instead of having each object type implement the catalog munging
independently, centralize knowledge about how to do it and expand the
existing table in objectaddress.c with enough data about each object
type to support this operation.

Author: KaiGai Kohei
Tweaks by me
Reviewed by Robert Haas
This commit is contained in:
Alvaro Herrera 2012-09-27 18:13:09 -03:00
parent a563d94180
commit 2164f9a125
17 changed files with 321 additions and 557 deletions

View File

@ -63,7 +63,6 @@
#include "rewrite/rewriteSupport.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
@ -81,7 +80,12 @@ typedef struct
Oid class_oid; /* oid of catalog */
Oid oid_index_oid; /* oid of index on system oid column */
int oid_catcache_id; /* id of catcache on system oid column */
int name_catcache_id; /* id of catcache on (name,namespace) */
AttrNumber attnum_name; /* attnum of name field */
AttrNumber attnum_namespace; /* attnum of namespace field */
AttrNumber attnum_owner; /* attnum of owner field */
AttrNumber attnum_acl; /* attnum of acl field */
AclObjectKind acl_kind; /* ACL_KIND_* of this object type */
} ObjectPropertyType;
static ObjectPropertyType ObjectProperty[] =
@ -90,157 +94,287 @@ static ObjectPropertyType ObjectProperty[] =
CastRelationId,
CastOidIndexId,
-1,
InvalidAttrNumber
-1,
InvalidAttrNumber,
InvalidAttrNumber,
InvalidAttrNumber,
InvalidAttrNumber,
-1
},
{
CollationRelationId,
CollationOidIndexId,
COLLOID,
Anum_pg_collation_collnamespace
-1, /* COLLNAMEENCNSP also takes encoding */
Anum_pg_collation_collname,
Anum_pg_collation_collnamespace,
Anum_pg_collation_collowner,
InvalidAttrNumber,
ACL_KIND_COLLATION
},
{
ConstraintRelationId,
ConstraintOidIndexId,
CONSTROID,
Anum_pg_constraint_connamespace
-1,
Anum_pg_constraint_conname,
Anum_pg_constraint_connamespace,
InvalidAttrNumber,
InvalidAttrNumber,
-1
},
{
ConversionRelationId,
ConversionOidIndexId,
CONVOID,
Anum_pg_conversion_connamespace
CONNAMENSP,
Anum_pg_conversion_conname,
Anum_pg_conversion_connamespace,
Anum_pg_conversion_conowner,
InvalidAttrNumber,
ACL_KIND_CONVERSION
},
{
DatabaseRelationId,
DatabaseOidIndexId,
DATABASEOID,
InvalidAttrNumber
-1,
Anum_pg_database_datname,
InvalidAttrNumber,
Anum_pg_database_datdba,
Anum_pg_database_datacl,
ACL_KIND_DATABASE
},
{
ExtensionRelationId,
ExtensionOidIndexId,
-1,
InvalidAttrNumber /* extension doesn't belong to extnamespace */
-1,
Anum_pg_extension_extname,
InvalidAttrNumber, /* extension doesn't belong to extnamespace */
Anum_pg_extension_extowner,
InvalidAttrNumber,
ACL_KIND_EXTENSION
},
{
ForeignDataWrapperRelationId,
ForeignDataWrapperOidIndexId,
FOREIGNDATAWRAPPEROID,
InvalidAttrNumber
FOREIGNDATAWRAPPERNAME,
Anum_pg_foreign_data_wrapper_fdwname,
InvalidAttrNumber,
Anum_pg_foreign_data_wrapper_fdwowner,
Anum_pg_foreign_data_wrapper_fdwacl,
ACL_KIND_FDW
},
{
ForeignServerRelationId,
ForeignServerOidIndexId,
FOREIGNSERVEROID,
InvalidAttrNumber
FOREIGNSERVERNAME,
Anum_pg_foreign_server_srvname,
InvalidAttrNumber,
Anum_pg_foreign_server_srvowner,
Anum_pg_foreign_server_srvacl,
ACL_KIND_FOREIGN_SERVER
},
{
ProcedureRelationId,
ProcedureOidIndexId,
PROCOID,
Anum_pg_proc_pronamespace
-1, /* PROCNAMEARGSNSP also takes argument types */
Anum_pg_proc_proname,
Anum_pg_proc_pronamespace,
Anum_pg_proc_proowner,
Anum_pg_proc_proacl,
ACL_KIND_PROC
},
{
LanguageRelationId,
LanguageOidIndexId,
LANGOID,
LANGNAME,
Anum_pg_language_lanname,
InvalidAttrNumber,
Anum_pg_language_lanowner,
Anum_pg_language_lanacl,
ACL_KIND_LANGUAGE
},
{
LargeObjectMetadataRelationId,
LargeObjectMetadataOidIndexId,
-1,
InvalidAttrNumber
-1,
InvalidAttrNumber,
InvalidAttrNumber,
Anum_pg_largeobject_metadata_lomowner,
Anum_pg_largeobject_metadata_lomacl,
ACL_KIND_LARGEOBJECT
},
{
OperatorClassRelationId,
OpclassOidIndexId,
CLAOID,
-1, /* CLAAMNAMENSP also takes opcmethod */
Anum_pg_opclass_opcname,
Anum_pg_opclass_opcnamespace,
Anum_pg_opclass_opcowner,
InvalidAttrNumber,
ACL_KIND_OPCLASS
},
{
OperatorRelationId,
OperatorOidIndexId,
OPEROID,
Anum_pg_operator_oprnamespace
-1, /* OPERNAMENSP also takes left and right type */
Anum_pg_operator_oprname,
Anum_pg_operator_oprnamespace,
Anum_pg_operator_oprowner,
InvalidAttrNumber,
ACL_KIND_OPER
},
{
OperatorFamilyRelationId,
OpfamilyOidIndexId,
OPFAMILYOID,
Anum_pg_opfamily_opfnamespace
-1, /* OPFAMILYAMNAMENSP also takes opfmethod */
Anum_pg_opfamily_opfname,
Anum_pg_opfamily_opfnamespace,
Anum_pg_opfamily_opfowner,
InvalidAttrNumber,
ACL_KIND_OPFAMILY
},
{
AuthIdRelationId,
AuthIdOidIndexId,
AUTHOID,
InvalidAttrNumber
AUTHNAME,
Anum_pg_authid_rolname,
InvalidAttrNumber,
InvalidAttrNumber,
InvalidAttrNumber,
-1
},
{
RewriteRelationId,
RewriteOidIndexId,
-1,
InvalidAttrNumber
-1,
Anum_pg_rewrite_rulename,
InvalidAttrNumber,
InvalidAttrNumber,
InvalidAttrNumber,
-1
},
{
NamespaceRelationId,
NamespaceOidIndexId,
NAMESPACEOID,
InvalidAttrNumber
NAMESPACENAME,
Anum_pg_namespace_nspname,
InvalidAttrNumber,
Anum_pg_namespace_nspowner,
Anum_pg_namespace_nspacl,
ACL_KIND_NAMESPACE
},
{
RelationRelationId,
ClassOidIndexId,
RELOID,
Anum_pg_class_relnamespace
RELNAMENSP,
Anum_pg_class_relname,
Anum_pg_class_relnamespace,
Anum_pg_class_relowner,
Anum_pg_class_relacl,
ACL_KIND_CLASS
},
{
TableSpaceRelationId,
TablespaceOidIndexId,
TABLESPACEOID,
InvalidAttrNumber
-1,
Anum_pg_tablespace_spcname,
InvalidAttrNumber,
Anum_pg_tablespace_spcowner,
Anum_pg_tablespace_spcacl,
ACL_KIND_TABLESPACE
},
{
TriggerRelationId,
TriggerOidIndexId,
-1,
InvalidAttrNumber
-1,
Anum_pg_trigger_tgname,
InvalidAttrNumber,
InvalidAttrNumber,
InvalidAttrNumber,
-1,
},
{
EventTriggerRelationId,
EventTriggerOidIndexId,
-1,
InvalidAttrNumber
EVENTTRIGGEROID,
EVENTTRIGGERNAME,
Anum_pg_event_trigger_evtname,
InvalidAttrNumber,
Anum_pg_event_trigger_evtowner,
InvalidAttrNumber,
ACL_KIND_EVENT_TRIGGER,
},
{
TSConfigRelationId,
TSConfigOidIndexId,
TSCONFIGOID,
Anum_pg_ts_config_cfgnamespace
TSCONFIGNAMENSP,
Anum_pg_ts_config_cfgname,
Anum_pg_ts_config_cfgnamespace,
Anum_pg_ts_config_cfgowner,
InvalidAttrNumber,
ACL_KIND_TSCONFIGURATION
},
{
TSDictionaryRelationId,
TSDictionaryOidIndexId,
TSDICTOID,
Anum_pg_ts_dict_dictnamespace
TSDICTNAMENSP,
Anum_pg_ts_dict_dictname,
Anum_pg_ts_dict_dictnamespace,
Anum_pg_ts_dict_dictowner,
InvalidAttrNumber,
ACL_KIND_TSDICTIONARY
},
{
TSParserRelationId,
TSParserOidIndexId,
TSPARSEROID,
Anum_pg_ts_parser_prsnamespace
TSPARSERNAMENSP,
Anum_pg_ts_parser_prsname,
Anum_pg_ts_parser_prsnamespace,
InvalidAttrNumber,
InvalidAttrNumber,
-1,
},
{
TSTemplateRelationId,
TSTemplateOidIndexId,
TSTEMPLATEOID,
TSTEMPLATENAMENSP,
Anum_pg_ts_template_tmplname,
Anum_pg_ts_template_tmplnamespace,
InvalidAttrNumber,
InvalidAttrNumber,
-1,
},
{
TypeRelationId,
TypeOidIndexId,
TYPEOID,
Anum_pg_type_typnamespace
TYPENAMENSP,
Anum_pg_type_typname,
Anum_pg_type_typnamespace,
Anum_pg_type_typowner,
Anum_pg_type_typacl,
ACL_KIND_TYPE
}
};
@ -1132,18 +1266,98 @@ get_object_namespace(const ObjectAddress *address)
return oid;
}
/*
* Interfaces to reference fields of ObjectPropertyType
*/
Oid
get_object_oid_index(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->oid_index_oid;
}
int
get_object_catcache_oid(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->oid_catcache_id;
}
int
get_object_catcache_name(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->name_catcache_id;
}
AttrNumber
get_object_attnum_name(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->attnum_name;
}
AttrNumber
get_object_attnum_namespace(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->attnum_namespace;
}
AttrNumber
get_object_attnum_owner(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->attnum_owner;
}
AttrNumber
get_object_attnum_acl(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->attnum_acl;
}
AclObjectKind
get_object_aclkind(Oid class_id)
{
ObjectPropertyType *prop = get_object_property_data(class_id);
return prop->acl_kind;
}
/*
* Find ObjectProperty structure by class_id.
*/
static ObjectPropertyType *
get_object_property_data(Oid class_id)
{
static ObjectPropertyType *prop_last = NULL;
int index;
for (index = 0; index < lengthof(ObjectProperty); index++)
if (ObjectProperty[index].class_oid == class_id)
return &ObjectProperty[index];
/*
* A shortcut to speed up multiple consecutive lookups of a particular
* object class.
*/
if (prop_last && prop_last->class_oid == class_id)
return prop_last;
elog(ERROR, "unrecognized class id: %u", class_id);
return NULL; /* not reached */
for (index = 0; index < lengthof(ObjectProperty); index++)
{
if (ObjectProperty[index].class_oid == class_id)
{
prop_last = &ObjectProperty[index];
return &ObjectProperty[index];
}
}
ereport(ERROR,
(errmsg_internal("unrecognized class id: %u", class_id)));
}

View File

@ -173,10 +173,6 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
AlterCollationNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_CONVERSION:
AlterConversionNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_EXTENSION:
AlterExtensionNamespace(stmt->object, stmt->newschema);
break;
@ -186,18 +182,6 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
stmt->newschema);
break;
case OBJECT_OPERATOR:
AlterOperatorNamespace(stmt->object, stmt->objarg, stmt->newschema);
break;
case OBJECT_OPCLASS:
AlterOpClassNamespace(stmt->object, stmt->addname, stmt->newschema);
break;
case OBJECT_OPFAMILY:
AlterOpFamilyNamespace(stmt->object, stmt->addname, stmt->newschema);
break;
case OBJECT_SEQUENCE:
case OBJECT_TABLE:
case OBJECT_VIEW:
@ -205,27 +189,44 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
AlterTableNamespace(stmt);
break;
case OBJECT_TSPARSER:
AlterTSParserNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_TSDICTIONARY:
AlterTSDictionaryNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_TSTEMPLATE:
AlterTSTemplateNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_TSCONFIGURATION:
AlterTSConfigurationNamespace(stmt->object, stmt->newschema);
break;
case OBJECT_TYPE:
case OBJECT_DOMAIN:
AlterTypeNamespace(stmt->object, stmt->newschema, stmt->objectType);
break;
/* generic code path */
case OBJECT_CONVERSION:
case OBJECT_OPERATOR:
case OBJECT_OPCLASS:
case OBJECT_OPFAMILY:
case OBJECT_TSPARSER:
case OBJECT_TSDICTIONARY:
case OBJECT_TSTEMPLATE:
case OBJECT_TSCONFIGURATION:
{
Relation catalog;
Relation relation;
Oid classId;
Oid nspOid;
ObjectAddress address;
address = get_object_address(stmt->objectType,
stmt->object,
stmt->objarg,
&relation,
AccessExclusiveLock,
false);
Assert(relation == NULL);
classId = address.classId;
catalog = heap_open(classId, RowExclusiveLock);
nspOid = LookupCreationNamespace(stmt->newschema);
AlterObjectNamespace_internal(catalog, address.objectId,
nspOid);
heap_close(catalog, RowExclusiveLock);
}
break;
default:
elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
(int) stmt->objectType);
@ -293,35 +294,23 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid)
break;
case OCLASS_CONVERSION:
oldNspOid = AlterConversionNamespace_oid(objid, nspOid);
break;
case OCLASS_OPERATOR:
oldNspOid = AlterOperatorNamespace_oid(objid, nspOid);
break;
case OCLASS_OPCLASS:
oldNspOid = AlterOpClassNamespace_oid(objid, nspOid);
break;
case OCLASS_OPFAMILY:
oldNspOid = AlterOpFamilyNamespace_oid(objid, nspOid);
break;
case OCLASS_TSPARSER:
oldNspOid = AlterTSParserNamespace_oid(objid, nspOid);
break;
case OCLASS_TSDICT:
oldNspOid = AlterTSDictionaryNamespace_oid(objid, nspOid);
break;
case OCLASS_TSTEMPLATE:
oldNspOid = AlterTSTemplateNamespace_oid(objid, nspOid);
break;
case OCLASS_TSCONFIG:
oldNspOid = AlterTSConfigurationNamespace_oid(objid, nspOid);
{
Relation catalog;
catalog = heap_open(classId, RowExclusiveLock);
oldNspOid = AlterObjectNamespace_internal(catalog, objid,
nspOid);
heap_close(catalog, RowExclusiveLock);
}
break;
default:
@ -336,32 +325,22 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid)
* cases (won't work for tables, nor other cases where we need to do more
* than change the namespace column of a single catalog entry).
*
* The AlterFooNamespace() calls just above will call a function whose job
* is to lookup the arguments for the generic function here.
*
* rel: catalog relation containing object (RowExclusiveLock'd by caller)
* oidCacheId: syscache that indexes this catalog by OID
* nameCacheId: syscache that indexes this catalog by name and namespace
* (pass -1 if there is none)
* objid: OID of object to change the namespace of
* nspOid: OID of new namespace
* Anum_name: column number of catalog's name column
* Anum_namespace: column number of catalog's namespace column
* Anum_owner: column number of catalog's owner column, or -1 if none
* acl_kind: ACL type for object, or -1 if none assigned
*
* If the object does not have an owner or permissions, pass -1 for
* Anum_owner and acl_kind. In this case the calling user must be superuser.
*
* Returns the OID of the object's previous namespace.
*/
Oid
AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId,
Oid objid, Oid nspOid,
int Anum_name, int Anum_namespace, int Anum_owner,
AclObjectKind acl_kind)
AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
{
Oid classId = RelationGetRelid(rel);
int oidCacheId = get_object_catcache_oid(classId);
int nameCacheId = get_object_catcache_name(classId);
AttrNumber Anum_name = get_object_attnum_name(classId);
AttrNumber Anum_namespace = get_object_attnum_namespace(classId);
AttrNumber Anum_owner = get_object_attnum_owner(classId);
AclObjectKind acl_kind = get_object_aclkind(classId);
Oid oldNspOid;
Datum name,
namespace;
@ -379,7 +358,8 @@ AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId,
name = heap_getattr(tup, Anum_name, RelationGetDescr(rel), &isnull);
Assert(!isnull);
namespace = heap_getattr(tup, Anum_namespace, RelationGetDescr(rel), &isnull);
namespace = heap_getattr(tup, Anum_namespace, RelationGetDescr(rel),
&isnull);
Assert(!isnull);
oldNspOid = DatumGetObjectId(namespace);

View File

@ -339,7 +339,7 @@ AlterCollationNamespace_oid(Oid collOid, Oid newNspOid)
/*
* We have to check for name collision ourselves, because
* AlterObjectNamespace doesn't know how to deal with the encoding
* AlterObjectNamespace_internal doesn't know how to deal with the encoding
* considerations.
*/
collation_name = get_collation_name(collOid);
@ -370,12 +370,7 @@ AlterCollationNamespace_oid(Oid collOid, Oid newNspOid)
get_namespace_name(newNspOid))));
/* OK, do the work */
oldNspOid = AlterObjectNamespace(rel, COLLOID, -1,
collOid, newNspOid,
Anum_pg_collation_collname,
Anum_pg_collation_collnamespace,
Anum_pg_collation_collowner,
ACL_KIND_COLLATION);
oldNspOid = AlterObjectNamespace_internal(rel, collOid, newNspOid);
heap_close(rel, RowExclusiveLock);

View File

@ -266,53 +266,3 @@ AlterConversionOwner_internal(Relation rel, Oid conversionOid, Oid newOwnerId)
heap_freetuple(tup);
}
/*
* Execute ALTER CONVERSION SET SCHEMA
*/
void
AlterConversionNamespace(List *name, const char *newschema)
{
Oid convOid,
nspOid;
Relation rel;
rel = heap_open(ConversionRelationId, RowExclusiveLock);
convOid = get_conversion_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, CONVOID, CONNAMENSP,
convOid, nspOid,
Anum_pg_conversion_conname,
Anum_pg_conversion_connamespace,
Anum_pg_conversion_conowner,
ACL_KIND_CONVERSION);
heap_close(rel, RowExclusiveLock);
}
/*
* Change conversion schema, by oid
*/
Oid
AlterConversionNamespace_oid(Oid convOid, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(ConversionRelationId, RowExclusiveLock);
oldNspOid = AlterObjectNamespace(rel, CONVOID, CONNAMENSP,
convOid, newNspOid,
Anum_pg_conversion_conname,
Anum_pg_conversion_connamespace,
Anum_pg_conversion_conowner,
ACL_KIND_CONVERSION);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}

View File

@ -26,7 +26,6 @@
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/syscache.h"

View File

@ -47,6 +47,7 @@
#include "catalog/pg_proc_fn.h"
#include "catalog/pg_type.h"
#include "catalog/pg_type_fn.h"
#include "commands/alter.h"
#include "commands/defrem.h"
#include "commands/proclang.h"
#include "miscadmin.h"
@ -1851,21 +1852,16 @@ AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
procRel = heap_open(ProcedureRelationId, RowExclusiveLock);
/*
* We have to check for name collisions ourselves, because
* AlterObjectNamespace_internal doesn't know how to deal with the
* argument types.
*/
tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for function %u", procOid);
proc = (Form_pg_proc) GETSTRUCT(tup);
/* check permissions on function */
if (!pg_proc_ownercheck(procOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
NameStr(proc->proname));
oldNspOid = proc->pronamespace;
/* common checks on switching namespaces */
CheckSetNamespace(oldNspOid, nspOid, ProcedureRelationId, procOid);
/* check for duplicate name (more friendly than unique-index failure) */
if (SearchSysCacheExists3(PROCNAMEARGSNSP,
CStringGetDatum(NameStr(proc->proname)),
@ -1877,21 +1873,8 @@ AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
NameStr(proc->proname),
get_namespace_name(nspOid))));
/* OK, modify the pg_proc row */
/* tup is a copy, so we can scribble directly on it */
proc->pronamespace = nspOid;
simple_heap_update(procRel, &tup->t_self, tup);
CatalogUpdateIndexes(procRel, tup);
/* Update dependency on schema */
if (changeDependencyFor(ProcedureRelationId, procOid,
NamespaceRelationId, oldNspOid, nspOid) != 1)
elog(ERROR, "failed to change schema dependency for function \"%s\"",
NameStr(proc->proname));
heap_freetuple(tup);
/* OK, do the work */
oldNspOid = AlterObjectNamespace_internal(procRel, procOid, nspOid);
heap_close(procRel, RowExclusiveLock);

View File

@ -1914,58 +1914,6 @@ AlterOpClassOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
}
}
/*
* ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
*/
void
AlterOpClassNamespace(List *name, char *access_method, const char *newschema)
{
Oid amOid;
Relation rel;
Oid opclassOid;
Oid nspOid;
amOid = get_am_oid(access_method, false);
rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
/* Look up the opclass */
opclassOid = get_opclass_oid(amOid, name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, CLAOID, -1,
opclassOid, nspOid,
Anum_pg_opclass_opcname,
Anum_pg_opclass_opcnamespace,
Anum_pg_opclass_opcowner,
ACL_KIND_OPCLASS);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterOpClassNamespace_oid(Oid opclassOid, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, CLAOID, -1,
opclassOid, newNspOid,
Anum_pg_opclass_opcname,
Anum_pg_opclass_opcnamespace,
Anum_pg_opclass_opcowner,
ACL_KIND_OPCLASS);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Change opfamily owner by name
*/
@ -2122,55 +2070,3 @@ get_am_oid(const char *amname, bool missing_ok)
errmsg("access method \"%s\" does not exist", amname)));
return oid;
}
/*
* ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
*/
void
AlterOpFamilyNamespace(List *name, char *access_method, const char *newschema)
{
Oid amOid;
Relation rel;
Oid opfamilyOid;
Oid nspOid;
amOid = get_am_oid(access_method, false);
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
/* Look up the opfamily */
opfamilyOid = get_opfamily_oid(amOid, name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, OPFAMILYOID, -1,
opfamilyOid, nspOid,
Anum_pg_opfamily_opfname,
Anum_pg_opfamily_opfnamespace,
Anum_pg_opfamily_opfowner,
ACL_KIND_OPFAMILY);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterOpFamilyNamespace_oid(Oid opfamilyOid, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, OPFAMILYOID, -1,
opfamilyOid, newNspOid,
Anum_pg_opfamily_opfname,
Anum_pg_opfamily_opfnamespace,
Anum_pg_opfamily_opfowner,
ACL_KIND_OPFAMILY);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}

View File

@ -423,56 +423,3 @@ AlterOperatorOwner_internal(Relation rel, Oid operOid, Oid newOwnerId)
heap_freetuple(tup);
}
/*
* Execute ALTER OPERATOR SET SCHEMA
*/
void
AlterOperatorNamespace(List *names, List *argtypes, const char *newschema)
{
List *operatorName = names;
TypeName *typeName1 = (TypeName *) linitial(argtypes);
TypeName *typeName2 = (TypeName *) lsecond(argtypes);
Oid operOid,
nspOid;
Relation rel;
rel = heap_open(OperatorRelationId, RowExclusiveLock);
Assert(list_length(argtypes) == 2);
operOid = LookupOperNameTypeNames(NULL, operatorName,
typeName1, typeName2,
false, -1);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, OPEROID, -1,
operOid, nspOid,
Anum_pg_operator_oprname,
Anum_pg_operator_oprnamespace,
Anum_pg_operator_oprowner,
ACL_KIND_OPER);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterOperatorNamespace_oid(Oid operOid, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(OperatorRelationId, RowExclusiveLock);
oldNspOid = AlterObjectNamespace(rel, OPEROID, -1,
operOid, newNspOid,
Anum_pg_operator_oprname,
Anum_pg_operator_oprnamespace,
Anum_pg_operator_oprowner,
ACL_KIND_OPER);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}

View File

@ -346,52 +346,6 @@ RenameTSParser(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH PARSER any_name SET SCHEMA name
*/
void
AlterTSParserNamespace(List *name, const char *newschema)
{
Oid prsId,
nspOid;
Relation rel;
rel = heap_open(TSParserRelationId, RowExclusiveLock);
prsId = get_ts_parser_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSPARSEROID, TSPARSERNAMENSP,
prsId, nspOid,
Anum_pg_ts_parser_prsname,
Anum_pg_ts_parser_prsnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSParserNamespace_oid(Oid prsId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSParserRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSPARSEROID, TSPARSERNAMENSP,
prsId, newNspOid,
Anum_pg_ts_parser_prsname,
Anum_pg_ts_parser_prsnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/* ---------------------- TS Dictionary commands -----------------------*/
/*
@ -625,54 +579,6 @@ RenameTSDictionary(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH DICTIONARY any_name SET SCHEMA name
*/
void
AlterTSDictionaryNamespace(List *name, const char *newschema)
{
Oid dictId,
nspOid;
Relation rel;
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
dictId = get_ts_dict_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSDICTOID, TSDICTNAMENSP,
dictId, nspOid,
Anum_pg_ts_dict_dictname,
Anum_pg_ts_dict_dictnamespace,
Anum_pg_ts_dict_dictowner,
ACL_KIND_TSDICTIONARY);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSDictionaryNamespace_oid(Oid dictId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSDICTOID, TSDICTNAMENSP,
dictId, newNspOid,
Anum_pg_ts_dict_dictname,
Anum_pg_ts_dict_dictnamespace,
Anum_pg_ts_dict_dictowner,
ACL_KIND_TSDICTIONARY);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS dictionary deletion.
*/
@ -1090,52 +996,6 @@ RenameTSTemplate(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH TEMPLATE any_name SET SCHEMA name
*/
void
AlterTSTemplateNamespace(List *name, const char *newschema)
{
Oid tmplId,
nspOid;
Relation rel;
rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
tmplId = get_ts_template_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSTEMPLATEOID, TSTEMPLATENAMENSP,
tmplId, nspOid,
Anum_pg_ts_template_tmplname,
Anum_pg_ts_template_tmplnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSTemplateNamespace_oid(Oid tmplId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSTEMPLATEOID, TSTEMPLATENAMENSP,
tmplId, newNspOid,
Anum_pg_ts_template_tmplname,
Anum_pg_ts_template_tmplnamespace,
-1, -1);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS template deletion.
*/
@ -1482,54 +1342,6 @@ RenameTSConfiguration(List *oldname, const char *newname)
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH CONFIGURATION any_name SET SCHEMA name
*/
void
AlterTSConfigurationNamespace(List *name, const char *newschema)
{
Oid cfgId,
nspOid;
Relation rel;
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
cfgId = get_ts_config_oid(name, false);
/* get schema OID */
nspOid = LookupCreationNamespace(newschema);
AlterObjectNamespace(rel, TSCONFIGOID, TSCONFIGNAMENSP,
cfgId, nspOid,
Anum_pg_ts_config_cfgname,
Anum_pg_ts_config_cfgnamespace,
Anum_pg_ts_config_cfgowner,
ACL_KIND_TSCONFIGURATION);
heap_close(rel, RowExclusiveLock);
}
Oid
AlterTSConfigurationNamespace_oid(Oid cfgId, Oid newNspOid)
{
Oid oldNspOid;
Relation rel;
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
oldNspOid =
AlterObjectNamespace(rel, TSCONFIGOID, TSCONFIGNAMENSP,
cfgId, newNspOid,
Anum_pg_ts_config_cfgname,
Anum_pg_ts_config_cfgnamespace,
Anum_pg_ts_config_cfgowner,
ACL_KIND_TSCONFIGURATION);
heap_close(rel, RowExclusiveLock);
return oldNspOid;
}
/*
* Guts of TS configuration deletion.
*/

View File

@ -2932,7 +2932,6 @@ _copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt *from)
COPY_NODE_FIELD(relation);
COPY_NODE_FIELD(object);
COPY_NODE_FIELD(objarg);
COPY_STRING_FIELD(addname);
COPY_STRING_FIELD(newschema);
COPY_SCALAR_FIELD(missing_ok);

View File

@ -1336,7 +1336,6 @@ _equalAlterObjectSchemaStmt(const AlterObjectSchemaStmt *a, const AlterObjectSch
COMPARE_NODE_FIELD(relation);
COMPARE_NODE_FIELD(object);
COMPARE_NODE_FIELD(objarg);
COMPARE_STRING_FIELD(addname);
COMPARE_STRING_FIELD(newschema);
COMPARE_SCALAR_FIELD(missing_ok);

View File

@ -7146,7 +7146,7 @@ AlterObjectSchemaStmt:
AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
n->objectType = OBJECT_OPCLASS;
n->object = $4;
n->addname = $6;
n->objarg = list_make1(makeString($6));
n->newschema = $9;
n->missing_ok = false;
$$ = (Node *)n;
@ -7156,7 +7156,7 @@ AlterObjectSchemaStmt:
AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
n->objectType = OBJECT_OPFAMILY;
n->object = $4;
n->addname = $6;
n->objarg = list_make1(makeString($6));
n->newschema = $9;
n->missing_ok = false;
$$ = (Node *)n;

View File

@ -13,8 +13,9 @@
#ifndef OBJECTADDRESS_H
#define OBJECTADDRESS_H
#include "nodes/parsenodes.h"
#include "nodes/pg_list.h"
#include "storage/lock.h"
#include "utils/acl.h"
#include "utils/relcache.h"
/*
@ -37,4 +38,13 @@ extern void check_object_ownership(Oid roleid,
extern Oid get_object_namespace(const ObjectAddress *address);
extern Oid get_object_oid_index(Oid class_id);
extern int get_object_catcache_oid(Oid class_id);
extern int get_object_catcache_name(Oid class_id);
extern AttrNumber get_object_attnum_name(Oid class_id);
extern AttrNumber get_object_attnum_namespace(Oid class_id);
extern AttrNumber get_object_attnum_owner(Oid class_id);
extern AttrNumber get_object_attnum_acl(Oid class_id);
extern AclObjectKind get_object_aclkind(Oid class_id);
#endif /* PARSE_OBJECT_H */

View File

@ -14,16 +14,13 @@
#ifndef ALTER_H
#define ALTER_H
#include "utils/acl.h"
#include "nodes/parsenodes.h"
#include "utils/relcache.h"
extern void ExecRenameStmt(RenameStmt *stmt);
extern void ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid);
extern Oid AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId,
Oid objid, Oid nspOid,
int Anum_name, int Anum_namespace, int Anum_owner,
AclObjectKind acl_kind);
extern Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid);
extern void ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
#endif /* ALTER_H */

View File

@ -21,7 +21,5 @@ extern void CreateConversionCommand(CreateConversionStmt *parsetree);
extern void RenameConversion(List *name, const char *newname);
extern void AlterConversionOwner(List *name, Oid newOwnerId);
extern void AlterConversionOwner_oid(Oid conversionOid, Oid newOwnerId);
extern void AlterConversionNamespace(List *name, const char *newschema);
extern Oid AlterConversionNamespace_oid(Oid convOid, Oid newNspOid);
#endif /* CONVERSIONCMDS_H */

View File

@ -64,8 +64,6 @@ extern void RemoveOperatorById(Oid operOid);
extern void AlterOperatorOwner(List *name, TypeName *typeName1,
TypeName *typename2, Oid newOwnerId);
extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId);
extern void AlterOperatorNamespace(List *names, List *argtypes, const char *newschema);
extern Oid AlterOperatorNamespace_oid(Oid operOid, Oid newNspOid);
/* commands/aggregatecmds.c */
extern void DefineAggregate(List *name, List *args, bool oldstyle,
@ -85,12 +83,8 @@ extern void RenameOpClass(List *name, const char *access_method, const char *new
extern void RenameOpFamily(List *name, const char *access_method, const char *newname);
extern void AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId);
extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId);
extern void AlterOpClassNamespace(List *name, char *access_method, const char *newschema);
extern Oid AlterOpClassNamespace_oid(Oid opclassOid, Oid newNspOid);
extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId);
extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId);
extern void AlterOpFamilyNamespace(List *name, char *access_method, const char *newschema);
extern Oid AlterOpFamilyNamespace_oid(Oid opfamilyOid, Oid newNspOid);
extern Oid get_am_oid(const char *amname, bool missing_ok);
extern Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok);
extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
@ -98,8 +92,6 @@ extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
/* commands/tsearchcmds.c */
extern void DefineTSParser(List *names, List *parameters);
extern void RenameTSParser(List *oldname, const char *newname);
extern void AlterTSParserNamespace(List *name, const char *newschema);
extern Oid AlterTSParserNamespace_oid(Oid prsId, Oid newNspOid);
extern void RemoveTSParserById(Oid prsId);
extern void DefineTSDictionary(List *names, List *parameters);
@ -107,13 +99,9 @@ extern void RenameTSDictionary(List *oldname, const char *newname);
extern void RemoveTSDictionaryById(Oid dictId);
extern void AlterTSDictionary(AlterTSDictionaryStmt *stmt);
extern void AlterTSDictionaryOwner(List *name, Oid newOwnerId);
extern void AlterTSDictionaryNamespace(List *name, const char *newschema);
extern Oid AlterTSDictionaryNamespace_oid(Oid dictId, Oid newNspOid);
extern void DefineTSTemplate(List *names, List *parameters);
extern void RenameTSTemplate(List *oldname, const char *newname);
extern void AlterTSTemplateNamespace(List *name, const char *newschema);
extern Oid AlterTSTemplateNamespace_oid(Oid tmplId, Oid newNspOid);
extern void RemoveTSTemplateById(Oid tmplId);
extern void DefineTSConfiguration(List *names, List *parameters);
@ -121,8 +109,6 @@ extern void RenameTSConfiguration(List *oldname, const char *newname);
extern void RemoveTSConfigurationById(Oid cfgId);
extern void AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
extern void AlterTSConfigurationOwner(List *name, Oid newOwnerId);
extern void AlterTSConfigurationNamespace(List *name, const char *newschema);
extern Oid AlterTSConfigurationNamespace_oid(Oid cfgId, Oid newNspOid);
extern text *serialize_deflist(List *deflist);
extern List *deserialize_deflist(Datum txt);

View File

@ -2168,7 +2168,6 @@ typedef struct AlterObjectSchemaStmt
RangeVar *relation; /* in case it's a table */
List *object; /* in case it's some other object */
List *objarg; /* argument types, if applicable */
char *addname; /* additional name if needed */
char *newschema; /* the new schema */
bool missing_ok; /* skip error if missing? */
} AlterObjectSchemaStmt;