allow "alter table set schema" from any node for Postgres tables - postgres tables

ddl-from-any-node-phase-1
Onur Tirtir 2025-11-12 15:44:09 +03:00
parent 0629766e57
commit c14b135780
1 changed files with 26 additions and 17 deletions

View File

@ -4330,11 +4330,6 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
{
Assert(stmt->objectType == OBJECT_TABLE || stmt->objectType == OBJECT_FOREIGN_TABLE);
if (!IsCoordinator())
{
return;
}
/*
* We will let Postgres deal with missing_ok
*/
@ -4345,16 +4340,24 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
/* We have already asserted that we have exactly 1 address in the addresses. */
ObjectAddress *tableAddress = linitial(tableAddresses);
char relKind = get_rel_relkind(tableAddress->objectId);
Oid relationId = tableAddress->objectId;
if (!OidIsValid(relationId))
{
Assert(stmt->missing_ok);
return;
}
char relKind = get_rel_relkind(relationId);
if (relKind == RELKIND_SEQUENCE || relKind == RELKIND_VIEW)
{
return;
}
Oid relationId = tableAddress->objectId;
Oid schemaId = get_namespace_oid(stmt->newschema, stmt->missing_ok);
if (!OidIsValid(schemaId))
{
Assert(stmt->missing_ok);
return;
}
@ -4364,9 +4367,16 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
* that by seeing the table is still a single shard table. (i.e. not undistributed
* at `preprocess` step)
*/
if (!IsCitusTableType(relationId, SINGLE_SHARD_DISTRIBUTED) &&
IsTenantSchema(schemaId))
if (IsCitusTableType(relationId, SINGLE_SHARD_DISTRIBUTED))
{
return;
}
if (!ShouldCreateTenantSchemaTable(relationId))
{
return;
}
EnsureTenantTable(relationId, "ALTER TABLE SET SCHEMA");
char *schemaName = get_namespace_name(schemaId);
@ -4375,5 +4385,4 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
tableName, schemaName)));
CreateTenantSchemaTable(relationId);
}
}