mirror of https://github.com/citusdata/citus.git
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
parent
a7c65a3ed8
commit
1b5560b2f7
|
@ -53,7 +53,7 @@ static List * SequenceDDLCommandsForTable(Oid relationId);
|
||||||
static void EnsureSupportedSequenceColumnType(Oid sequenceOid);
|
static void EnsureSupportedSequenceColumnType(Oid sequenceOid);
|
||||||
static Oid TypeOfColumn(Oid tableId, int16 columnId);
|
static Oid TypeOfColumn(Oid tableId, int16 columnId);
|
||||||
static char * TruncateTriggerCreateCommand(Oid relationId);
|
static char * TruncateTriggerCreateCommand(Oid relationId);
|
||||||
static char * OwnerName(Oid objectId);
|
static char * SchemaOwnerName(Oid objectId);
|
||||||
static bool HasMetadataWorkers(void);
|
static bool HasMetadataWorkers(void);
|
||||||
|
|
||||||
|
|
||||||
|
@ -893,7 +893,7 @@ CreateSchemaDDLCommand(Oid schemaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
schemaNameDef = makeStringInfo();
|
schemaNameDef = makeStringInfo();
|
||||||
ownerName = OwnerName(schemaId);
|
ownerName = SchemaOwnerName(schemaId);
|
||||||
appendStringInfo(schemaNameDef, CREATE_SCHEMA_COMMAND, schemaName, ownerName);
|
appendStringInfo(schemaNameDef, CREATE_SCHEMA_COMMAND, schemaName, ownerName);
|
||||||
|
|
||||||
return schemaNameDef->data;
|
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 *
|
static char *
|
||||||
OwnerName(Oid objectId)
|
SchemaOwnerName(Oid objectId)
|
||||||
{
|
{
|
||||||
HeapTuple tuple = NULL;
|
HeapTuple tuple = NULL;
|
||||||
Oid ownerId = InvalidOid;
|
Oid ownerId = InvalidOid;
|
||||||
char *ownerName = NULL;
|
char *ownerName = NULL;
|
||||||
|
|
||||||
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(objectId));
|
tuple = SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(objectId));
|
||||||
if (HeapTupleIsValid(tuple))
|
if (HeapTupleIsValid(tuple))
|
||||||
{
|
{
|
||||||
ownerId = ((Form_pg_class) GETSTRUCT(tuple))->relowner;
|
ownerId = ((Form_pg_namespace) GETSTRUCT(tuple))->nspowner;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -989,6 +989,8 @@ OwnerName(Oid objectId)
|
||||||
|
|
||||||
ownerName = GetUserNameFromId(ownerId, false);
|
ownerName = GetUserNameFromId(ownerId, false);
|
||||||
|
|
||||||
|
ReleaseSysCache(tuple);
|
||||||
|
|
||||||
return ownerName;
|
return ownerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue