diff --git a/src/test/regress/citus_tests/run_test.py b/src/test/regress/citus_tests/run_test.py index 9c901785c41..5964267ec35 100755 --- a/src/test/regress/citus_tests/run_test.py +++ b/src/test/regress/citus_tests/run_test.py @@ -109,6 +109,10 @@ def extra_tests(self): "multi_mx_function_table_reference", ], ), + "multi_mx_modifying_xacts": TestDeps(None, ["multi_mx_create_table"]), + "multi_mx_router_planner": TestDeps(None, ["multi_mx_create_table"]), + "multi_mx_copy_data": TestDeps(None, ["multi_mx_create_table"]), + "multi_simple_queries": TestDeps("base_schedule"), } if not (test_file_name or test_file_path): diff --git a/src/test/regress/expected/multi_data_types.out b/src/test/regress/expected/multi_data_types.out index 4bc7da5c719..a88f9e1de25 100644 --- a/src/test/regress/expected/multi_data_types.out +++ b/src/test/regress/expected/multi_data_types.out @@ -3,6 +3,14 @@ -- create, distribute, INSERT, SELECT and UPDATE -- =================================================================== SET citus.next_shard_id TO 530000; +-- Given that other test files depend on the existence of types created in this file, +-- we cannot drop them at the end. Instead, we drop them at the beginning of the test +-- to make this file runnable multiple times via run_test.py. +BEGIN; + SET LOCAL client_min_messages TO WARNING; + DROP TYPE IF EXISTS test_composite_type, other_composite_type, bug_status CASCADE; + DROP OPERATOR FAMILY IF EXISTS cats_op_fam USING hash; +COMMIT; -- create a custom type... CREATE TYPE test_composite_type AS ( i integer, diff --git a/src/test/regress/expected/multi_modifying_xacts.out b/src/test/regress/expected/multi_modifying_xacts.out index 607c327ff3e..0294e1060bc 100644 --- a/src/test/regress/expected/multi_modifying_xacts.out +++ b/src/test/regress/expected/multi_modifying_xacts.out @@ -1,5 +1,7 @@ SET citus.next_shard_id TO 1200000; SET citus.next_placement_id TO 1200000; +CREATE SCHEMA multi_modifying_xacts; +SET search_path TO multi_modifying_xacts; -- =================================================================== -- test end-to-end modification functionality -- =================================================================== @@ -190,7 +192,7 @@ ALTER TABLE labs ADD COLUMN motto text; INSERT INTO labs VALUES (6, 'Bell Labs'); ABORT; -- but the DDL should correctly roll back -SELECT "Column", "Type", "Modifiers" FROM table_desc WHERE relid='public.labs'::regclass; +SELECT "Column", "Type", "Modifiers" FROM public.table_desc WHERE relid='multi_modifying_xacts.labs'::regclass; Column | Type | Modifiers --------------------------------------------------------------------- id | bigint | not null @@ -339,7 +341,7 @@ CREATE FUNCTION reject_large_id() RETURNS trigger AS $rli$ END; $rli$ LANGUAGE plpgsql; -- register after insert trigger -SELECT * FROM run_command_on_placements('researchers', 'CREATE CONSTRAINT TRIGGER reject_large_researcher_id AFTER INSERT ON %s DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_large_id()') +SELECT * FROM run_command_on_placements('multi_modifying_xacts.researchers', 'CREATE CONSTRAINT TRIGGER reject_large_researcher_id AFTER INSERT ON %s DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE multi_modifying_xacts.reject_large_id()') ORDER BY nodeport, shardid; nodename | nodeport | shardid | success | result --------------------------------------------------------------------- @@ -498,6 +500,7 @@ AND s.logicalrelid = 'objects'::regclass; -- create trigger on one worker to reject certain values \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ BEGIN @@ -514,6 +517,7 @@ AFTER INSERT ON objects_1200003 DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- test partial failure; worker_1 succeeds, 2 fails -- in this case, we expect the transaction to abort \set VERBOSITY terse @@ -551,6 +555,7 @@ DELETE FROM objects; -- there cannot be errors on different shards at different times -- because the first failure will fail the whole transaction \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ BEGIN @@ -567,6 +572,7 @@ AFTER INSERT ON labs_1200002 DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; BEGIN; INSERT INTO objects VALUES (1, 'apple'); INSERT INTO objects VALUES (2, 'BAD'); @@ -602,12 +608,14 @@ AND (s.logicalrelid = 'objects'::regclass OR -- what if the failures happen at COMMIT time? \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON objects_1200003; CREATE CONSTRAINT TRIGGER reject_bad AFTER INSERT ON objects_1200003 DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- should be the same story as before, just at COMMIT time -- as we use 2PC, the transaction is rollbacked BEGIN; @@ -644,12 +652,14 @@ WHERE sp.shardid = s.shardid AND s.logicalrelid = 'objects'::regclass; -- what if all nodes have failures at COMMIT time? \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON labs_1200002; CREATE CONSTRAINT TRIGGER reject_bad AFTER INSERT ON labs_1200002 DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- reduce the log level for differences between PG14 and PG15 -- in PGconn->errorMessage -- relevant PG commit b15f254466aefbabcbed001929f6e09db59fd158 @@ -688,8 +698,10 @@ AND (s.logicalrelid = 'objects'::regclass OR -- what if one shard (objects) succeeds but another (labs) completely fails? \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON objects_1200003; \c - - - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200004; BEGIN; INSERT INTO objects VALUES (1, 'apple'); @@ -833,6 +845,7 @@ SELECT * FROM reference_modifying_xacts; -- lets fail on of the workers at before the commit time \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad_reference() RETURNS trigger AS $rb$ BEGIN @@ -849,6 +862,7 @@ AFTER INSERT ON reference_modifying_xacts_1200006 DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- try without wrapping inside a transaction INSERT INTO reference_modifying_xacts VALUES (999, 3); @@ -860,12 +874,14 @@ ERROR: illegal value COMMIT; -- lets fail one of the workers at COMMIT time \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_reference ON reference_modifying_xacts_1200006; CREATE CONSTRAINT TRIGGER reject_bad_reference AFTER INSERT ON reference_modifying_xacts_1200006 DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- try without wrapping inside a transaction INSERT INTO reference_modifying_xacts VALUES (999, 3); @@ -890,8 +906,10 @@ ORDER BY s.logicalrelid, sp.shardstate; -- for the time-being drop the constraint \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_reference ON reference_modifying_xacts_1200006; \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- now create a hash distributed table and run tests -- including both the reference table and the hash -- distributed table @@ -923,6 +941,7 @@ INSERT INTO hash_modifying_xacts VALUES (2, 2); ABORT; -- lets fail one of the workers before COMMIT time for the hash table \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad_hash() RETURNS trigger AS $rb$ BEGIN @@ -939,6 +958,7 @@ AFTER INSERT ON hash_modifying_xacts_1200007 DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- the transaction as a whole should fail BEGIN; @@ -955,6 +975,7 @@ SELECT * FROM reference_modifying_xacts WHERE key = 55; -- now lets fail on of the workers for the hash distributed table table -- when there is a reference table involved \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_hash ON hash_modifying_xacts_1200007; -- the trigger is on execution time CREATE CONSTRAINT TRIGGER reject_bad_hash @@ -962,6 +983,7 @@ AFTER INSERT ON hash_modifying_xacts_1200007 DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- the transaction as a whole should fail BEGIN; @@ -994,11 +1016,13 @@ ORDER BY s.logicalrelid, sp.shardstate; -- and ensure that hash distributed table's -- change is rollbacked as well \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; CREATE CONSTRAINT TRIGGER reject_bad_reference AFTER INSERT ON reference_modifying_xacts_1200006 DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse BEGIN; -- to expand participant to include all worker nodes @@ -1127,8 +1151,10 @@ SELECT count(*) FROM pg_dist_transaction; -- in which we'll make the remote host unavailable -- first create the new user on all nodes CREATE USER test_user; +GRANT ALL ON SCHEMA multi_modifying_xacts TO test_user; -- now connect back to the master with the new user \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200015; CREATE TABLE reference_failure_test (key int, value int); SELECT create_reference_table('reference_failure_test'); @@ -1148,21 +1174,24 @@ SELECT create_distributed_table('numbers_hash_failure_test', 'key'); -- ensure that the shard is created for this user \c - test_user - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.override_table_visibility TO false; \dt reference_failure_test_1200015 - List of relations - Schema | Name | Type | Owner + List of relations + Schema | Name | Type | Owner --------------------------------------------------------------------- - public | reference_failure_test_1200015 | table | test_user + multi_modifying_xacts | reference_failure_test_1200015 | table | test_user (1 row) -- now connect with the default user, -- and rename the existing user \c - :default_user - :worker_1_port +SET search_path TO multi_modifying_xacts; ALTER USER test_user RENAME TO test_user_new; NOTICE: not propagating ALTER ROLE ... RENAME TO commands to worker nodes -- connect back to master and query the reference table \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; -- should fail since the worker doesn't have test_user anymore INSERT INTO reference_failure_test VALUES (1, '1'); ERROR: connection to the remote node localhost:xxxxx failed with the following error: FATAL: role "test_user" does not exist @@ -1277,14 +1306,17 @@ WARNING: connection to the remote node localhost:xxxxx failed with the followin -- break the other node as well \c - :default_user - :worker_2_port +SET search_path TO multi_modifying_xacts; ALTER USER test_user RENAME TO test_user_new; NOTICE: not propagating ALTER ROLE ... RENAME TO commands to worker nodes \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; -- fails on all shard placements INSERT INTO numbers_hash_failure_test VALUES (2,2); ERROR: connection to the remote node localhost:xxxxx failed with the following error: FATAL: role "test_user" does not exist -- connect back to the master with the proper user to continue the tests \c - :default_user - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200020; SET citus.next_placement_id TO 1200033; -- unbreak both nodes by renaming the user back to the original name @@ -1297,6 +1329,7 @@ SELECT * FROM run_command_on_workers('ALTER USER test_user_new RENAME TO test_us DROP TABLE reference_modifying_xacts, hash_modifying_xacts, hash_modifying_xacts_second, reference_failure_test, numbers_hash_failure_test; +REVOKE ALL ON SCHEMA multi_modifying_xacts FROM test_user; DROP USER test_user; -- set up foreign keys to test transactions with co-located and reference tables BEGIN; @@ -1322,7 +1355,9 @@ SELECT create_reference_table('itemgroups'); (1 row) +SET client_min_messages TO WARNING; DROP TABLE IF EXISTS users ; +RESET client_min_messages; CREATE TABLE users ( id int PRIMARY KEY, name text, @@ -1354,18 +1389,18 @@ JOIN USING (shardid) ORDER BY id; - id | shard_name | nodename | nodeport ---------------------------------------------------------------------- - 1 | users_1200022 | localhost | 57637 - 2 | users_1200025 | localhost | 57638 - 3 | users_1200023 | localhost | 57638 - 4 | users_1200023 | localhost | 57638 - 5 | users_1200022 | localhost | 57637 - 6 | users_1200024 | localhost | 57637 - 7 | users_1200023 | localhost | 57638 - 8 | users_1200022 | localhost | 57637 - 9 | users_1200025 | localhost | 57638 - 10 | users_1200022 | localhost | 57637 + id | shard_name | nodename | nodeport +--------------------------------------------------------------------- + 1 | multi_modifying_xacts.users_1200022 | localhost | 57637 + 2 | multi_modifying_xacts.users_1200025 | localhost | 57638 + 3 | multi_modifying_xacts.users_1200023 | localhost | 57638 + 4 | multi_modifying_xacts.users_1200023 | localhost | 57638 + 5 | multi_modifying_xacts.users_1200022 | localhost | 57637 + 6 | multi_modifying_xacts.users_1200024 | localhost | 57637 + 7 | multi_modifying_xacts.users_1200023 | localhost | 57638 + 8 | multi_modifying_xacts.users_1200022 | localhost | 57637 + 9 | multi_modifying_xacts.users_1200025 | localhost | 57638 + 10 | multi_modifying_xacts.users_1200022 | localhost | 57637 (10 rows) END; @@ -1546,5 +1581,5 @@ SELECT name FROM labs WHERE id = 1001; (1 row) RESET citus.function_opens_transaction_block; -DROP FUNCTION insert_abort(); -DROP TABLE items, users, itemgroups, usergroups, researchers, labs; +SET client_min_messages TO WARNING; +DROP SCHEMA multi_modifying_xacts CASCADE; diff --git a/src/test/regress/expected/multi_mx_copy_data.out b/src/test/regress/expected/multi_mx_copy_data.out index c1d3d71806c..5cd3426b31e 100644 --- a/src/test/regress/expected/multi_mx_copy_data.out +++ b/src/test/regress/expected/multi_mx_copy_data.out @@ -1,6 +1,7 @@ -- -- MULTI_MX_COPY_DATA -- +TRUNCATE lineitem_mx, orders_mx; \set nation_data_file :abs_srcdir '/data/nation.data' \set client_side_copy_command '\\copy nation_hash FROM ' :'nation_data_file' ' with delimiter '''|''';' :client_side_copy_command @@ -161,3 +162,4 @@ SET search_path TO public; :client_side_copy_command \set client_side_copy_command '\\copy supplier_mx FROM ' :'supplier_data_file' ' with delimiter '''|''';' :client_side_copy_command +DROP TABLE citus_mx_test_schema.nation_hash_replicated; diff --git a/src/test/regress/expected/multi_mx_modifying_xacts.out b/src/test/regress/expected/multi_mx_modifying_xacts.out index e486b8b1b21..dfbdc760370 100644 --- a/src/test/regress/expected/multi_mx_modifying_xacts.out +++ b/src/test/regress/expected/multi_mx_modifying_xacts.out @@ -406,3 +406,6 @@ SELECT * FROM labs_mx WHERE id = 8; --------------------------------------------------------------------- (0 rows) +TRUNCATE objects_mx, labs_mx, researchers_mx; +DROP TRIGGER reject_bad_mx ON labs_mx_1220102; +DROP FUNCTION reject_bad_mx; diff --git a/src/test/regress/expected/multi_mx_router_planner.out b/src/test/regress/expected/multi_mx_router_planner.out index d006b4bb828..bf007be9d8b 100644 --- a/src/test/regress/expected/multi_mx_router_planner.out +++ b/src/test/regress/expected/multi_mx_router_planner.out @@ -1460,3 +1460,7 @@ DEBUG: query has a single distribution column value: 1 51 (6 rows) +SET client_min_messages to WARNING; +TRUNCATE articles_hash_mx, company_employees_mx, articles_single_shard_hash_mx; +DROP MATERIALIZED VIEW mv_articles_hash_mx_error; +DROP TABLE authors_hash_mx; diff --git a/src/test/regress/expected/multi_router_planner.out b/src/test/regress/expected/multi_router_planner.out index 56ff44b3be1..5e9033a51f3 100644 --- a/src/test/regress/expected/multi_router_planner.out +++ b/src/test/regress/expected/multi_router_planner.out @@ -1981,7 +1981,7 @@ SELECT master_create_empty_shard('articles_append') AS shard_id \gset UPDATE pg_dist_shard SET shardmaxvalue = 100, shardminvalue=1 WHERE shardid = :shard_id; -- we execute the query within a function to consolidate the error messages -- between different executors -CREATE FUNCTION raise_failed_execution_router(query text) RETURNS void AS $$ +CREATE OR REPLACE FUNCTION raise_failed_execution_router(query text) RETURNS void AS $$ BEGIN EXECUTE query; EXCEPTION WHEN OTHERS THEN @@ -2452,7 +2452,7 @@ SELECT shardid, shardstate, nodename, nodeport FROM pg_dist_shard_placement SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'failure_test'::regclass ) - ORDER BY placementid; + ORDER BY shardid, nodeport; shardid | shardstate | nodename | nodeport --------------------------------------------------------------------- 840017 | 1 | localhost | 57637 diff --git a/src/test/regress/expected/multi_simple_queries.out b/src/test/regress/expected/multi_simple_queries.out index 6bd8bad4aa5..4578d69a800 100644 --- a/src/test/regress/expected/multi_simple_queries.out +++ b/src/test/regress/expected/multi_simple_queries.out @@ -7,6 +7,8 @@ SET citus.coordinator_aggregation_strategy TO 'disabled'; -- =================================================================== -- test end-to-end query functionality -- =================================================================== +CREATE SCHEMA simple_queries_test; +SET search_path TO simple_queries_test; CREATE TABLE articles ( id bigint NOT NULL, author_id bigint NOT NULL, @@ -382,7 +384,7 @@ SELECT author_id FROM articles 8 (3 rows) -SELECT o_orderstatus, count(*), avg(o_totalprice) FROM orders +SELECT o_orderstatus, count(*), avg(o_totalprice) FROM public.orders GROUP BY o_orderstatus HAVING count(*) > 1450 OR avg(o_totalprice) > 150000 ORDER BY o_orderstatus; @@ -392,7 +394,7 @@ SELECT o_orderstatus, count(*), avg(o_totalprice) FROM orders P | 75 | 164847.914533333333 (2 rows) -SELECT o_orderstatus, sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders +SELECT o_orderstatus, sum(l_linenumber), avg(l_linenumber) FROM public.lineitem, public.orders WHERE l_orderkey = o_orderkey AND l_orderkey > 9030 GROUP BY o_orderstatus HAVING sum(l_linenumber) > 1000 @@ -541,7 +543,7 @@ DEBUG: query has a single distribution column value: 2 -- error out on unsupported aggregate SET client_min_messages to 'NOTICE'; -CREATE AGGREGATE public.invalid(int) ( +CREATE AGGREGATE invalid(int) ( sfunc = int4pl, stype = int ); @@ -812,10 +814,11 @@ SELECT * FROM (SELECT nextval('query_seq') FROM articles LIMIT 3) vals; (3 rows) -- but not elsewhere -SELECT sum(nextval('query_seq')) FROM articles; -ERROR: relation "public.query_seq" does not exist +SELECT sum(nextval('simple_queries_test.query_seq')) FROM articles; +ERROR: relation "simple_queries_test.query_seq" does not exist CONTEXT: while executing command on localhost:xxxxx -SELECT n FROM (SELECT nextval('query_seq') n, random() FROM articles) vals; -ERROR: relation "public.query_seq" does not exist +SELECT n FROM (SELECT nextval('simple_queries_test.query_seq') n, random() FROM articles) vals; +ERROR: relation "simple_queries_test.query_seq" does not exist CONTEXT: while executing command on localhost:xxxxx -DROP SEQUENCE query_seq; +SET client_min_messages TO WARNING; +DROP SCHEMA simple_queries_test CASCADE; diff --git a/src/test/regress/expected/multi_upsert.out b/src/test/regress/expected/multi_upsert.out index 08308aba013..e41b2a3d5e0 100644 --- a/src/test/regress/expected/multi_upsert.out +++ b/src/test/regress/expected/multi_upsert.out @@ -1,5 +1,7 @@ -- this test file aims to test UPSERT feature on Citus SET citus.next_shard_id TO 980000; +CREATE SCHEMA upsert_test; +SET search_path TO upsert_test; CREATE TABLE upsert_test ( part_key int UNIQUE, @@ -244,3 +246,5 @@ ERROR: functions used in the WHERE clause of the ON CONFLICT clause of INSERTs INSERT INTO upsert_test (part_key, other_col) VALUES (1, 1) ON CONFLICT (part_key) DO UPDATE SET part_key = 15; ERROR: modifying the partition value of rows is not allowed +SET client_min_messages TO WARNING; +DROP SCHEMA upsert_test CASCADE; diff --git a/src/test/regress/sql/multi_data_types.sql b/src/test/regress/sql/multi_data_types.sql index 7601bb319af..d307c4c6fbf 100644 --- a/src/test/regress/sql/multi_data_types.sql +++ b/src/test/regress/sql/multi_data_types.sql @@ -6,6 +6,15 @@ SET citus.next_shard_id TO 530000; +-- Given that other test files depend on the existence of types created in this file, +-- we cannot drop them at the end. Instead, we drop them at the beginning of the test +-- to make this file runnable multiple times via run_test.py. +BEGIN; + SET LOCAL client_min_messages TO WARNING; + DROP TYPE IF EXISTS test_composite_type, other_composite_type, bug_status CASCADE; + DROP OPERATOR FAMILY IF EXISTS cats_op_fam USING hash; +COMMIT; + -- create a custom type... CREATE TYPE test_composite_type AS ( i integer, diff --git a/src/test/regress/sql/multi_modifying_xacts.sql b/src/test/regress/sql/multi_modifying_xacts.sql index 2be3a0911a0..50648009310 100644 --- a/src/test/regress/sql/multi_modifying_xacts.sql +++ b/src/test/regress/sql/multi_modifying_xacts.sql @@ -1,6 +1,9 @@ SET citus.next_shard_id TO 1200000; SET citus.next_placement_id TO 1200000; +CREATE SCHEMA multi_modifying_xacts; +SET search_path TO multi_modifying_xacts; + -- =================================================================== -- test end-to-end modification functionality -- =================================================================== @@ -169,7 +172,7 @@ INSERT INTO labs VALUES (6, 'Bell Labs'); ABORT; -- but the DDL should correctly roll back -SELECT "Column", "Type", "Modifiers" FROM table_desc WHERE relid='public.labs'::regclass; +SELECT "Column", "Type", "Modifiers" FROM public.table_desc WHERE relid='multi_modifying_xacts.labs'::regclass; SELECT * FROM labs WHERE id = 6; -- COPY can happen after single row INSERT @@ -294,7 +297,7 @@ CREATE FUNCTION reject_large_id() RETURNS trigger AS $rli$ $rli$ LANGUAGE plpgsql; -- register after insert trigger -SELECT * FROM run_command_on_placements('researchers', 'CREATE CONSTRAINT TRIGGER reject_large_researcher_id AFTER INSERT ON %s DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_large_id()') +SELECT * FROM run_command_on_placements('multi_modifying_xacts.researchers', 'CREATE CONSTRAINT TRIGGER reject_large_researcher_id AFTER INSERT ON %s DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE multi_modifying_xacts.reject_large_id()') ORDER BY nodeport, shardid; -- hide postgresql version dependend messages for next test only @@ -418,6 +421,7 @@ AND s.logicalrelid = 'objects'::regclass; -- create trigger on one worker to reject certain values \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ @@ -437,6 +441,7 @@ DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- test partial failure; worker_1 succeeds, 2 fails -- in this case, we expect the transaction to abort @@ -465,6 +470,7 @@ DELETE FROM objects; -- there cannot be errors on different shards at different times -- because the first failure will fail the whole transaction \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ BEGIN @@ -483,6 +489,7 @@ DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; BEGIN; INSERT INTO objects VALUES (1, 'apple'); @@ -506,6 +513,7 @@ AND (s.logicalrelid = 'objects'::regclass OR -- what if the failures happen at COMMIT time? \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON objects_1200003; @@ -515,6 +523,7 @@ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- should be the same story as before, just at COMMIT time -- as we use 2PC, the transaction is rollbacked @@ -547,6 +556,7 @@ AND s.logicalrelid = 'objects'::regclass; -- what if all nodes have failures at COMMIT time? \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON labs_1200002; @@ -556,6 +566,7 @@ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- reduce the log level for differences between PG14 and PG15 -- in PGconn->errorMessage @@ -586,10 +597,12 @@ AND (s.logicalrelid = 'objects'::regclass OR -- what if one shard (objects) succeeds but another (labs) completely fails? \c - - - :worker_2_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad ON objects_1200003; \c - - - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200004; BEGIN; INSERT INTO objects VALUES (1, 'apple'); @@ -682,6 +695,7 @@ SELECT * FROM reference_modifying_xacts; -- lets fail on of the workers at before the commit time \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad_reference() RETURNS trigger AS $rb$ BEGIN @@ -700,6 +714,7 @@ DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- try without wrapping inside a transaction INSERT INTO reference_modifying_xacts VALUES (999, 3); @@ -711,6 +726,7 @@ COMMIT; -- lets fail one of the workers at COMMIT time \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_reference ON reference_modifying_xacts_1200006; CREATE CONSTRAINT TRIGGER reject_bad_reference @@ -719,6 +735,7 @@ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- try without wrapping inside a transaction @@ -740,10 +757,12 @@ ORDER BY s.logicalrelid, sp.shardstate; -- for the time-being drop the constraint \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_reference ON reference_modifying_xacts_1200006; \c - - - :master_port +SET search_path TO multi_modifying_xacts; -- now create a hash distributed table and run tests -- including both the reference table and the hash @@ -777,6 +796,7 @@ ABORT; -- lets fail one of the workers before COMMIT time for the hash table \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.enable_metadata_sync TO OFF; CREATE FUNCTION reject_bad_hash() RETURNS trigger AS $rb$ BEGIN @@ -795,6 +815,7 @@ DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- the transaction as a whole should fail @@ -809,6 +830,7 @@ SELECT * FROM reference_modifying_xacts WHERE key = 55; -- now lets fail on of the workers for the hash distributed table table -- when there is a reference table involved \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; DROP TRIGGER reject_bad_hash ON hash_modifying_xacts_1200007; -- the trigger is on execution time @@ -818,6 +840,7 @@ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse -- the transaction as a whole should fail @@ -844,6 +867,7 @@ ORDER BY s.logicalrelid, sp.shardstate; -- change is rollbacked as well \c - - - :worker_1_port +SET search_path TO multi_modifying_xacts; CREATE CONSTRAINT TRIGGER reject_bad_reference AFTER INSERT ON reference_modifying_xacts_1200006 @@ -851,6 +875,7 @@ DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE reject_bad_reference(); \c - - - :master_port +SET search_path TO multi_modifying_xacts; \set VERBOSITY terse BEGIN; @@ -920,9 +945,11 @@ SELECT count(*) FROM pg_dist_transaction; -- first create the new user on all nodes CREATE USER test_user; +GRANT ALL ON SCHEMA multi_modifying_xacts TO test_user; -- now connect back to the master with the new user \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200015; CREATE TABLE reference_failure_test (key int, value int); SELECT create_reference_table('reference_failure_test'); @@ -934,16 +961,19 @@ SELECT create_distributed_table('numbers_hash_failure_test', 'key'); -- ensure that the shard is created for this user \c - test_user - :worker_1_port +SET search_path TO multi_modifying_xacts; SET citus.override_table_visibility TO false; \dt reference_failure_test_1200015 -- now connect with the default user, -- and rename the existing user \c - :default_user - :worker_1_port +SET search_path TO multi_modifying_xacts; ALTER USER test_user RENAME TO test_user_new; -- connect back to master and query the reference table \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; -- should fail since the worker doesn't have test_user anymore INSERT INTO reference_failure_test VALUES (1, '1'); @@ -1007,15 +1037,18 @@ SELECT count(*) FROM numbers_hash_failure_test; -- break the other node as well \c - :default_user - :worker_2_port +SET search_path TO multi_modifying_xacts; ALTER USER test_user RENAME TO test_user_new; \c - test_user - :master_port +SET search_path TO multi_modifying_xacts; -- fails on all shard placements INSERT INTO numbers_hash_failure_test VALUES (2,2); -- connect back to the master with the proper user to continue the tests \c - :default_user - :master_port +SET search_path TO multi_modifying_xacts; SET citus.next_shard_id TO 1200020; SET citus.next_placement_id TO 1200033; -- unbreak both nodes by renaming the user back to the original name @@ -1024,6 +1057,7 @@ SELECT * FROM run_command_on_workers('ALTER USER test_user_new RENAME TO test_us DROP TABLE reference_modifying_xacts, hash_modifying_xacts, hash_modifying_xacts_second, reference_failure_test, numbers_hash_failure_test; +REVOKE ALL ON SCHEMA multi_modifying_xacts FROM test_user; DROP USER test_user; -- set up foreign keys to test transactions with co-located and reference tables @@ -1043,7 +1077,10 @@ CREATE TABLE itemgroups ( ); SELECT create_reference_table('itemgroups'); +SET client_min_messages TO WARNING; DROP TABLE IF EXISTS users ; +RESET client_min_messages; + CREATE TABLE users ( id int PRIMARY KEY, name text, @@ -1199,5 +1236,5 @@ SELECT insert_abort(); SELECT name FROM labs WHERE id = 1001; RESET citus.function_opens_transaction_block; -DROP FUNCTION insert_abort(); -DROP TABLE items, users, itemgroups, usergroups, researchers, labs; +SET client_min_messages TO WARNING; +DROP SCHEMA multi_modifying_xacts CASCADE; diff --git a/src/test/regress/sql/multi_mx_copy_data.sql b/src/test/regress/sql/multi_mx_copy_data.sql index 26d4d3c4214..90ed80b5d09 100644 --- a/src/test/regress/sql/multi_mx_copy_data.sql +++ b/src/test/regress/sql/multi_mx_copy_data.sql @@ -2,6 +2,8 @@ -- MULTI_MX_COPY_DATA -- +TRUNCATE lineitem_mx, orders_mx; + \set nation_data_file :abs_srcdir '/data/nation.data' \set client_side_copy_command '\\copy nation_hash FROM ' :'nation_data_file' ' with delimiter '''|''';' :client_side_copy_command @@ -96,3 +98,5 @@ SET search_path TO public; :client_side_copy_command \set client_side_copy_command '\\copy supplier_mx FROM ' :'supplier_data_file' ' with delimiter '''|''';' :client_side_copy_command + +DROP TABLE citus_mx_test_schema.nation_hash_replicated; diff --git a/src/test/regress/sql/multi_mx_modifying_xacts.sql b/src/test/regress/sql/multi_mx_modifying_xacts.sql index cf60f023da4..15335f57926 100644 --- a/src/test/regress/sql/multi_mx_modifying_xacts.sql +++ b/src/test/regress/sql/multi_mx_modifying_xacts.sql @@ -331,3 +331,7 @@ COMMIT; -- no data should persists SELECT * FROM objects_mx WHERE id = 1; SELECT * FROM labs_mx WHERE id = 8; + +TRUNCATE objects_mx, labs_mx, researchers_mx; +DROP TRIGGER reject_bad_mx ON labs_mx_1220102; +DROP FUNCTION reject_bad_mx; diff --git a/src/test/regress/sql/multi_mx_router_planner.sql b/src/test/regress/sql/multi_mx_router_planner.sql index fdfd81b0788..6a1271720f9 100644 --- a/src/test/regress/sql/multi_mx_router_planner.sql +++ b/src/test/regress/sql/multi_mx_router_planner.sql @@ -657,3 +657,8 @@ INSERT INTO articles_hash_mx VALUES (51, 1, 'amateus', 1814); SELECT id FROM articles_hash_mx WHERE author_id = 1; + +SET client_min_messages to WARNING; +TRUNCATE articles_hash_mx, company_employees_mx, articles_single_shard_hash_mx; +DROP MATERIALIZED VIEW mv_articles_hash_mx_error; +DROP TABLE authors_hash_mx; diff --git a/src/test/regress/sql/multi_router_planner.sql b/src/test/regress/sql/multi_router_planner.sql index 87104599cce..dd03ed0b349 100644 --- a/src/test/regress/sql/multi_router_planner.sql +++ b/src/test/regress/sql/multi_router_planner.sql @@ -929,7 +929,7 @@ UPDATE pg_dist_shard SET shardmaxvalue = 100, shardminvalue=1 WHERE shardid = :s -- we execute the query within a function to consolidate the error messages -- between different executors -CREATE FUNCTION raise_failed_execution_router(query text) RETURNS void AS $$ +CREATE OR REPLACE FUNCTION raise_failed_execution_router(query text) RETURNS void AS $$ BEGIN EXECUTE query; EXCEPTION WHEN OTHERS THEN @@ -1199,7 +1199,7 @@ SELECT shardid, shardstate, nodename, nodeport FROM pg_dist_shard_placement SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'failure_test'::regclass ) - ORDER BY placementid; + ORDER BY shardid, nodeport; \c - postgres - :worker_1_port DROP OWNED BY router_user; DROP USER router_user; diff --git a/src/test/regress/sql/multi_simple_queries.sql b/src/test/regress/sql/multi_simple_queries.sql index 8d7e45255cc..7fcf45b1c8a 100644 --- a/src/test/regress/sql/multi_simple_queries.sql +++ b/src/test/regress/sql/multi_simple_queries.sql @@ -11,6 +11,9 @@ SET citus.coordinator_aggregation_strategy TO 'disabled'; -- test end-to-end query functionality -- =================================================================== +CREATE SCHEMA simple_queries_test; +SET search_path TO simple_queries_test; + CREATE TABLE articles ( id bigint NOT NULL, author_id bigint NOT NULL, @@ -203,12 +206,12 @@ SELECT author_id FROM articles HAVING author_id <= 2 OR author_id = 8 ORDER BY author_id; -SELECT o_orderstatus, count(*), avg(o_totalprice) FROM orders +SELECT o_orderstatus, count(*), avg(o_totalprice) FROM public.orders GROUP BY o_orderstatus HAVING count(*) > 1450 OR avg(o_totalprice) > 150000 ORDER BY o_orderstatus; -SELECT o_orderstatus, sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders +SELECT o_orderstatus, sum(l_linenumber), avg(l_linenumber) FROM public.lineitem, public.orders WHERE l_orderkey = o_orderkey AND l_orderkey > 9030 GROUP BY o_orderstatus HAVING sum(l_linenumber) > 1000 @@ -277,7 +280,7 @@ SELECT avg(word_count) -- error out on unsupported aggregate SET client_min_messages to 'NOTICE'; -CREATE AGGREGATE public.invalid(int) ( +CREATE AGGREGATE invalid(int) ( sfunc = int4pl, stype = int ); @@ -355,7 +358,8 @@ SELECT nextval('query_seq')*2 FROM articles LIMIT 3; SELECT * FROM (SELECT nextval('query_seq') FROM articles LIMIT 3) vals; -- but not elsewhere -SELECT sum(nextval('query_seq')) FROM articles; -SELECT n FROM (SELECT nextval('query_seq') n, random() FROM articles) vals; +SELECT sum(nextval('simple_queries_test.query_seq')) FROM articles; +SELECT n FROM (SELECT nextval('simple_queries_test.query_seq') n, random() FROM articles) vals; -DROP SEQUENCE query_seq; +SET client_min_messages TO WARNING; +DROP SCHEMA simple_queries_test CASCADE; diff --git a/src/test/regress/sql/multi_upsert.sql b/src/test/regress/sql/multi_upsert.sql index 24503b7a4da..6ef72d57684 100644 --- a/src/test/regress/sql/multi_upsert.sql +++ b/src/test/regress/sql/multi_upsert.sql @@ -3,6 +3,8 @@ SET citus.next_shard_id TO 980000; +CREATE SCHEMA upsert_test; +SET search_path TO upsert_test; CREATE TABLE upsert_test ( @@ -207,3 +209,6 @@ INSERT INTO upsert_test (part_key, other_col) VALUES (1, 1) ON CONFLICT (part_ke -- error out on attempt to update the partition key INSERT INTO upsert_test (part_key, other_col) VALUES (1, 1) ON CONFLICT (part_key) DO UPDATE SET part_key = 15; + +SET client_min_messages TO WARNING; +DROP SCHEMA upsert_test CASCADE;