mirror of https://github.com/citusdata/citus.git
Use CreateViewDDLCommand in GetViewCreationCommandsOfTable
parent
a9f8a60007
commit
1f8de3484e
|
@ -206,7 +206,6 @@ static char * CreateWorkerChangeSequenceDependencyCommand(char *sequenceSchemaNa
|
||||||
char *sourceName,
|
char *sourceName,
|
||||||
char *targetSchemaName,
|
char *targetSchemaName,
|
||||||
char *targetName);
|
char *targetName);
|
||||||
static char * GetAccessMethodForMatViewIfExists(Oid viewOid);
|
|
||||||
static bool WillRecreateForeignKeyToReferenceTable(Oid relationId,
|
static bool WillRecreateForeignKeyToReferenceTable(Oid relationId,
|
||||||
CascadeToColocatedOption cascadeOption);
|
CascadeToColocatedOption cascadeOption);
|
||||||
static void WarningsForDroppingForeignKeysWithDistributedTables(Oid relationId);
|
static void WarningsForDroppingForeignKeysWithDistributedTables(Oid relationId);
|
||||||
|
@ -1263,35 +1262,8 @@ GetViewCreationCommandsOfTable(Oid relationId)
|
||||||
Oid viewOid = InvalidOid;
|
Oid viewOid = InvalidOid;
|
||||||
foreach_oid(viewOid, views)
|
foreach_oid(viewOid, views)
|
||||||
{
|
{
|
||||||
Datum viewDefinitionDatum = DirectFunctionCall1(pg_get_viewdef,
|
char *createViewCommand = CreateViewDDLCommand(viewOid);
|
||||||
ObjectIdGetDatum(viewOid));
|
commands = lappend(commands, makeTableDDLCommandString(createViewCommand));
|
||||||
char *viewDefinition = TextDatumGetCString(viewDefinitionDatum);
|
|
||||||
StringInfo query = makeStringInfo();
|
|
||||||
char *viewName = get_rel_name(viewOid);
|
|
||||||
char *schemaName = get_namespace_name(get_rel_namespace(viewOid));
|
|
||||||
char *qualifiedViewName = quote_qualified_identifier(schemaName, viewName);
|
|
||||||
bool isMatView = get_rel_relkind(viewOid) == RELKIND_MATVIEW;
|
|
||||||
|
|
||||||
/* here we need to get the access method of the view to recreate it */
|
|
||||||
char *accessMethodName = GetAccessMethodForMatViewIfExists(viewOid);
|
|
||||||
|
|
||||||
appendStringInfoString(query, "CREATE ");
|
|
||||||
|
|
||||||
if (isMatView)
|
|
||||||
{
|
|
||||||
appendStringInfoString(query, "MATERIALIZED ");
|
|
||||||
}
|
|
||||||
|
|
||||||
appendStringInfo(query, "VIEW %s ", qualifiedViewName);
|
|
||||||
|
|
||||||
if (accessMethodName)
|
|
||||||
{
|
|
||||||
appendStringInfo(query, "USING %s ", accessMethodName);
|
|
||||||
}
|
|
||||||
|
|
||||||
appendStringInfo(query, "AS %s", viewDefinition);
|
|
||||||
|
|
||||||
commands = lappend(commands, makeTableDDLCommandString(query->data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands;
|
return commands;
|
||||||
|
@ -1694,32 +1666,6 @@ CreateWorkerChangeSequenceDependencyCommand(char *sequenceSchemaName, char *sequ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GetAccessMethodForMatViewIfExists returns if there's an access method
|
|
||||||
* set to the view with the given oid. Returns NULL otherwise.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
GetAccessMethodForMatViewIfExists(Oid viewOid)
|
|
||||||
{
|
|
||||||
char *accessMethodName = NULL;
|
|
||||||
Relation relation = try_relation_open(viewOid, AccessShareLock);
|
|
||||||
if (relation == NULL)
|
|
||||||
{
|
|
||||||
ereport(ERROR, (errmsg("cannot complete operation "
|
|
||||||
"because no such view exists")));
|
|
||||||
}
|
|
||||||
|
|
||||||
Oid accessMethodOid = relation->rd_rel->relam;
|
|
||||||
if (OidIsValid(accessMethodOid))
|
|
||||||
{
|
|
||||||
accessMethodName = get_am_name(accessMethodOid);
|
|
||||||
}
|
|
||||||
relation_close(relation, NoLock);
|
|
||||||
|
|
||||||
return accessMethodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WillRecreateForeignKeyToReferenceTable checks if the table of relationId has any foreign
|
* WillRecreateForeignKeyToReferenceTable checks if the table of relationId has any foreign
|
||||||
* key to a reference table, if conversion will be cascaded to colocated table this function
|
* key to a reference table, if conversion will be cascaded to colocated table this function
|
||||||
|
|
Loading…
Reference in New Issue