Fix OwnerName function to work with schemas

We incorrectly try to use relation cache to find particular schema's owner and
when we cannot find the schema in the relation cache(i.e always), we automatically
used current user as the schema's owner. This means we always created schemas in
the data nodes with current user. With this patch we started to use namespace
cache to find schemas.
pull/1412/head
Burak Yucesoy 2017-05-15 02:52:39 +03:00
parent a7c65a3ed8
commit 1b5560b2f7
1 changed files with 8 additions and 6 deletions

View File

@ -53,7 +53,7 @@ static List * SequenceDDLCommandsForTable(Oid relationId);
static void EnsureSupportedSequenceColumnType(Oid sequenceOid);
static Oid TypeOfColumn(Oid tableId, int16 columnId);
static char * TruncateTriggerCreateCommand(Oid relationId);
static char * OwnerName(Oid objectId);
static char * SchemaOwnerName(Oid objectId);
static bool HasMetadataWorkers(void);
@ -893,7 +893,7 @@ CreateSchemaDDLCommand(Oid schemaId)
}
schemaNameDef = makeStringInfo();
ownerName = OwnerName(schemaId);
ownerName = SchemaOwnerName(schemaId);
appendStringInfo(schemaNameDef, CREATE_SCHEMA_COMMAND, schemaName, ownerName);
return schemaNameDef->data;
@ -968,19 +968,19 @@ TruncateTriggerCreateCommand(Oid relationId)
/*
* OwnerName returns the name of the owner of the specified object.
* SchemaOwnerName returns the name of the owner of the specified schema.
*/
static char *
OwnerName(Oid objectId)
SchemaOwnerName(Oid objectId)
{
HeapTuple tuple = NULL;
Oid ownerId = InvalidOid;
char *ownerName = NULL;
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(objectId));
tuple = SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(objectId));
if (HeapTupleIsValid(tuple))
{
ownerId = ((Form_pg_class) GETSTRUCT(tuple))->relowner;
ownerId = ((Form_pg_namespace) GETSTRUCT(tuple))->nspowner;
}
else
{
@ -989,6 +989,8 @@ OwnerName(Oid objectId)
ownerName = GetUserNameFromId(ownerId, false);
ReleaseSysCache(tuple);
return ownerName;
}