From 6986f53835685460e000610f95912e52fda6a7f1 Mon Sep 17 00:00:00 2001 From: Aykut Bozkurt Date: Mon, 16 May 2022 13:06:12 +0300 Subject: [PATCH] propagate unqualified vacuum and analyze to all worker nodes --- .../commands/distribute_object_ops.c | 13 ++ .../distributed/commands/utility_hook.c | 8 - src/backend/distributed/commands/vacuum.c | 168 ++++++++-------- src/include/distributed/commands.h | 2 +- .../regress/expected/multi_size_queries.out | 2 +- src/test/regress/expected/multi_utilities.out | 184 +++++++++++++++++- src/test/regress/sql/multi_utilities.sql | 80 +++++++- 7 files changed, 349 insertions(+), 108 deletions(-) diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index d516ad777..24afc0a0a 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -1024,6 +1024,14 @@ static DistributeObjectOps Type_Rename = { .address = RenameTypeStmtObjectAddress, .markDistributed = false, }; +static DistributeObjectOps Vacuum_Analyze = { + .deparse = NULL, + .qualify = NULL, + .preprocess = NULL, + .postprocess = PostprocessVacuumStmt, + .address = NULL, + .markDistributed = false, +}; /* * PreprocessRenameViewStmt function can be called internally by ALTER TABLE view_name @@ -1653,6 +1661,11 @@ GetDistributeObjectOps(Node *node) return &Any_Reindex; } + case T_VacuumStmt: + { + return &Vacuum_Analyze; + } + case T_RenameStmt: { RenameStmt *stmt = castNode(RenameStmt, node); diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index fa78e70aa..cb6ab86a3 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -830,14 +830,6 @@ ProcessUtilityInternal(PlannedStmt *pstmt, } } - /* TODO: fold VACUUM's processing into the above block */ - if (IsA(parsetree, VacuumStmt)) - { - VacuumStmt *vacuumStmt = (VacuumStmt *) parsetree; - - PostprocessVacuumStmt(vacuumStmt, queryString); - } - if (!IsDropCitusExtensionStmt(parsetree) && !IsA(parsetree, DropdbStmt)) { /* diff --git a/src/backend/distributed/commands/vacuum.c b/src/backend/distributed/commands/vacuum.c index 9b1e0bfb3..42eb00467 100644 --- a/src/backend/distributed/commands/vacuum.c +++ b/src/backend/distributed/commands/vacuum.c @@ -20,7 +20,7 @@ #include "distributed/deparse_shard_query.h" #include "distributed/listutils.h" #include "distributed/metadata_cache.h" -#include "distributed/multi_executor.h" +#include "distributed/metadata_sync.h" #include "distributed/resource_lock.h" #include "distributed/transaction_management.h" #include "distributed/version_compat.h" @@ -48,7 +48,6 @@ typedef struct CitusVacuumParams } CitusVacuumParams; /* Local functions forward declarations for processing distributed table commands */ -static bool IsDistributedVacuumStmt(int vacuumOptions, List *VacuumCitusRelationIdList); static List * VacuumTaskList(Oid relationId, CitusVacuumParams vacuumParams, List *vacuumColumnList); static char * DeparseVacuumStmtPrefix(CitusVacuumParams vacuumParams); @@ -57,44 +56,28 @@ static List * VacuumColumnList(VacuumStmt *vacuumStmt, int relationIndex); static List * ExtractVacuumTargetRels(VacuumStmt *vacuumStmt); static void ExecuteVacuumOnDistributedTables(VacuumStmt *vacuumStmt, List *relationIdList, CitusVacuumParams vacuumParams); +static void ExecuteUnqualifiedVacuumTasks(VacuumStmt *vacuumStmt, + CitusVacuumParams vacuumParams); static CitusVacuumParams VacuumStmtParams(VacuumStmt *vacstmt); static List * VacuumCitusRelationIdList(VacuumStmt *vacuumStmt, CitusVacuumParams vacuumParams); /* * PostprocessVacuumStmt processes vacuum statements that may need propagation to - * distributed tables. If a VACUUM or ANALYZE command references a distributed - * table, it is propagated to all involved nodes; otherwise, this function will - * immediately exit after some error checking. + * citus tables only if ddl propagation is enabled. If a VACUUM or ANALYZE command + * references a citus table or no table, it is propagated to all involved nodes; otherwise, + * the statements will not be propagated. * * Unlike most other Process functions within this file, this function does not * return a modified parse node, as it is expected that the local VACUUM or * ANALYZE has already been processed. */ -void -PostprocessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand) +List * +PostprocessVacuumStmt(Node *node, const char *vacuumCommand) { + VacuumStmt *vacuumStmt = castNode(VacuumStmt, node); + CitusVacuumParams vacuumParams = VacuumStmtParams(vacuumStmt); - const char *stmtName = (vacuumParams.options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE"; - - /* - * No table in the vacuum statement means vacuuming all relations - * which is not supported by citus. - */ - if (list_length(vacuumStmt->rels) == 0) - { - /* WARN for unqualified VACUUM commands */ - ereport(WARNING, (errmsg("not propagating %s command to worker nodes", stmtName), - errhint("Provide a specific table in order to %s " - "distributed tables.", stmtName))); - } - - - List *citusRelationIdList = VacuumCitusRelationIdList(vacuumStmt, vacuumParams); - if (list_length(citusRelationIdList) == 0) - { - return; - } if (vacuumParams.options & VACOPT_VACUUM) { @@ -109,25 +92,33 @@ PostprocessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand) } /* - * Here we get the relation list again because we might have - * closed the current transaction and the memory context got reset. - * Vacuum's context is PortalContext, which lasts for the whole session - * so committing/starting a new transaction doesn't affect it. + * when no table is specified propagate the command as it is; + * otherwise, only propagate when there is at least 1 citus table */ - citusRelationIdList = VacuumCitusRelationIdList(vacuumStmt, vacuumParams); - bool distributedVacuumStmt = IsDistributedVacuumStmt(vacuumParams.options, - citusRelationIdList); - if (!distributedVacuumStmt) + List *citusRelationIdList = VacuumCitusRelationIdList(vacuumStmt, vacuumParams); + + if (list_length(vacuumStmt->rels) == 0) { - return; + /* no table is specified (unqualified vacuum) */ + + ExecuteUnqualifiedVacuumTasks(vacuumStmt, vacuumParams); + } + else if (list_length(citusRelationIdList) > 0) + { + /* there is at least 1 citus table specified */ + + ExecuteVacuumOnDistributedTables(vacuumStmt, citusRelationIdList, + vacuumParams); } - ExecuteVacuumOnDistributedTables(vacuumStmt, citusRelationIdList, vacuumParams); + /* else only local tables are specified */ + + return NIL; } /* - * VacuumCitusRelationIdList returns the oid of the relations in the given vacuum statement. + * VacuumCitusRelationIdList returns the oid of the citus relations in the given vacuum statement. */ static List * VacuumCitusRelationIdList(VacuumStmt *vacuumStmt, CitusVacuumParams vacuumParams) @@ -183,53 +174,6 @@ ExecuteVacuumOnDistributedTables(VacuumStmt *vacuumStmt, List *relationIdList, } -/* - * IsDistributedVacuumStmt returns whether distributed execution of a - * given VacuumStmt is supported. The provided relationId list represents - * the list of tables targeted by the provided statement. - * - * Returns true if the statement requires distributed execution and returns - * false otherwise. - */ -static bool -IsDistributedVacuumStmt(int vacuumOptions, List *VacuumCitusRelationIdList) -{ - bool distributeStmt = false; - int distributedRelationCount = 0; - - const char *stmtName = (vacuumOptions & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE"; - - - Oid relationId = InvalidOid; - foreach_oid(relationId, VacuumCitusRelationIdList) - { - if (OidIsValid(relationId) && IsCitusTable(relationId)) - { - distributedRelationCount++; - } - } - - if (distributedRelationCount == 0) - { - /* nothing to do here */ - } - else if (!EnableDDLPropagation) - { - /* WARN if DDL propagation is not enabled */ - ereport(WARNING, (errmsg("not propagating %s command to worker nodes", stmtName), - errhint("Set citus.enable_ddl_propagation to true in order to " - "send targeted %s commands to worker nodes.", - stmtName))); - } - else - { - distributeStmt = true; - } - - return distributeStmt; -} - - /* * VacuumTaskList returns a list of tasks to be executed as part of processing * a VacuumStmt which targets a distributed relation. @@ -606,3 +550,57 @@ VacuumStmtParams(VacuumStmt *vacstmt) (disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0); return params; } + + +/* + * ExecuteUnqualifiedVacuumTasks executes tasks for unqualified vacuum commands + */ +static void +ExecuteUnqualifiedVacuumTasks(VacuumStmt *vacuumStmt, CitusVacuumParams vacuumParams) +{ + /* don't allow concurrent node list changes that require an exclusive lock */ + List *workerNodes = TargetWorkerSetNodeList(ALL_SHARD_NODES, RowShareLock); + + if (list_length(workerNodes) == 0) + { + return; + } + + const char *vacuumStringPrefix = DeparseVacuumStmtPrefix(vacuumParams); + + StringInfo vacuumCommand = makeStringInfo(); + appendStringInfoString(vacuumCommand, vacuumStringPrefix); + + List *unqualifiedVacuumCommands = list_make3(DISABLE_DDL_PROPAGATION, + vacuumCommand->data, + ENABLE_DDL_PROPAGATION); + + Task *task = CitusMakeNode(Task); + task->jobId = INVALID_JOB_ID; + task->taskType = VACUUM_ANALYZE_TASK; + SetTaskQueryStringList(task, unqualifiedVacuumCommands); + task->dependentTaskList = NULL; + task->replicationModel = REPLICATION_MODEL_INVALID; + task->cannotBeExecutedInTransction = ((vacuumParams.options) & VACOPT_VACUUM); + + + int32 localNodeGroupId = GetLocalGroupId(); + + WorkerNode *workerNode = NULL; + foreach_ptr(workerNode, workerNodes) + { + if (workerNode->groupId != localNodeGroupId) + { + ShardPlacement *targetPlacement = CitusMakeNode(ShardPlacement); + targetPlacement->nodeName = workerNode->workerName; + targetPlacement->nodePort = workerNode->workerPort; + targetPlacement->groupId = workerNode->groupId; + + task->taskPlacementList = lappend(task->taskPlacementList, + targetPlacement); + } + } + + bool localExecution = false; + ExecuteUtilityTaskList(list_make1(task), localExecution); +} diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 1db02fd3c..96172bad4 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -553,7 +553,7 @@ extern void UpdateFunctionDistributionInfo(const ObjectAddress *distAddress, bool *forceDelegation); /* vacuum.c - forward declarations */ -extern void PostprocessVacuumStmt(VacuumStmt *vacuumStmt, const char *vacuumCommand); +extern List * PostprocessVacuumStmt(Node *node, const char *vacuumCommand); /* view.c - forward declarations */ extern List * PreprocessViewStmt(Node *node, const char *queryString, diff --git a/src/test/regress/expected/multi_size_queries.out b/src/test/regress/expected/multi_size_queries.out index 4f1df941c..97036b1db 100644 --- a/src/test/regress/expected/multi_size_queries.out +++ b/src/test/regress/expected/multi_size_queries.out @@ -75,7 +75,7 @@ SELECT citus_table_size('customer_copy_hash'), citus_table_size('supplier'); citus_table_size | citus_table_size | citus_table_size --------------------------------------------------------------------- - 548864 | 548864 | 425984 + 548864 | 548864 | 442368 (1 row) CREATE INDEX index_1 on customer_copy_hash(c_custkey); diff --git a/src/test/regress/expected/multi_utilities.out b/src/test/regress/expected/multi_utilities.out index 725c307da..41e426508 100644 --- a/src/test/regress/expected/multi_utilities.out +++ b/src/test/regress/expected/multi_utilities.out @@ -246,10 +246,6 @@ WHERE tablename = 'dustbunnies_990002' ORDER BY attname; \c - - :master_host :master_port SET citus.log_remote_commands TO ON; --- verify warning for unqualified VACUUM -VACUUM; -WARNING: not propagating VACUUM command to worker nodes -HINT: Provide a specific table in order to VACUUM distributed tables. -- check for multiple table vacuum VACUUM dustbunnies, second_dustbunnies; NOTICE: issuing VACUUM public.dustbunnies_990002 @@ -260,14 +256,10 @@ NOTICE: issuing VACUUM public.second_dustbunnies_990003 DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing VACUUM public.second_dustbunnies_990003 DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx --- and warning when using targeted VACUUM without DDL propagation +-- and do not propagate when using targeted VACUUM without DDL propagation SET citus.enable_ddl_propagation to false; VACUUM dustbunnies; -WARNING: not propagating VACUUM command to worker nodes -HINT: Set citus.enable_ddl_propagation to true in order to send targeted VACUUM commands to worker nodes. ANALYZE dustbunnies; -WARNING: not propagating ANALYZE command to worker nodes -HINT: Set citus.enable_ddl_propagation to true in order to send targeted ANALYZE commands to worker nodes. SET citus.enable_ddl_propagation to DEFAULT; -- test worker_hash SELECT worker_hash(123); @@ -314,3 +306,177 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx 1 (1 row) +SET citus.shard_count TO 1; +SET citus.shard_replication_factor TO 1; +SET citus.next_shard_id TO 970000; +SET citus.log_remote_commands TO OFF; +CREATE TABLE local_vacuum_table(id int); +CREATE TABLE reference_vacuum_table(id int); +SELECT create_reference_table('reference_vacuum_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE distributed_vacuum_table(id int); +SELECT create_distributed_table('distributed_vacuum_table', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +SET citus.log_remote_commands TO ON; +-- should propagate to all workers because no table is specified +VACUUM; +NOTICE: issuing SET citus.enable_ddl_propagation TO 'off' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'off' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'on' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'on' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should not propagate because no distributed table is specified +VACUUM local_vacuum_table; +-- should propagate to all workers because table is reference table +VACUUM reference_vacuum_table; +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should propagate to all workers because table is distributed table +VACUUM distributed_vacuum_table; +NOTICE: issuing VACUUM public.distributed_vacuum_table_970001 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- only distributed_vacuum_table and reference_vacuum_table should propagate +VACUUM distributed_vacuum_table, local_vacuum_table, reference_vacuum_table; +NOTICE: issuing VACUUM public.distributed_vacuum_table_970001 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- only reference_vacuum_table should propagate +VACUUM local_vacuum_table, reference_vacuum_table; +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing VACUUM public.reference_vacuum_table_970000 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should not propagate because ddl propagation is disabled +SET citus.enable_ddl_propagation TO OFF; +VACUUM distributed_vacuum_table; +SET citus.enable_ddl_propagation TO ON; +SET citus.log_remote_commands TO OFF; +-- ANALYZE tests +CREATE TABLE local_analyze_table(id int); +CREATE TABLE reference_analyze_table(id int); +SELECT create_reference_table('reference_analyze_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE distributed_analyze_table(id int); +SELECT create_distributed_table('distributed_analyze_table', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +SET citus.log_remote_commands TO ON; +-- should propagate to all workers because no table is specified +ANALYZE; +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'off' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'off' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'on' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing SET citus.enable_ddl_propagation TO 'on' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should not propagate because no distributed table is specified +ANALYZE local_analyze_table; +-- should propagate to all workers because table is reference table +ANALYZE reference_analyze_table; +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should propagate to all workers because table is distributed table +ANALYZE distributed_analyze_table; +NOTICE: issuing ANALYZE public.distributed_analyze_table_970003 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- only distributed_analyze_table and reference_analyze_table should propagate +ANALYZE distributed_analyze_table, local_analyze_table, reference_analyze_table; +NOTICE: issuing ANALYZE public.distributed_analyze_table_970003 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- only reference_analyze_table should propagate +ANALYZE local_analyze_table, reference_analyze_table; +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing ANALYZE public.reference_analyze_table_970002 +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx' +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should not propagate because ddl propagation is disabled +SET citus.enable_ddl_propagation TO OFF; +ANALYZE distributed_analyze_table; +SET citus.enable_ddl_propagation TO ON; diff --git a/src/test/regress/sql/multi_utilities.sql b/src/test/regress/sql/multi_utilities.sql index eb4432726..ba11960a1 100644 --- a/src/test/regress/sql/multi_utilities.sql +++ b/src/test/regress/sql/multi_utilities.sql @@ -170,13 +170,10 @@ WHERE tablename = 'dustbunnies_990002' ORDER BY attname; \c - - :master_host :master_port SET citus.log_remote_commands TO ON; --- verify warning for unqualified VACUUM -VACUUM; - -- check for multiple table vacuum VACUUM dustbunnies, second_dustbunnies; --- and warning when using targeted VACUUM without DDL propagation +-- and do not propagate when using targeted VACUUM without DDL propagation SET citus.enable_ddl_propagation to false; VACUUM dustbunnies; ANALYZE dustbunnies; @@ -198,3 +195,78 @@ SELECT worker_create_or_alter_role(NULL, 'create role dontcrash', NULL); -- confirm that citus_create_restore_point works SELECT 1 FROM citus_create_restore_point('regression-test'); + +SET citus.shard_count TO 1; +SET citus.shard_replication_factor TO 1; +SET citus.next_shard_id TO 970000; + +SET citus.log_remote_commands TO OFF; + +CREATE TABLE local_vacuum_table(id int); + +CREATE TABLE reference_vacuum_table(id int); +SELECT create_reference_table('reference_vacuum_table'); + +CREATE TABLE distributed_vacuum_table(id int); +SELECT create_distributed_table('distributed_vacuum_table', 'id'); + +SET citus.log_remote_commands TO ON; + +-- should propagate to all workers because no table is specified +VACUUM; + +-- should not propagate because no distributed table is specified +VACUUM local_vacuum_table; + +-- should propagate to all workers because table is reference table +VACUUM reference_vacuum_table; + +-- should propagate to all workers because table is distributed table +VACUUM distributed_vacuum_table; + +-- only distributed_vacuum_table and reference_vacuum_table should propagate +VACUUM distributed_vacuum_table, local_vacuum_table, reference_vacuum_table; + +-- only reference_vacuum_table should propagate +VACUUM local_vacuum_table, reference_vacuum_table; + +-- should not propagate because ddl propagation is disabled +SET citus.enable_ddl_propagation TO OFF; +VACUUM distributed_vacuum_table; +SET citus.enable_ddl_propagation TO ON; + +SET citus.log_remote_commands TO OFF; + +-- ANALYZE tests +CREATE TABLE local_analyze_table(id int); + +CREATE TABLE reference_analyze_table(id int); +SELECT create_reference_table('reference_analyze_table'); + +CREATE TABLE distributed_analyze_table(id int); +SELECT create_distributed_table('distributed_analyze_table', 'id'); + +SET citus.log_remote_commands TO ON; + +-- should propagate to all workers because no table is specified +ANALYZE; + +-- should not propagate because no distributed table is specified +ANALYZE local_analyze_table; + +-- should propagate to all workers because table is reference table +ANALYZE reference_analyze_table; + +-- should propagate to all workers because table is distributed table +ANALYZE distributed_analyze_table; + +-- only distributed_analyze_table and reference_analyze_table should propagate +ANALYZE distributed_analyze_table, local_analyze_table, reference_analyze_table; + +-- only reference_analyze_table should propagate +ANALYZE local_analyze_table, reference_analyze_table; + +-- should not propagate because ddl propagation is disabled +SET citus.enable_ddl_propagation TO OFF; +ANALYZE distributed_analyze_table; +SET citus.enable_ddl_propagation TO ON;