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); Assert(stmt->objectType == OBJECT_TABLE || stmt->objectType == OBJECT_FOREIGN_TABLE);
if (!IsCoordinator())
{
return;
}
/* /*
* We will let Postgres deal with missing_ok * 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. */ /* We have already asserted that we have exactly 1 address in the addresses. */
ObjectAddress *tableAddress = linitial(tableAddresses); 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) if (relKind == RELKIND_SEQUENCE || relKind == RELKIND_VIEW)
{ {
return; return;
} }
Oid relationId = tableAddress->objectId;
Oid schemaId = get_namespace_oid(stmt->newschema, stmt->missing_ok); Oid schemaId = get_namespace_oid(stmt->newschema, stmt->missing_ok);
if (!OidIsValid(schemaId)) if (!OidIsValid(schemaId))
{ {
Assert(stmt->missing_ok);
return; return;
} }
@ -4364,16 +4367,22 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
* that by seeing the table is still a single shard table. (i.e. not undistributed * that by seeing the table is still a single shard table. (i.e. not undistributed
* at `preprocess` step) * at `preprocess` step)
*/ */
if (!IsCitusTableType(relationId, SINGLE_SHARD_DISTRIBUTED) && if (IsCitusTableType(relationId, SINGLE_SHARD_DISTRIBUTED))
IsTenantSchema(schemaId))
{ {
EnsureTenantTable(relationId, "ALTER TABLE SET SCHEMA"); return;
char *schemaName = get_namespace_name(schemaId);
char *tableName = stmt->relation->relname;
ereport(NOTICE, (errmsg("Moving %s into distributed schema %s",
tableName, schemaName)));
CreateTenantSchemaTable(relationId);
} }
if (!ShouldCreateTenantSchemaTable(relationId))
{
return;
}
EnsureTenantTable(relationId, "ALTER TABLE SET SCHEMA");
char *schemaName = get_namespace_name(schemaId);
char *tableName = stmt->relation->relname;
ereport(NOTICE, (errmsg("Moving %s into distributed schema %s",
tableName, schemaName)));
CreateTenantSchemaTable(relationId);
} }