From 2071ef2a60b9f96d1179f8c1b61a291839172b91 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Wed, 25 May 2022 11:38:16 +0300 Subject: [PATCH] addres rev --- .../citus_add_local_table_to_metadata.c | 18 +++++++++++++++++- .../distributed/metadata/metadata_sync.c | 7 +++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index 7645d9eab..43e43b61e 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -345,8 +345,13 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve ExecuteAndLogUtilityCommandList(shellTableDDLEvents); /* - * Execute the view creation commands with the shell table. + * Execute the view creation commands with the shell table. Since we want to create + * views locally here, disable/enable ddl propagation. Views will be distributed via + * FinalizeCitusLocalTableCreation below. */ + tableViewCreationCommands = lcons(DISABLE_DDL_PROPAGATION, tableViewCreationCommands); + tableViewCreationCommands = lappend(tableViewCreationCommands, + ENABLE_DDL_PROPAGATION); ExecuteAndLogUtilityCommandList(tableViewCreationCommands); /* @@ -1036,9 +1041,20 @@ static void DropViewsOnTable(Oid relationId) { List *views = GetDependingViews(relationId); + List *reverseOrderedViews = NIL; + /* + * GetDependingViews returns views in the dependency order. We should drop views + * in the reversed order since dropping views can cascade to other views below ... + */ Oid viewId = InvalidOid; foreach_oid(viewId, views) + { + reverseOrderedViews = list_insert_nth_oid(reverseOrderedViews, 0, viewId); + } + + viewId = InvalidOid; + foreach_oid(viewId, reverseOrderedViews) { char *viewName = get_rel_name(viewId); char *schemaName = get_namespace_name(get_rel_namespace(viewId)); diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index 9e7ba50c8..2057327c3 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -350,14 +350,17 @@ CreateDependentViewsOnWorkers(Oid relationId) continue; } + ObjectAddress viewAddress = { 0 }; + ObjectAddressSet(viewAddress, RelationRelationId, viewOid); + + EnsureDependenciesExistOnAllNodes(&viewAddress); + char *createViewCommand = CreateViewDDLCommand(viewOid); char *alterViewOwnerCommand = AlterViewOwnerCommand(viewOid); SendCommandToWorkersWithMetadata(createViewCommand); SendCommandToWorkersWithMetadata(alterViewOwnerCommand); - ObjectAddress viewAddress = { 0 }; - ObjectAddressSet(viewAddress, RelationRelationId, viewOid); MarkObjectDistributed(&viewAddress); }