From a1c630a16ee4b0c599e8bc27e5094f18cfe33ec6 Mon Sep 17 00:00:00 2001 From: Naisila Puka <37271756+naisila@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:34:13 +0300 Subject: [PATCH 1/2] Reduce shard_count to reduce drain_node execution time (#6128) master_drain_node in distributed_triggers.sql test file takes too long to execute. It is directly dependent on the shard count. Hence I reduced shard count from 32 to 4 (default in tests), since this doesn't affect the validity of the tests. --- .../regress/expected/distributed_triggers.out | 57 +++---------------- src/test/regress/sql/distributed_triggers.sql | 3 +- 2 files changed, 8 insertions(+), 52 deletions(-) diff --git a/src/test/regress/expected/distributed_triggers.out b/src/test/regress/expected/distributed_triggers.out index bef576fb4..002c4e465 100644 --- a/src/test/regress/expected/distributed_triggers.out +++ b/src/test/regress/expected/distributed_triggers.out @@ -4,7 +4,6 @@ NOTICE: schema "distributed_triggers" does not exist, skipping CREATE SCHEMA distributed_triggers; SET search_path TO 'distributed_triggers'; SET citus.shard_replication_factor = 1; -SET citus.shard_count = 32; SET citus.next_shard_id TO 800000; -- -- Test citus.enable_unsafe_triggers @@ -211,8 +210,8 @@ SELECT tgrelid::regclass::text, tgname FROM pg_trigger WHERE tgname like 'record SELECT run_command_on_workers($$SELECT count(*) FROM pg_trigger WHERE tgname like 'record_change_trigger%';$$); run_command_on_workers --------------------------------------------------------------------- - (localhost,57637,t,17) - (localhost,57638,t,17) + (localhost,57637,t,3) + (localhost,57638,t,3) (2 rows) ALTER TRIGGER "record_change_trigger" ON "distributed_triggers"."data" RENAME TO "new_record_change_trigger"; @@ -237,8 +236,8 @@ SELECT run_command_on_workers($$SELECT count(*) FROM pg_trigger WHERE tgname lik SELECT run_command_on_workers($$SELECT count(*) FROM pg_trigger WHERE tgname like 'new_record_change_trigger%';$$); run_command_on_workers --------------------------------------------------------------------- - (localhost,57637,t,17) - (localhost,57638,t,17) + (localhost,57637,t,3) + (localhost,57638,t,3) (2 rows) --This should fail @@ -505,7 +504,7 @@ $rec_audit$ LANGUAGE plpgsql; CREATE TRIGGER record_emp_trig AFTER INSERT OR UPDATE OR DELETE ON emptest FOR EACH STATEMENT EXECUTE FUNCTION distributed_triggers.record_emp(); -INSERT INTO emptest VALUES ('test5', 1); +INSERT INTO emptest VALUES ('test6', 1); ERROR: cannot execute a distributed query from a query on a shard DETAIL: Executing a distributed query in a function call that may be pushed to a remote node can lead to incorrect results. HINT: Avoid nesting of distributed queries or use alter user current_user set citus.allow_nested_distributed_execution to on to allow it with possible incorrectness. @@ -776,48 +775,6 @@ NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... -NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... NOTICE: Moving shard xxxxx from localhost:xxxxx to localhost:xxxxx ... master_drain_node --------------------------------------------------------------------- @@ -862,7 +819,7 @@ SELECT tgrelid::regclass::text, tgname FROM pg_trigger WHERE tgname like 'insert SELECT run_command_on_workers($$SELECT count(*) FROM pg_trigger WHERE tgname like 'insert_99_trigger%'$$); run_command_on_workers --------------------------------------------------------------------- - (localhost,57637,t,33) + (localhost,57637,t,5) (1 row) INSERT INTO distributed_table VALUES (99); @@ -898,7 +855,7 @@ SELECT tgrelid::regclass::text, tgname FROM pg_trigger WHERE tgname like 'insert SELECT run_command_on_workers($$SELECT count(*) FROM pg_trigger WHERE tgname like 'insert_99_trigger%'$$); run_command_on_workers --------------------------------------------------------------------- - (localhost,57637,t,33) + (localhost,57637,t,5) (localhost,57638,t,1) (2 rows) diff --git a/src/test/regress/sql/distributed_triggers.sql b/src/test/regress/sql/distributed_triggers.sql index 9acb1434c..e070a7e2e 100644 --- a/src/test/regress/sql/distributed_triggers.sql +++ b/src/test/regress/sql/distributed_triggers.sql @@ -3,7 +3,6 @@ DROP SCHEMA IF EXISTS distributed_triggers CASCADE; CREATE SCHEMA distributed_triggers; SET search_path TO 'distributed_triggers'; SET citus.shard_replication_factor = 1; -SET citus.shard_count = 32; SET citus.next_shard_id TO 800000; -- @@ -302,7 +301,7 @@ CREATE TRIGGER record_emp_trig AFTER INSERT OR UPDATE OR DELETE ON emptest FOR EACH STATEMENT EXECUTE FUNCTION distributed_triggers.record_emp(); -INSERT INTO emptest VALUES ('test5', 1); +INSERT INTO emptest VALUES ('test6', 1); DELETE FROM emptest; SELECT * FROM emptest; SELECT operation_type FROM record_op; From b67abdd28c56c97014cab0d85b5b8ff958e86429 Mon Sep 17 00:00:00 2001 From: aykut-bozkurt <51649454+aykut-bozkurt@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:49:14 +0300 Subject: [PATCH 2/2] we should not log error in preprocess if attached partition is missing. (#6131) --- src/backend/distributed/commands/table.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index d8fb4f59d..1cf1e54a5 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -439,9 +439,18 @@ PreprocessAlterTableStmtAttachPartition(AlterTableStmt *alterTableStatement, Oid parentRelationId = AlterTableLookupRelation(alterTableStatement, lockmode); PartitionCmd *partitionCommand = (PartitionCmd *) alterTableCommand->def; - bool partitionMissingOk = false; + bool partitionMissingOk = true; Oid partitionRelationId = RangeVarGetRelid(partitionCommand->name, lockmode, partitionMissingOk); + if (!OidIsValid(partitionRelationId)) + { + /* + * We can stop propagation here instead of logging error. Pg will complain + * in standard_utility, so we are safe to stop here. We pass missing_ok + * as true to not diverge from pg output. + */ + return NIL; + } if (!IsCitusTable(parentRelationId)) {