From dceaddbe4de87819f117e66d65c2463d702101dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Kalac=C4=B1?= Date: Fri, 25 Oct 2019 10:54:54 +0200 Subject: [PATCH] Remove real-time/router executors (step 1) (#3125) See #3125 for details on each item. * Remove real-time/router executor tests-1 These are the ones which doesn't have '_%d' in the test output files. * Remove real-time/router executor tests-2 These are the ones which has in the test output files. * Move the tests outputs to correct place * Make sure that single shard commits use 2PC on adaptive executor It looks like we've messed the tests in #2891. Fixing back. * Use adaptive executor for all router queries This becomes important because when task-tracker is picked, we used to pick router executor, which doesn't make sense. * Remove explicit references to real-time/router executors in the tests * JobExecutorType never picks real-time/router executors * Make sure to go incremental in test output numbers * Even users cannot pick real-time anymore * Do not use real-time/router custom scans * Get rid of unnecessary normalizations * Reflect unneeded normalizations * Get rid of unnecessary test output file --- .../executor/multi_server_executor.c | 56 +- .../distributed/planner/distributed_planner.c | 12 - src/backend/distributed/shared_library_init.c | 2 +- src/test/regress/bin/normalize.sed | 9 +- .../expected/failure_1pc_copy_append_9.out | 294 -- .../failure_connection_establishment.out | 5 +- .../failure_connection_establishment_9.out | 244 -- ...ure_create_distributed_table_non_empty.out | 48 +- ...e_create_distributed_table_non_empty_9.out | 1003 ------ .../failure_create_reference_table.out | 18 +- .../failure_create_reference_table_9.out | 255 -- .../regress/expected/failure_create_table.out | 79 +- .../expected/failure_create_table_9.out | 713 ----- .../regress/expected/failure_cte_subquery.out | 23 +- .../expected/failure_cte_subquery_9.out | 393 --- src/test/regress/expected/failure_ddl.out | 40 +- src/test/regress/expected/failure_ddl_9.out | 1109 ------- .../failure_insert_select_pushdown.out | 8 +- .../failure_insert_select_pushdown_9.out | 150 - .../failure_insert_select_via_coordinator.out | 16 +- ...ailure_insert_select_via_coordinator_9.out | 229 -- .../regress/expected/failure_multi_dml.out | 12 +- .../regress/expected/failure_multi_dml_9.out | 490 --- .../expected/failure_multi_row_insert.out | 20 +- .../expected/failure_multi_row_insert_9.out | 158 - .../failure_multi_shard_update_delete.out | 64 +- .../failure_multi_shard_update_delete_9.out | 694 ---- .../expected/failure_real_time_select.out | 52 +- .../expected/failure_real_time_select_9.out | 314 -- .../regress/expected/failure_ref_tables.out | 12 +- .../regress/expected/failure_ref_tables_9.out | 99 - .../regress/expected/failure_savepoints.out | 77 +- .../regress/expected/failure_savepoints_9.out | 353 --- .../regress/expected/failure_single_mod.out | 18 +- .../regress/expected/failure_single_mod_9.out | 128 - .../expected/failure_single_select_9.out | 247 -- .../regress/expected/failure_truncate.out | 31 +- .../regress/expected/failure_truncate_9.out | 1299 -------- src/test/regress/expected/failure_vacuum.out | 17 +- ...lure_vacuum_8.out => failure_vacuum_1.out} | 0 .../regress/expected/failure_vacuum_9.out | 133 - .../isolation_citus_dist_activity_9.out | 229 -- .../isolation_dump_global_wait_edges_9.out | 98 - .../expected/local_shard_execution.out | 62 - .../regress/expected/multi_insert_select.out | 2 - .../expected/multi_insert_select_9.out | 2820 ----------------- .../regress/expected/multi_join_pruning.out | 18 +- .../regress/expected/multi_modifications.out | 8 +- .../expected/multi_modifications_9.out | 1291 -------- .../expected/multi_modifying_xacts.out | 22 +- .../expected/multi_modifying_xacts_9.out | 1584 --------- .../expected/multi_partition_pruning.out | 6 +- .../regress/expected/multi_partitioning.out | 22 +- .../regress/expected/multi_partitioning_1.out | 1935 ----------- .../multi_subquery_window_functions.out | 2 +- .../regress/expected/with_transactions.out | 6 +- .../regress/expected/with_transactions_9.out | 126 - .../regress/sql/local_shard_execution.sql | 60 - 58 files changed, 320 insertions(+), 16895 deletions(-) delete mode 100644 src/test/regress/expected/failure_1pc_copy_append_9.out delete mode 100644 src/test/regress/expected/failure_connection_establishment_9.out delete mode 100644 src/test/regress/expected/failure_create_distributed_table_non_empty_9.out delete mode 100644 src/test/regress/expected/failure_create_reference_table_9.out delete mode 100644 src/test/regress/expected/failure_create_table_9.out delete mode 100644 src/test/regress/expected/failure_cte_subquery_9.out delete mode 100644 src/test/regress/expected/failure_ddl_9.out delete mode 100644 src/test/regress/expected/failure_insert_select_pushdown_9.out delete mode 100644 src/test/regress/expected/failure_insert_select_via_coordinator_9.out delete mode 100644 src/test/regress/expected/failure_multi_dml_9.out delete mode 100644 src/test/regress/expected/failure_multi_row_insert_9.out delete mode 100644 src/test/regress/expected/failure_multi_shard_update_delete_9.out delete mode 100644 src/test/regress/expected/failure_real_time_select_9.out delete mode 100644 src/test/regress/expected/failure_ref_tables_9.out delete mode 100644 src/test/regress/expected/failure_savepoints_9.out delete mode 100644 src/test/regress/expected/failure_single_mod_9.out delete mode 100644 src/test/regress/expected/failure_single_select_9.out delete mode 100644 src/test/regress/expected/failure_truncate_9.out rename src/test/regress/expected/{failure_vacuum_8.out => failure_vacuum_1.out} (100%) delete mode 100644 src/test/regress/expected/failure_vacuum_9.out delete mode 100644 src/test/regress/expected/isolation_citus_dist_activity_9.out delete mode 100644 src/test/regress/expected/isolation_dump_global_wait_edges_9.out delete mode 100644 src/test/regress/expected/multi_insert_select_9.out delete mode 100644 src/test/regress/expected/multi_modifications_9.out delete mode 100644 src/test/regress/expected/multi_modifying_xacts_9.out delete mode 100644 src/test/regress/expected/multi_partitioning_1.out delete mode 100644 src/test/regress/expected/with_transactions_9.out diff --git a/src/backend/distributed/executor/multi_server_executor.c b/src/backend/distributed/executor/multi_server_executor.c index dfac02c43..1a5878c48 100644 --- a/src/backend/distributed/executor/multi_server_executor.c +++ b/src/backend/distributed/executor/multi_server_executor.c @@ -45,14 +45,10 @@ MultiExecutorType JobExecutorType(DistributedPlan *distributedPlan) { Job *job = distributedPlan->workerJob; - List *workerNodeList = NIL; - int workerNodeCount = 0; - int taskCount = 0; - double tasksPerNode = 0.; MultiExecutorType executorType = TaskExecutorType; bool routerExecutablePlan = distributedPlan->routerExecutable; - /* check if can switch to router executor */ + /* debug distribution column value */ if (routerExecutablePlan) { if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2) @@ -76,12 +72,7 @@ JobExecutorType(DistributedPlan *distributedPlan) } } - if (TaskExecutorType == MULTI_EXECUTOR_ADAPTIVE) - { - return TaskExecutorType; - } - - return MULTI_EXECUTOR_ROUTER; + return MULTI_EXECUTOR_ADAPTIVE; } if (distributedPlan->insertSelectSubquery != NULL) @@ -97,43 +88,7 @@ JobExecutorType(DistributedPlan *distributedPlan) Assert(distributedPlan->modLevel == ROW_MODIFY_READONLY); - workerNodeList = ActiveReadableNodeList(); - workerNodeCount = list_length(workerNodeList); - taskCount = list_length(job->taskList); - tasksPerNode = taskCount / ((double) workerNodeCount); - - if (executorType == MULTI_EXECUTOR_REAL_TIME) - { - double reasonableConnectionCount = 0; - - /* if we need to open too many connections per worker, warn the user */ - if (tasksPerNode >= MaxConnections) - { - ereport(WARNING, (errmsg("this query uses more connections than the " - "configured max_connections limit"), - errhint("Consider increasing max_connections or setting " - "citus.task_executor_type to " - "\"task-tracker\"."))); - } - - /* - * If we need to open too many outgoing connections, warn the user. - * The real-time executor caps the number of tasks it starts by the same limit, - * but we still issue this warning because it degrades performance. - */ - reasonableConnectionCount = MaxMasterConnectionCount(); - if (taskCount >= reasonableConnectionCount) - { - ereport(WARNING, (errmsg("this query uses more file descriptors than the " - "configured max_files_per_process limit"), - errhint("Consider increasing max_files_per_process or " - "setting citus.task_executor_type to " - "\"task-tracker\"."))); - } - } - - if (executorType == MULTI_EXECUTOR_REAL_TIME || - executorType == MULTI_EXECUTOR_ADAPTIVE) + if (executorType == MULTI_EXECUTOR_ADAPTIVE) { /* if we have repartition jobs with real time executor and repartition * joins are not enabled, error out. Otherwise, switch to task-tracker @@ -158,6 +113,11 @@ JobExecutorType(DistributedPlan *distributedPlan) } else { + List *workerNodeList = ActiveReadableNodeList(); + int workerNodeCount = list_length(workerNodeList); + int taskCount = list_length(job->taskList); + double tasksPerNode = taskCount / ((double) workerNodeCount); + /* if we have more tasks per node than what can be tracked, warn the user */ if (tasksPerNode >= MaxTrackedTasksPerNode) { diff --git a/src/backend/distributed/planner/distributed_planner.c b/src/backend/distributed/planner/distributed_planner.c index 6cdd73bea..6c4061b25 100644 --- a/src/backend/distributed/planner/distributed_planner.c +++ b/src/backend/distributed/planner/distributed_planner.c @@ -984,24 +984,12 @@ FinalizePlan(PlannedStmt *localPlan, DistributedPlan *distributedPlan) break; } - case MULTI_EXECUTOR_REAL_TIME: - { - customScan->methods = &RealTimeCustomScanMethods; - break; - } - case MULTI_EXECUTOR_TASK_TRACKER: { customScan->methods = &TaskTrackerCustomScanMethods; break; } - case MULTI_EXECUTOR_ROUTER: - { - customScan->methods = &RouterCustomScanMethods; - break; - } - case MULTI_EXECUTOR_COORDINATOR_INSERT_SELECT: { customScan->methods = &CoordinatorInsertSelectCustomScanMethods; diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index 279400ecb..78e278a4e 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -112,7 +112,7 @@ static const struct config_enum_entry replication_model_options[] = { static const struct config_enum_entry task_executor_type_options[] = { { "adaptive", MULTI_EXECUTOR_ADAPTIVE, false }, - { "real-time", MULTI_EXECUTOR_REAL_TIME, false }, + { "real-time", MULTI_EXECUTOR_ADAPTIVE, false }, /* ignore real-time executor, always use adaptive */ { "task-tracker", MULTI_EXECUTOR_TASK_TRACKER, false }, { NULL, 0, false } }; diff --git a/src/test/regress/bin/normalize.sed b/src/test/regress/bin/normalize.sed index 6006fd820..3e2ebbc9c 100644 --- a/src/test/regress/bin/normalize.sed +++ b/src/test/regress/bin/normalize.sed @@ -16,6 +16,7 @@ s/node group [12] (but|does)/node group \1/ # Differing names can have differing table column widths s/(-+\|)+-+/---/g +s/.*-------------.*/---------------------------------------------------------------------/g # In foreign_key_to_reference_table, normalize shard table names, etc in # the generated plan @@ -47,14 +48,6 @@ s/name_len_12345678901234567890123456789012345678_fcd8ab6f_[0-9]+/name_len_12345 # normalize pkey constraints in multi_insert_select.sql s/"(raw_events_second_user_id_value_1_key_|agg_events_user_id_value_1_agg_key_)[0-9]+"/"\1xxxxxxx"/g -# normalize explain outputs, basically wipeout the executor name from the output -s/.*Custom Scan \(Citus.*/Custom Scan \(Citus\)/g -s/.*-------------.*/---------------------------------------------------------------------/g -s/.* QUERY PLAN .*/ QUERY PLAN /g -s/.*Custom Plan Provider.*Citus.*/ \"Custom Plan Provider\": \"Citus\", /g -s/.*Custom-Plan-Provide.*/\Citus Unified\<\/Custom-Plan-Provider\> /g -s/ +$//g - # normalize failed task ids s/ERROR: failed to execute task [0-9]+/ERROR: failed to execute task X/g diff --git a/src/test/regress/expected/failure_1pc_copy_append_9.out b/src/test/regress/expected/failure_1pc_copy_append_9.out deleted file mode 100644 index c9ac2c2d7..000000000 --- a/src/test/regress/expected/failure_1pc_copy_append_9.out +++ /dev/null @@ -1,294 +0,0 @@ -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- do not cache any connections -SET citus.max_cached_conns_per_worker TO 1; -SET citus.shard_count = 1; -SET citus.shard_replication_factor = 2; -- one shard per worker -SET citus.multi_shard_commit_protocol TO '1pc'; -SET citus.next_shard_id TO 100400; -ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 100; -CREATE TABLE copy_test (key int, value int); -SELECT create_distributed_table('copy_test', 'key', 'append'); - create_distributed_table --------------------------- - -(1 row) - -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - -SELECT citus.dump_network_traffic(); - dump_network_traffic ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - (0,coordinator,"[initial message]") - (0,worker,"['AuthenticationOk()', 'ParameterStatus(application_name=citus)', 'ParameterStatus(client_encoding=UTF8)', 'ParameterStatus(DateStyle=ISO, MDY)', 'ParameterStatus(integer_datetimes=on)', 'ParameterStatus(IntervalStyle=postgres)', 'ParameterStatus(is_superuser=on)', 'ParameterStatus(server_encoding=UTF8)', 'ParameterStatus(server_version=XXX)', 'ParameterStatus(session_authorization=postgres)', 'ParameterStatus(standard_conforming_strings=on)', 'ParameterStatus(TimeZone=XXX)', 'BackendKeyData(XXX)', 'ReadyForQuery(state=idle)']") - (0,coordinator,"[""Query(query=SELECT worker_apply_shard_ddl_command (100400, 'CREATE TABLE public.copy_test (key integer, value integer)'))""]") - (0,worker,"[""RowDescription(fieldcount=1,fields=['F(name=worker_apply_shard_ddl_command,tableoid=0,colattrnum=0,typoid=2278,typlen=4,typmod=-1,format_code=0)'])"", 'DataRow(columncount=1,columns=[""C(length=0,value=b\\'\\')""])', 'CommandComplete(command=SELECT 1)', 'ReadyForQuery(state=idle)']") - (0,coordinator,"[""Query(query=SELECT worker_apply_shard_ddl_command (100400, 'ALTER TABLE public.copy_test OWNER TO postgres'))""]") - (0,worker,"[""RowDescription(fieldcount=1,fields=['F(name=worker_apply_shard_ddl_command,tableoid=0,colattrnum=0,typoid=2278,typlen=4,typmod=-1,format_code=0)'])"", 'DataRow(columncount=1,columns=[""C(length=0,value=b\\'\\')""])', 'CommandComplete(command=SELECT 1)', 'ReadyForQuery(state=idle)']") - (0,coordinator,"[""Query(query=BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(0, XX, 'XXXX-XX-XX XX:XX:XX.XXXXXX-XX');)""]") - (0,worker,"['CommandComplete(command=BEGIN)', ""RowDescription(fieldcount=1,fields=['F(name=assign_distributed_transaction_id,tableoid=0,colattrnum=0,typoid=2278,typlen=4,typmod=-1,format_code=0)'])"", 'DataRow(columncount=1,columns=[""C(length=0,value=b\\'\\')""])', 'CommandComplete(command=SELECT 1)', 'ReadyForQuery(state=in_transaction_block)']") - (0,coordinator,"['Query(query=COPY public.copy_test_XXXXXX FROM STDIN WITH (FORMAT BINARY))']") - (0,worker,"[""Backend(type=G,body=b'\\\\x01\\\\x00\\\\x02\\\\x00\\\\x01\\\\x00\\\\x01')""]") - (0,coordinator,"[""CopyData(data=b'PGCOPY\\\\n\\\\xff\\\\r\\\\n\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00')"", ""CopyData(data=b'\\\\x00\\\\x02\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x00')"", ""CopyData(data=b'\\\\x00\\\\x02\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x01\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x01')"", ""CopyData(data=b'\\\\x00\\\\x02\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x02\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x04')"", ""CopyData(data=b'\\\\x00\\\\x02\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\x03\\\\x00\\\\x00\\\\x00\\\\x04\\\\x00\\\\x00\\\\x00\\\\t')"", ""CopyData(data=b'\\\\xff\\\\xff')"", 'CopyDone()']") - (0,worker,"['CommandComplete(command=COPY 4)', 'ReadyForQuery(state=in_transaction_block)']") - (0,coordinator,"[""Query(query=SELECT pg_table_size('public.copy_test_XXXXXX'))""]") - (0,worker,"[""RowDescription(fieldcount=1,fields=['F(name=pg_table_size,tableoid=0,colattrnum=0,typoid=20,typlen=8,typmod=-1,format_code=0)'])"", 'DataRow(columncount=1,columns=[""C(length=0,value=b\\'\\')""])', 'CommandComplete(command=SELECT 1)', 'ReadyForQuery(state=in_transaction_block)']") - (0,coordinator,"['Query(query=SELECT min(key), max(key) FROM public.copy_test_XXXXXX)']") - (0,worker,"[""RowDescription(fieldcount=2,fields=['F(name=min,tableoid=0,colattrnum=0,typoid=23,typlen=4,typmod=-1,format_code=0)', 'F(name=max,tableoid=0,colattrnum=0,typoid=23,typlen=4,typmod=-1,format_code=0)'])"", 'DataRow(columncount=2,columns=[""C(length=0,value=b\\'\\')"", ""C(length=1,value=b\\'0\\')""])', 'CommandComplete(command=SELECT 1)', 'ReadyForQuery(state=in_transaction_block)']") - (0,coordinator,"['Query(query=COMMIT)']") - (0,worker,"['CommandComplete(command=COMMIT)', 'ReadyForQuery(state=idle)']") - (0,coordinator,"['Query(query=COPY (SELECT count(1) AS count FROM copy_test_100400 copy_test WHERE true) TO STDOUT)']") - (0,worker,"[""CopyOutResponse(format=0,columncount=1,columns=['Anonymous(format=0)'])"", ""CopyData(data=b'4\\\\n')"", 'CopyDone()', 'CommandComplete(command=COPY 1)', 'ReadyForQuery(state=idle)']") -(20 rows) - ----- all of the following tests test behavior with 2 shard placements ---- -SHOW citus.shard_replication_factor; - citus.shard_replication_factor --------------------------------- - 2 -(1 row) - ----- kill the connection when we try to create the shard ---- -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - ----- kill the connection when we try to start a transaction ---- -SELECT citus.mitmproxy('conn.onQuery(query="assign_distributed_transaction_id").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -ERROR: failure on connection marked as essential: localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - ----- kill the connection when we start the COPY ---- -SELECT citus.mitmproxy('conn.onQuery(query="FROM STDIN WITH").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - ----- kill the connection when we send the data ---- -SELECT citus.mitmproxy('conn.onCopyData().kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -ERROR: failed to COPY to shard 100404 on localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT count(1) FROM copy_test; -WARNING: could not consume data from worker node - count -------- - 4 -(1 row) - ----- cancel the connection when we send the data ---- -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -ERROR: canceling statement due to user request -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; -ERROR: canceling statement due to user request ----- kill the connection when we try to get the size of the table ---- -SELECT citus.mitmproxy('conn.onQuery(query="pg_table_size").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -ERROR: failure on connection marked as essential: localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - ----- kill the connection when we try to get the min, max of the table ---- -SELECT citus.mitmproxy('conn.onQuery(query="SELECT min\(key\), max\(key\)").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -ERROR: failure on connection marked as essential: localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 -(2 rows) - -SELECT count(1) FROM copy_test; - count -------- - 4 -(1 row) - ----- kill the connection when we try to COMMIT ---- -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -COPY copy_test FROM PROGRAM 'echo 0, 0 && echo 1, 1 && echo 2, 4 && echo 3, 9' WITH CSV; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT * FROM pg_dist_shard s, pg_dist_shard_placement p - WHERE (s.shardid = p.shardid) AND s.logicalrelid = 'copy_test'::regclass - ORDER BY placementid; - logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue | shardid | shardstate | shardlength | nodename | nodeport | placementid ---------------+---------+--------------+---------------+---------------+---------+------------+-------------+-----------+----------+------------- - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 57637 | 100 - copy_test | 100400 | t | 0 | 3 | 100400 | 1 | 8192 | localhost | 9060 | 101 - copy_test | 100408 | t | 0 | 3 | 100408 | 1 | 8192 | localhost | 57637 | 112 - copy_test | 100408 | t | 0 | 3 | 100408 | 3 | 8192 | localhost | 9060 | 113 -(4 rows) - -SELECT count(1) FROM copy_test; - count -------- - 8 -(1 row) - --- ==== Clean up, we're done here ==== -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE copy_test; diff --git a/src/test/regress/expected/failure_connection_establishment.out b/src/test/regress/expected/failure_connection_establishment.out index 6dc419197..bbb430e22 100644 --- a/src/test/regress/expected/failure_connection_establishment.out +++ b/src/test/regress/expected/failure_connection_establishment.out @@ -44,8 +44,7 @@ SELECT citus.mitmproxy('conn.delay(500)'); (1 row) ALTER TABLE products ADD CONSTRAINT p_key PRIMARY KEY(product_no); -WARNING: could not establish connection after 400 ms -ERROR: connection error: localhost:9060 +ERROR: could not establish any connections to the node localhost:9060 after 400 ms SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -170,7 +169,7 @@ SELECT citus.mitmproxy('conn.delay(500)'); (1 row) SELECT count(*) FROM single_replicatated; -ERROR: failed to execute task 1 +ERROR: could not establish any connections to the node localhost:9060 after 400 ms SET citus.force_max_query_parallelization TO OFF; -- one similar test, but this time on modification queries -- to see that connection establishement failures could diff --git a/src/test/regress/expected/failure_connection_establishment_9.out b/src/test/regress/expected/failure_connection_establishment_9.out deleted file mode 100644 index bbb430e22..000000000 --- a/src/test/regress/expected/failure_connection_establishment_9.out +++ /dev/null @@ -1,244 +0,0 @@ --- --- failure_connection_establishment.sql tests some behaviour of connection management when --- it fails to connect. --- --- Failure cases covered: --- - timeout --- -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE SCHEMA fail_connect; -SET search_path TO 'fail_connect'; -SET citus.shard_count TO 4; -SET citus.max_cached_conns_per_worker TO 0; -ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1450000; -ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 1450000; -CREATE TABLE products ( - product_no integer, - name text, - price numeric -); -SELECT create_distributed_table('products', 'product_no'); - create_distributed_table --------------------------- - -(1 row) - --- Can only add primary key constraint on distribution column (or group of columns --- including distribution column) --- Command below should error out since 'name' is not a distribution column -ALTER TABLE products ADD CONSTRAINT p_key PRIMARY KEY(name); -ERROR: cannot create constraint on "products" -DETAIL: Distributed relations cannot have UNIQUE, EXCLUDE, or PRIMARY KEY constraints that do not include the partition column (with an equality operator if EXCLUDE). --- we will insert a connection delay here as this query was the cause for an investigation --- into connection establishment problems -SET citus.node_connection_timeout TO 400; -SELECT citus.mitmproxy('conn.delay(500)'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE products ADD CONSTRAINT p_key PRIMARY KEY(product_no); -ERROR: could not establish any connections to the node localhost:9060 after 400 ms -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE r1 ( - id int PRIMARY KEY, - name text -); -INSERT INTO r1 (id, name) VALUES -(1,'foo'), -(2,'bar'), -(3,'baz'); -SELECT create_reference_table('r1'); -NOTICE: Copying data from local table... - create_reference_table ------------------------- - -(1 row) - -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -SELECT citus.mitmproxy('conn.delay(500)'); - mitmproxy ------------ - -(1 row) - --- we cannot control which replica of the reference table will be queried and there is --- only one specific client we can control the connection for. --- by using round-robin task_assignment_policy we can force to hit both machines. --- and in the end, dumping the network traffic shows that the connection establishment --- is initiated to the node behind the proxy -SET client_min_messages TO ERROR; -SET citus.task_assignment_policy TO 'round-robin'; --- suppress the warning since we can't control which shard is chose first. Failure of this --- test would be if one of the queries does not return the result but an error. -SELECT name FROM r1 WHERE id = 2; - name ------- - bar -(1 row) - -SELECT name FROM r1 WHERE id = 2; - name ------- - bar -(1 row) - --- verify a connection attempt was made to the intercepted node, this would have cause the --- connection to have been delayed and thus caused a timeout -SELECT citus.dump_network_traffic(); - dump_network_traffic -------------------------------------- - (0,coordinator,"[initial message]") -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- similar test with the above but this time on a --- distributed table instead of a reference table --- and with citus.force_max_query_parallelization is set -SET citus.force_max_query_parallelization TO ON; -SELECT citus.mitmproxy('conn.delay(500)'); - mitmproxy ------------ - -(1 row) - --- suppress the warning since we can't control which shard is chose first. Failure of this --- test would be if one of the queries does not return the result but an error. -SELECT count(*) FROM products; - count -------- - 0 -(1 row) - -SELECT count(*) FROM products; - count -------- - 0 -(1 row) - --- use OFFSET 1 to prevent printing the line where source --- is the worker -SELECT citus.dump_network_traffic() ORDER BY 1 OFFSET 1; - dump_network_traffic -------------------------------------- - (1,coordinator,"[initial message]") -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_replication_factor TO 1; -CREATE TABLE single_replicatated(key int); -SELECT create_distributed_table('single_replicatated', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- this time the table is single replicated and we're still using the --- the max parallelization flag, so the query should fail -SET citus.force_max_query_parallelization TO ON; -SELECT citus.mitmproxy('conn.delay(500)'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM single_replicatated; -ERROR: could not establish any connections to the node localhost:9060 after 400 ms -SET citus.force_max_query_parallelization TO OFF; --- one similar test, but this time on modification queries --- to see that connection establishement failures could --- mark placement INVALID -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT - count(*) as invalid_placement_count -FROM - pg_dist_shard_placement -WHERE - shardstate = 3 AND - shardid IN (SELECT shardid from pg_dist_shard where logicalrelid = 'products'::regclass); - invalid_placement_count -------------------------- - 0 -(1 row) - -SELECT citus.mitmproxy('conn.delay(500)'); - mitmproxy ------------ - -(1 row) - -INSERT INTO products VALUES (100, '100', 100); -COMMIT; -SELECT - count(*) as invalid_placement_count -FROM - pg_dist_shard_placement -WHERE - shardstate = 3 AND - shardid IN (SELECT shardid from pg_dist_shard where logicalrelid = 'products'::regclass); - invalid_placement_count -------------------------- - 1 -(1 row) - --- show that INSERT went through -SELECT count(*) FROM products WHERE product_no = 100; - count -------- - 1 -(1 row) - -RESET client_min_messages; --- verify get_global_active_transactions works when a timeout happens on a connection -SELECT get_global_active_transactions(); -WARNING: could not establish connection after 400 ms -WARNING: connection error: localhost:9060 - get_global_active_transactions --------------------------------- -(0 rows) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.node_connection_timeout TO DEFAULT; -DROP SCHEMA fail_connect CASCADE; -NOTICE: drop cascades to 3 other objects -DETAIL: drop cascades to table products -drop cascades to table r1 -drop cascades to table single_replicatated -SET search_path TO default; diff --git a/src/test/regress/expected/failure_create_distributed_table_non_empty.out b/src/test/regress/expected/failure_create_distributed_table_non_empty.out index d6ed907f0..8b5acb091 100644 --- a/src/test/regress/expected/failure_create_distributed_table_non_empty.out +++ b/src/test/regress/expected/failure_create_distributed_table_non_empty.out @@ -125,10 +125,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT create_distributed_table('test_table', 'id'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -159,13 +159,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT create_distributed_table('test_table', 'id'); -WARNING: cancel requests are ignored during shard creation -NOTICE: Copying data from local table... - create_distributed_table --------------------------- - -(1 row) - +ERROR: canceling statement due to user request SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -175,7 +169,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- - 4 + 0 (1 row) SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); @@ -196,10 +190,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); (1 row) SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- @@ -474,7 +468,9 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- @@ -559,10 +555,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^SELECT worker_apply_shard_ddl_comma (1 row) SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- @@ -666,7 +662,9 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R SELECT create_distributed_table('test_table', 'id'); ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -697,11 +695,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - +ERROR: canceling statement due to user request SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -711,7 +705,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- - 4 + 0 (1 row) SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); @@ -732,10 +726,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); (1 row) SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- @@ -947,7 +941,9 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; count ------- diff --git a/src/test/regress/expected/failure_create_distributed_table_non_empty_9.out b/src/test/regress/expected/failure_create_distributed_table_non_empty_9.out deleted file mode 100644 index 8b5acb091..000000000 --- a/src/test/regress/expected/failure_create_distributed_table_non_empty_9.out +++ /dev/null @@ -1,1003 +0,0 @@ --- --- Failure tests for COPY to reference tables --- --- We have to keep two copies of this failure test --- because if the shards are created via the executor --- cancellations are processed, otherwise they are not -CREATE SCHEMA create_distributed_table_non_empty_failure; -SET search_path TO 'create_distributed_table_non_empty_failure'; -SET citus.next_shard_id TO 11000000; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- we'll start with replication factor 1 and 2pc -SET citus.shard_replication_factor TO 1; -SET citus.shard_count to 4; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- in the first test, kill the first connection we sent from the coordinator -SELECT citus.mitmproxy('conn.kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- in the first test, cancel the first connection we sent from the coordinator -SELECT citus.mitmproxy('conn.cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill as soon as the coordinator sends CREATE SCHEMA -SELECT citus.mitmproxy('conn.onQuery(query="^CREATE SCHEMA").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,1) -(2 rows) - --- cancel as soon as the coordinator sends CREATE SCHEMA --- Note: Schema should be created in workers because Citus --- does not check for interrupts until GetRemoteCommandResult is called. --- Since we already sent the command at this stage, the schemas get created in workers -SELECT citus.mitmproxy('conn.onQuery(query="^CREATE SCHEMA").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,1) -(2 rows) - -SELECT run_command_on_workers($$DROP SCHEMA IF EXISTS create_distributed_table_non_empty_failure$$); - run_command_on_workers ------------------------------------ - (localhost,9060,t,"DROP SCHEMA") - (localhost,57637,t,"DROP SCHEMA") -(2 rows) - --- this triggers a schema creation which prevents further transactions around dependency propagation -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,1) - (localhost,57637,t,1) -(2 rows) - --- cancel as soon as the coordinator sends begin --- if the shards are created via the executor, the table creation will fail --- otherwise shards will be created because we ignore cancel requests during the shard creation --- Interrupts are hold in CreateShardsWithRoundRobinPolicy -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,1) - (localhost,57637,t,1) -(2 rows) - -DROP TABLE test_table ; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- kill as soon as the coordinator sends CREATE TABLE -SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill as soon as the coordinator sends COPY -SELECT citus.mitmproxy('conn.onQuery(query="COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill when the COPY is completed, it should be rollbacked properly -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -NOTICE: Copying data from local table... -ERROR: failed to COPY to shard 11000016 on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel as soon as the coordinator sends COPY, table --- should not be created and rollbacked properly -SELECT citus.mitmproxy('conn.onQuery(query="COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel when the COPY is completed, it should be rollbacked properly -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -NOTICE: Copying data from local table... -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- immediately kill when we see prepare transaction to see if the command --- successfully rollbacked the created shards --- we don't want to see the prepared transaction numbers in the warnings -SET client_min_messages TO ERROR; -SELECT citus.mitmproxy('conn.onQuery(query="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- immediately cancel when we see prepare transaction to see if the command --- successfully rollbacked the created shards -SELECT citus.mitmproxy('conn.onQuery(query="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - --- kill as soon as the coordinator sends COMMIT --- shards should be created and kill should not affect -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 4 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 2 -(1 row) - -DROP TABLE test_table ; --- since we want to interrupt the schema creation again we need to drop and recreate --- for citus to redistribute the dependency -DROP SCHEMA create_distributed_table_non_empty_failure; -CREATE SCHEMA create_distributed_table_non_empty_failure; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- cancel as soon as the coordinator sends COMMIT --- shards should be created and kill should not affect -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 4 -(1 row) - -DROP TABLE test_table ; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- kill as soon as the coordinator sends ROLLBACK --- the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ROLLBACK; -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel as soon as the coordinator sends ROLLBACK --- should be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- We are done with pure create_distributed_table testing and now --- testing for co-located tables. -CREATE TABLE colocated_table(id int, value_1 int); -SELECT create_distributed_table('colocated_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - --- Now, cancel the connection just after transaction is opened on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, kill the connection just after transaction is opened on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, cancel the connection just after the COPY started to --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, kill the connection just after the COPY started to --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, cancel the connection when we issue CREATE TABLE on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT worker_apply_shard_ddl_command").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, kill the connection when we issue CREATE TABLE on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now run the same tests with 1pc -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE colocated_table; -DROP TABLE test_table; -DROP SCHEMA create_distributed_table_non_empty_failure; -CREATE SCHEMA create_distributed_table_non_empty_failure; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); -SET citus.multi_shard_commit_protocol TO '1pc'; -SELECT citus.mitmproxy('conn.kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- in the first test, cancel the first connection we sent from the coordinator -SELECT citus.mitmproxy('conn.cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- this triggers a schema creation which prevents further transactions around dependency propagation -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,1) - (localhost,57637,t,1) -(2 rows) - --- cancel as soon as the coordinator sends begin --- if the shards are created via the executor, the table creation will fail --- otherwise shards will be created because we ignore cancel requests during the shard creation --- Interrupts are hold in CreateShardsWithRoundRobinPolicy -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'create_distributed_table_non_empty_failure'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,1) - (localhost,57637,t,1) -(2 rows) - -DROP TABLE test_table ; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- kill as soon as the coordinator sends CREATE TABLE -SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill as soon as the coordinator sends COPY -SELECT citus.mitmproxy('conn.onQuery(query="COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill when the COPY is completed, it should be rollbacked properly -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: failed to COPY to shard 11000096 on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel as soon as the coordinator sends COPY, table --- should not be created and rollbacked properly -SELECT citus.mitmproxy('conn.onQuery(query="COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel when the COPY is completed, it should be rollbacked properly -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill as soon as the coordinator sends ROLLBACK --- the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ROLLBACK; -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- cancel as soon as the coordinator sends ROLLBACK --- should be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- kill as soon as the coordinator sends COMMIT --- the command can be COMMITed -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -COMMIT; -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 4 -(1 row) - -DROP TABLE test_table; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); --- cancel as soon as the coordinator sends COMMIT --- should be COMMITed -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -COMMIT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 4 -(1 row) - -DROP TABLE test_table; -CREATE TABLE test_table(id int, value_1 int); -INSERT INTO test_table VALUES (1,1),(2,2),(3,3),(4,4); -CREATE TABLE colocated_table(id int, value_1 int); -SELECT create_distributed_table('colocated_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - --- Now, cancel the connection just after transaction is opened on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, kill the connection just after transaction is opened on --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, cancel the connection just after the COPY started to --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - --- Now, kill the connection just after the COPY started to --- workers. Note that, when there is a colocated table, interrupts --- are not held and we can cancel in the middle of the execution -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id', colocate_with => 'colocated_table'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'create_distributed_table_non_empty_failure' and table_name LIKE 'test_table%'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP SCHEMA create_distributed_table_non_empty_failure CASCADE; diff --git a/src/test/regress/expected/failure_create_reference_table.out b/src/test/regress/expected/failure_create_reference_table.out index 713fbec2a..9cd6b4a97 100644 --- a/src/test/regress/expected/failure_create_reference_table.out +++ b/src/test/regress/expected/failure_create_reference_table.out @@ -25,10 +25,10 @@ SELECT citus.mitmproxy('conn.onQuery().kill()'); (1 row) SELECT create_reference_table('ref_table'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard_placement; count ------- @@ -43,10 +43,10 @@ SELECT citus.mitmproxy('conn.onCommandComplete(command="BEGIN").kill()'); (1 row) SELECT create_reference_table('ref_table'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard_placement; count ------- @@ -76,10 +76,10 @@ SELECT citus.mitmproxy('conn.onCommandComplete(command="SELECT 1").kill()'); (1 row) SELECT create_reference_table('ref_table'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard_placement; count ------- diff --git a/src/test/regress/expected/failure_create_reference_table_9.out b/src/test/regress/expected/failure_create_reference_table_9.out deleted file mode 100644 index 9cd6b4a97..000000000 --- a/src/test/regress/expected/failure_create_reference_table_9.out +++ /dev/null @@ -1,255 +0,0 @@ --- --- Failure tests for creating reference table --- -CREATE SCHEMA failure_reference_table; -SET search_path TO 'failure_reference_table'; -SET citus.next_shard_id TO 10000000; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- this is merely used to get the schema creation propagated. Without there are failures --- not related to reference tables but schema creation due to dependency creation on workers -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; -CREATE TABLE ref_table(id int); -INSERT INTO ref_table VALUES(1),(2),(3); --- Kill on sending first query to worker node, should error --- out and not create any placement -SELECT citus.mitmproxy('conn.onQuery().kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Kill after creating transaction on worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="BEGIN").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Cancel after creating transaction on worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="BEGIN").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Kill after copying data to worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="SELECT 1").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Cancel after copying data to worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="SELECT 1").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Kill after copying data to worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY 3").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -NOTICE: Copying data from local table... -ERROR: failed to COPY to shard 10000005 on localhost:9060 -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- Cancel after copying data to worker node -SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY 3").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -NOTICE: Copying data from local table... -ERROR: canceling statement due to user request -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - --- we don't want to see the prepared transaction numbers in the warnings -SET client_min_messages TO ERROR; --- Kill after preparing transaction. Since we don't commit after preparing, we recover --- prepared transaction afterwards. -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT count(*) FROM pg_dist_shard_placement; - count -------- - 0 -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - --- Kill after commiting prepared, this should succeed -SELECT citus.mitmproxy('conn.onCommandComplete(command="COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_reference_table('ref_table'); - create_reference_table ------------------------- - -(1 row) - -SELECT shardid, nodeport, shardstate FROM pg_dist_shard_placement ORDER BY shardid, nodeport; - shardid | nodeport | shardstate -----------+----------+------------ - 10000008 | 9060 | 1 - 10000008 | 57637 | 1 -(2 rows) - -SET client_min_messages TO NOTICE; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE ref_table; -DROP SCHEMA failure_reference_table; -CREATE SCHEMA failure_reference_table; -CREATE TABLE ref_table(id int); -INSERT INTO ref_table VALUES(1),(2),(3); --- Test in transaction -SELECT citus.mitmproxy('conn.onQuery().kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_reference_table('ref_table'); -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -ERROR: failure on connection marked as essential: localhost:9060 -COMMIT; --- kill on ROLLBACK, should be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_reference_table('ref_table'); -NOTICE: Copying data from local table... - create_reference_table ------------------------- - -(1 row) - -ROLLBACK; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT * FROM pg_dist_shard_placement ORDER BY shardid, nodeport; - shardid | shardstate | shardlength | nodename | nodeport | placementid ----------+------------+-------------+----------+----------+------------- -(0 rows) - --- cancel when the coordinator send ROLLBACK, should be rollbacked. We ignore cancellations --- during the ROLLBACK. -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_reference_table('ref_table'); -NOTICE: Copying data from local table... - create_reference_table ------------------------- - -(1 row) - -ROLLBACK; -SELECT * FROM pg_dist_shard_placement ORDER BY shardid, nodeport; - shardid | shardstate | shardlength | nodename | nodeport | placementid ----------+------------+-------------+----------+----------+------------- -(0 rows) - -DROP SCHEMA failure_reference_table CASCADE; -NOTICE: drop cascades to table ref_table -SET search_path TO default; diff --git a/src/test/regress/expected/failure_create_table.out b/src/test/regress/expected/failure_create_table.out index 8160981b2..9a74ae556 100644 --- a/src/test/regress/expected/failure_create_table.out +++ b/src/test/regress/expected/failure_create_table.out @@ -89,10 +89,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT create_distributed_table('test_table','id'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -120,10 +120,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT worker_apply_shard_ddl_comman (1 row) SELECT create_distributed_table('test_table','id'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -154,10 +154,10 @@ BEGIN; (1 row) SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 COMMIT; SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -188,12 +188,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT create_distributed_table('test_table','id'); -WARNING: cancel requests are ignored during shard creation - create_distributed_table --------------------------- - -(1 row) - +ERROR: canceling statement due to user request SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -203,14 +198,14 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM pg_dist_shard; count ------- - 4 + 0 (1 row) SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); run_command_on_workers ------------------------ - (localhost,9060,t,2) - (localhost,57637,t,2) + (localhost,9060,t,0) + (localhost,57637,t,0) (2 rows) DROP TABLE test_table; @@ -230,10 +225,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); (1 row) SELECT create_distributed_table('test_table','id',colocate_with=>'temp_table'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -389,10 +384,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R BEGIN; SELECT create_distributed_table('test_table','id'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. ROLLBACK; SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -425,12 +420,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R BEGIN; SELECT create_distributed_table('test_table','id'); -WARNING: cancel requests are ignored during shard creation - create_distributed_table --------------------------- - -(1 row) - +ERROR: canceling statement due to user request COMMIT; SELECT recover_prepared_transactions(); recover_prepared_transactions @@ -447,14 +437,14 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM pg_dist_shard; count ------- - 4 + 0 (1 row) SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); run_command_on_workers ------------------------ - (localhost,9060,t,2) - (localhost,57637,t,2) + (localhost,9060,t,0) + (localhost,57637,t,0) (2 rows) -- drop tables and schema and recreate to start from a non-distributed schema again @@ -506,10 +496,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); BEGIN; SELECT create_distributed_table('test_table','id'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 ROLLBACK; SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -543,10 +533,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R BEGIN; SELECT create_distributed_table('test_table','id'); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. ROLLBACK; SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -578,12 +568,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R BEGIN; SELECT create_distributed_table('test_table','id'); -WARNING: cancel requests are ignored during shard creation - create_distributed_table --------------------------- - -(1 row) - +ERROR: canceling statement due to user request COMMIT; SELECT recover_prepared_transactions(); recover_prepared_transactions @@ -600,14 +585,14 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM pg_dist_shard; count ------- - 4 + 0 (1 row) SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); run_command_on_workers ------------------------ - (localhost,9060,t,2) - (localhost,57637,t,2) + (localhost,9060,t,0) + (localhost,57637,t,0) (2 rows) DROP TABLE test_table; @@ -630,10 +615,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) SELECT master_create_worker_shards('test_table_2', 4, 2); -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ERROR: connection error: localhost:9060 -DETAIL: connection not open +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT count(*) FROM pg_dist_shard; count ------- diff --git a/src/test/regress/expected/failure_create_table_9.out b/src/test/regress/expected/failure_create_table_9.out deleted file mode 100644 index 9a74ae556..000000000 --- a/src/test/regress/expected/failure_create_table_9.out +++ /dev/null @@ -1,713 +0,0 @@ --- --- failure_create_table adds failure tests for creating table without data. --- -CREATE SCHEMA failure_create_table; -SET search_path TO 'failure_create_table'; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_replication_factor TO 1; -SET citus.shard_count to 4; -CREATE TABLE test_table(id int, value_1 int); --- Kill connection before sending query to the worker -SELECT citus.mitmproxy('conn.kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- kill as soon as the coordinator sends CREATE SCHEMA --- Since schemas are created in separate transaction, schema will --- be created only on the node which is not behind the proxy. --- https://github.com/citusdata/citus/pull/1652 -SELECT citus.mitmproxy('conn.onQuery(query="^CREATE SCHEMA").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table', 'id'); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata WHERE schema_name = 'failure_create_table'$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,1) -(2 rows) - --- this is merely used to get the schema creation propagated. Without there are failures --- not related to reference tables but schema creation due to dependency creation on workers -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; --- Now, kill the connection while opening transaction on workers. -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, kill the connection after sending create table command with worker_apply_shard_ddl_command UDF -SELECT citus.mitmproxy('conn.onQuery(query="SELECT worker_apply_shard_ddl_command").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Kill the connection while creating a distributed table in sequential mode on sending create command --- with worker_apply_shard_ddl_command UDF. -BEGIN; - SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; - SELECT citus.mitmproxy('conn.onQuery(query="SELECT worker_apply_shard_ddl_command").after(1).kill()'); - mitmproxy ------------ - -(1 row) - - SELECT create_distributed_table('test_table', 'id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -COMMIT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, cancel the connection while creating transaction --- workers. Note that, cancel requests will be ignored during --- shard creation. -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -DROP TABLE test_table; -CREATE TABLE test_table(id int, value_1 int); --- Kill and cancel the connection with colocate_with option while sending the create table command -CREATE TABLE temp_table(id int, value_1 int); -SELECT create_distributed_table('temp_table','id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id',colocate_with=>'temp_table'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 4 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id',colocate_with=>'temp_table'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 4 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Kill and cancel the connection after worker sends "PREPARE TRANSACTION" ack with colocate_with option -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id',colocate_with=>'temp_table'); -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 4 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT create_distributed_table('test_table','id',colocate_with=>'temp_table'); -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 4 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- drop tables and schema and recreate to start from a non-distributed schema again -DROP TABLE temp_table; -DROP TABLE test_table; -DROP SCHEMA failure_create_table; -CREATE SCHEMA failure_create_table; -CREATE TABLE test_table(id int, value_1 int); --- Test inside transaction --- Kill connection before sending query to the worker -SELECT citus.mitmproxy('conn.kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- this is merely used to get the schema creation propagated. Without there are failures --- not related to reference tables but schema creation due to dependency creation on workers -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; --- Now, kill the connection while creating transaction on workers in transaction. -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, cancel the connection while creating the transaction on --- workers. Note that, cancel requests will be ignored during --- shard creation again in transaction if we're not relying on the --- executor. So, we'll have two output files -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: canceling statement due to user request -COMMIT; -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- drop tables and schema and recreate to start from a non-distributed schema again -DROP TABLE test_table; -DROP SCHEMA failure_create_table; -CREATE SCHEMA failure_create_table; -CREATE TABLE test_table(id int, value_1 int); --- Test inside transaction and with 1PC -SET citus.multi_shard_commit_protocol TO "1pc"; --- Kill connection before sending query to the worker with 1pc. -SELECT citus.mitmproxy('conn.kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Kill connection while sending create table command with 1pc. -SELECT citus.mitmproxy('conn.onQuery(query="CREATE TABLE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- this is merely used to get the schema creation propagated. Without there are failures --- not related to reference tables but schema creation due to dependency creation on workers -CREATE TYPE schema_proc AS (a int); -DROP TYPE schema_proc; --- Now, kill the connection while opening transactions on workers with 1pc. Transaction will be opened due to BEGIN. -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Now, cancel the connection while creating transactions on --- workers with 1pc. Note that, cancel requests will be ignored during --- shard creation unless the executor is used. So, we'll have two output files -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT create_distributed_table('test_table','id'); -ERROR: canceling statement due to user request -COMMIT; -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -DROP TABLE test_table; -DROP SCHEMA failure_create_table; -CREATE SCHEMA failure_create_table; --- Test master_create_worker_shards with 2pc -SET citus.multi_shard_commit_protocol TO "2pc"; -CREATE TABLE test_table_2(id int, value_1 int); -SELECT master_create_distributed_table('test_table_2', 'id', 'hash'); - master_create_distributed_table ---------------------------------- - -(1 row) - --- Kill connection before sending query to the worker -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT master_create_worker_shards('test_table_2', 4, 2); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Kill the connection after worker sends "PREPARE TRANSACTION" ack -SELECT citus.mitmproxy('conn.onCommandComplete(command="^PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT master_create_worker_shards('test_table_2', 4, 2); -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - --- Cancel the connection after sending prepare transaction in master_create_worker_shards -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT master_create_worker_shards('test_table_2', 4, 2); -ERROR: canceling statement due to user request --- Show that there is no pending transaction -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM pg_dist_shard; - count -------- - 0 -(1 row) - -SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.tables WHERE table_schema = 'failure_create_table' and table_name LIKE 'test_table%' ORDER BY 1$$); - run_command_on_workers ------------------------- - (localhost,9060,t,0) - (localhost,57637,t,0) -(2 rows) - -DROP SCHEMA failure_create_table CASCADE; -NOTICE: drop cascades to table test_table_2 -SET search_path TO default; diff --git a/src/test/regress/expected/failure_cte_subquery.out b/src/test/regress/expected/failure_cte_subquery.out index e955a4b9d..aba610d66 100644 --- a/src/test/regress/expected/failure_cte_subquery.out +++ b/src/test/regress/expected/failure_cte_subquery.out @@ -83,10 +83,10 @@ FROM ORDER BY 1 DESC LIMIT 5 ) as foo WHERE foo.user_id = cte.user_id; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. -- kill at the third copy (pull) SELECT citus.mitmproxy('conn.onQuery(query="SELECT DISTINCT users_table.user").kill()'); @@ -118,9 +118,10 @@ FROM ORDER BY 1 DESC LIMIT 5 ) as foo WHERE foo.user_id = cte.user_id; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. -- cancel at the first copy (push) SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); mitmproxy @@ -257,10 +258,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^DELETE FROM").kill()'); WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify contents are the same SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -373,10 +374,10 @@ BEGIN; SET LOCAL citus.multi_shard_modify_mode = 'sequential'; WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 END; RESET SEARCH_PATH; SELECT citus.mitmproxy('conn.allow()'); diff --git a/src/test/regress/expected/failure_cte_subquery_9.out b/src/test/regress/expected/failure_cte_subquery_9.out deleted file mode 100644 index aba610d66..000000000 --- a/src/test/regress/expected/failure_cte_subquery_9.out +++ /dev/null @@ -1,393 +0,0 @@ -CREATE SCHEMA cte_failure; -SET SEARCH_PATH=cte_failure; -SET citus.shard_count to 2; -SET citus.shard_replication_factor to 1; -SET citus.next_shard_id TO 16000000; -SELECT pg_backend_pid() as pid \gset -CREATE TABLE users_table (user_id int, user_name text); -CREATE TABLE events_table(user_id int, event_id int, event_type int); -SELECT create_distributed_table('users_table', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('events_table', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE users_table_local AS SELECT * FROM users_table; --- kill at the first copy (push) -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- kill at the second copy (pull) -SELECT citus.mitmproxy('conn.onQuery(query="SELECT user_id FROM cte_failure.events_table_16000002").kill()'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. - --- kill at the third copy (pull) -SELECT citus.mitmproxy('conn.onQuery(query="SELECT DISTINCT users_table.user").kill()'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- cancel at the first copy (push) -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: canceling statement due to user request --- cancel at the second copy (pull) -SELECT citus.mitmproxy('conn.onQuery(query="SELECT user_id FROM").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: canceling statement due to user request --- cancel at the third copy (pull) -SELECT citus.mitmproxy('conn.onQuery(query="SELECT DISTINCT users_table.user").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -WITH cte AS ( - WITH local_cte AS ( - SELECT * FROM users_table_local - ), - dist_cte AS ( - SELECT user_id FROM events_table - ) - SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id -) -SELECT - count(*) -FROM - cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND - event_type IN (1,2,3,4) - ORDER BY 1 DESC LIMIT 5 - ) as foo - WHERE foo.user_id = cte.user_id; -ERROR: canceling statement due to user request --- distributed update tests -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- insert some rows -INSERT INTO users_table VALUES (1, 'A'), (2, 'B'), (3, 'C'), (4, 'D'), (5, 'E'); -INSERT INTO events_table VALUES (1,1,1), (1,2,1), (1,3,1), (2,1, 4), (3, 4,1), (5, 1, 2), (5, 2, 1), (5, 2,2); -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- following will delete and insert the same rows -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; --- verify contents are the same -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- kill connection during deletion -SELECT citus.mitmproxy('conn.onQuery(query="^DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify contents are the same -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- kill connection during insert -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- verify contents are the same -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- cancel during deletion -SELECT citus.mitmproxy('conn.onQuery(query="^DELETE FROM").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: canceling statement due to user request --- verify contents are the same -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- cancel during insert -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: canceling statement due to user request --- verify contents are the same -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM users_table ORDER BY 1, 2; - user_id | user_name ----------+----------- - 1 | A - 2 | B - 3 | C - 4 | D - 5 | E -(5 rows) - --- test sequential delete/insert -SELECT citus.mitmproxy('conn.onQuery(query="^DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SET LOCAL citus.multi_shard_modify_mode = 'sequential'; -WITH cte_delete as (DELETE FROM users_table WHERE user_name in ('A', 'D') RETURNING *) -INSERT INTO users_table SELECT * FROM cte_delete; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -END; -RESET SEARCH_PATH; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP SCHEMA cte_failure CASCADE; -NOTICE: drop cascades to 3 other objects -DETAIL: drop cascades to table cte_failure.users_table -drop cascades to table cte_failure.events_table -drop cascades to table cte_failure.users_table_local diff --git a/src/test/regress/expected/failure_ddl.out b/src/test/regress/expected/failure_ddl.out index 8f2d23547..769e14b14 100644 --- a/src/test/regress/expected/failure_ddl.out +++ b/src/test/regress/expected/failure_ddl.out @@ -70,7 +70,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------- @@ -100,10 +103,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kil (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- show that we've never commited the changes SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg @@ -379,7 +382,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) ALTER TABLE test_table DROP COLUMN new_column; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------------------ @@ -409,10 +415,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kil (1 row) ALTER TABLE test_table DROP COLUMN new_column; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------------------ @@ -747,7 +753,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------- @@ -777,10 +786,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kil (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------- @@ -1038,7 +1047,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; array_agg ------------- @@ -1068,10 +1080,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kil (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- kill as soon as the coordinator after it sends worker_apply_shard_ddl_command 2nd time SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").after(2).kill()'); mitmproxy @@ -1080,10 +1092,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").aft (1 row) ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- cancel as soon as the coordinator after it sends worker_apply_shard_ddl_command 2nd time SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").after(2).cancel(' || pg_backend_pid() || ')'); mitmproxy diff --git a/src/test/regress/expected/failure_ddl_9.out b/src/test/regress/expected/failure_ddl_9.out deleted file mode 100644 index 769e14b14..000000000 --- a/src/test/regress/expected/failure_ddl_9.out +++ /dev/null @@ -1,1109 +0,0 @@ --- --- Test DDL command propagation failures --- Different dimensions we're testing: --- Replication factor, 1PC-2PC, sequential-parallel modes --- -CREATE SCHEMA ddl_failure; -SET search_path TO 'ddl_failure'; --- do not cache any connections -SET citus.max_cached_conns_per_worker TO 0; --- we don't want to see the prepared transaction numbers in the warnings -SET client_min_messages TO ERROR; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.next_shard_id TO 100800; --- we'll start with replication factor 1, 1PC and parallel mode -SET citus.multi_shard_commit_protocol TO '1pc'; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 1; -CREATE TABLE test_table (key int, value int); -SELECT create_distributed_table('test_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- show that we've never commited the changes -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request --- show that we've never commited the changes -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- since we've killed the connection just after --- the coordinator sends the COMMIT, the command should be applied --- to the distributed table and the shards on the other worker --- however, there is no way to recover the failure on the shards --- that live in the failed worker, since we're running 1PC -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,value}") - (localhost,9060,100802,t,"{key,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- manually drop & re-create the table for the next tests -DROP TABLE test_table; -SET citus.next_shard_id TO 100800; -SET citus.multi_shard_commit_protocol TO '1pc'; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 1; -CREATE TABLE test_table (key int, value int); -SELECT create_distributed_table('test_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- cancel as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- interrupts are held during COMMIT/ROLLBACK, so the command --- should have been applied without any issues since cancel is ignored -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- the following tests rely the column not exists, so drop manually -ALTER TABLE test_table DROP COLUMN new_column; --- but now kill just after the worker sends response to --- COMMIT command, so we'll have lots of warnings but the command --- should have been committed both on the distributed table and the placements -SET client_min_messages TO WARNING; -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: could not commit transaction for shard 100802 on any active node -WARNING: could not commit transaction for shard 100800 on any active node -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET client_min_messages TO ERROR; -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- now cancel just after the worker sends response to --- but Postgres doesn't accepts interrupts during COMMIT and ROLLBACK --- so should not cancel at all, so not an effective test but adding in --- case Citus messes up this behaviour -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- the remaining tests rely on table having new_column -ALTER TABLE test_table ADD COLUMN new_column INT; --- finally, test failing on ROLLBACK with 1PC --- fail just after the coordinator sends the ROLLBACK --- so the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SET LOCAL client_min_messages TO WARNING; -ALTER TABLE test_table DROP COLUMN new_column; -ROLLBACK; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 --- now cancel just after the worker sends response to --- but Postgres doesn't accepts interrupts during COMMIT and ROLLBACK --- so should not cancel at all, so not an effective test but adding in --- case Citus messes up this behaviour -SELECT citus.mitmproxy('conn.onQuery(query="ROLLBACK").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table DROP COLUMN new_column; -ROLLBACK; --- but now kill just after the worker sends response to --- ROLLBACK command, so we'll have lots of warnings but the command --- should have been rollbacked both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table DROP COLUMN new_column; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- now, lets test with 2PC -SET citus.multi_shard_commit_protocol TO '2pc'; --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- kill as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- cancel as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - --- killing on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- we should be able to recover the transaction and --- see that the command is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 2 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- cancelling on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- we should be able to recover the transaction and --- see that the command is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- killing on command complete of COMMIT PREPARE, we should see that the command succeeds --- and all the workers committed -SELECT citus.mitmproxy('conn.onCommandComplete(command="COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100800,t,"{key,value}") - (localhost,9060,100802,t,"{key,value}") - (localhost,57637,100801,t,"{key,value}") - (localhost,57637,100803,t,"{key,value}") -(4 rows) - --- we shouldn't have any prepared transactions in the workers -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100800,t,"{key,value}") - (localhost,9060,100802,t,"{key,value}") - (localhost,57637,100801,t,"{key,value}") - (localhost,57637,100803,t,"{key,value}") -(4 rows) - --- kill as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- some of the placements would be missing the new column --- since we've not commited the prepared transactions -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,value}") - (localhost,9060,100802,t,"{key,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- we should be able to recover the transaction and --- see that the command is committed -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 2 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- finally, test failing on ROLLBACK with 2PC --- fail just after the coordinator sends the ROLLBACK --- so the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table DROP COLUMN new_column; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- ROLLBACK should have failed on the distributed table and the placements -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- but now kill just after the worker sends response to --- ROLLBACK command, so we'll have lots of warnings but the command --- should have been rollbacked both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table DROP COLUMN new_column; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- make sure that the transaction is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100800,t,"{key,new_column,value}") - (localhost,9060,100802,t,"{key,new_column,value}") - (localhost,57637,100801,t,"{key,new_column,value}") - (localhost,57637,100803,t,"{key,new_column,value}") -(4 rows) - --- another set of tests with 2PC and replication factor = 2 -SET citus.multi_shard_commit_protocol TO '2pc'; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 2; --- re-create the table with replication factor 2 -DROP TABLE test_table; -CREATE TABLE test_table (key int, value int); -SELECT create_distributed_table('test_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- killing on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- we should be able to recover the transaction and --- see that the command is rollbacked on all workers --- note that in this case recover_prepared_transactions() --- sends ROLLBACK PREPARED to the workers given that --- the transaction has not been commited on any placement yet -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 4 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100804,t,"{key,value}") - (localhost,9060,100805,t,"{key,value}") - (localhost,9060,100806,t,"{key,value}") - (localhost,9060,100807,t,"{key,value}") - (localhost,57637,100804,t,"{key,value}") - (localhost,57637,100805,t,"{key,value}") - (localhost,57637,100806,t,"{key,value}") - (localhost,57637,100807,t,"{key,value}") -(8 rows) - --- killing on command complete of COMMIT PREPARE, we should see that the command succeeds --- and all the workers committed -SELECT citus.mitmproxy('conn.onCommandComplete(command="COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg ------------------------- - {key,new_column,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100804,t,"{key,new_column,value}") - (localhost,9060,100805,t,"{key,new_column,value}") - (localhost,9060,100806,t,"{key,new_column,value}") - (localhost,9060,100807,t,"{key,new_column,value}") - (localhost,57637,100804,t,"{key,new_column,value}") - (localhost,57637,100805,t,"{key,new_column,value}") - (localhost,57637,100806,t,"{key,new_column,value}") - (localhost,57637,100807,t,"{key,new_column,value}") -(8 rows) - --- we shouldn't have any prepared transactions in the workers -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------------------ - (localhost,9060,100804,t,"{key,new_column,value}") - (localhost,9060,100805,t,"{key,new_column,value}") - (localhost,9060,100806,t,"{key,new_column,value}") - (localhost,9060,100807,t,"{key,new_column,value}") - (localhost,57637,100804,t,"{key,new_column,value}") - (localhost,57637,100805,t,"{key,new_column,value}") - (localhost,57637,100806,t,"{key,new_column,value}") - (localhost,57637,100807,t,"{key,new_column,value}") -(8 rows) - --- kill as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table DROP COLUMN new_column; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- some of the placements would be missing the new column --- since we've not commited the prepared transactions -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ----------------------------------------------------- - (localhost,9060,100804,t,"{key,new_column,value}") - (localhost,9060,100805,t,"{key,new_column,value}") - (localhost,9060,100806,t,"{key,new_column,value}") - (localhost,9060,100807,t,"{key,new_column,value}") - (localhost,57637,100804,t,"{key,value}") - (localhost,57637,100805,t,"{key,value}") - (localhost,57637,100806,t,"{key,value}") - (localhost,57637,100807,t,"{key,value}") -(8 rows) - --- we should be able to recover the transaction and --- see that the command is committed -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 4 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100804,t,"{key,value}") - (localhost,9060,100805,t,"{key,value}") - (localhost,9060,100806,t,"{key,value}") - (localhost,9060,100807,t,"{key,value}") - (localhost,57637,100804,t,"{key,value}") - (localhost,57637,100805,t,"{key,value}") - (localhost,57637,100806,t,"{key,value}") - (localhost,57637,100807,t,"{key,value}") -(8 rows) - --- finally, test failing on ROLLBACK with 2PC --- fail just after the coordinator sends the ROLLBACK --- so the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table ADD COLUMN new_column INT; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- ROLLBACK should have failed on the distributed table and the placements -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100804,t,"{key,value}") - (localhost,9060,100805,t,"{key,value}") - (localhost,9060,100806,t,"{key,value}") - (localhost,9060,100807,t,"{key,value}") - (localhost,57637,100804,t,"{key,value}") - (localhost,57637,100805,t,"{key,value}") - (localhost,57637,100806,t,"{key,value}") - (localhost,57637,100807,t,"{key,value}") -(8 rows) - --- but now kill just after the worker sends response to --- ROLLBACK command, so we'll have lots of warnings but the command --- should have been rollbacked both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -ALTER TABLE test_table ADD COLUMN new_column INT; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- make sure that the transaction is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT run_command_on_placements('test_table', $$SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = '%s'::regclass;$$) ORDER BY 1; - run_command_on_placements ------------------------------------------- - (localhost,9060,100804,t,"{key,value}") - (localhost,9060,100805,t,"{key,value}") - (localhost,9060,100806,t,"{key,value}") - (localhost,9060,100807,t,"{key,value}") - (localhost,57637,100804,t,"{key,value}") - (localhost,57637,100805,t,"{key,value}") - (localhost,57637,100806,t,"{key,value}") - (localhost,57637,100807,t,"{key,value}") -(8 rows) - --- now do some tests with sequential mode -SET citus.multi_shard_modify_mode TO 'sequential'; --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SELECT array_agg(name::text ORDER BY name::text) FROM public.table_attrs where relid = 'test_table'::regclass; - array_agg -------------- - {key,value} -(1 row) - --- kill as soon as the coordinator sends worker_apply_shard_ddl_command -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- kill as soon as the coordinator after it sends worker_apply_shard_ddl_command 2nd time -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").after(2).kill()'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- cancel as soon as the coordinator after it sends worker_apply_shard_ddl_command 2nd time -SELECT citus.mitmproxy('conn.onQuery(query="worker_apply_shard_ddl_command").after(2).cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ALTER TABLE test_table ADD COLUMN new_column INT; -ERROR: canceling statement due to user request -SET search_path TO 'public'; -DROP SCHEMA ddl_failure CASCADE; diff --git a/src/test/regress/expected/failure_insert_select_pushdown.out b/src/test/regress/expected/failure_insert_select_pushdown.out index 048e93de1..a27290627 100644 --- a/src/test/regress/expected/failure_insert_select_pushdown.out +++ b/src/test/regress/expected/failure_insert_select_pushdown.out @@ -44,10 +44,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown" (1 row) INSERT INTO events_summary SELECT user_id, event_id, count(*) FROM events_table GROUP BY 1,2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 --verify nothing is modified SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -98,10 +98,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown" (1 row) INSERT INTO events_table SELECT * FROM events_table; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 --verify nothing is modified SELECT citus.mitmproxy('conn.allow()'); mitmproxy diff --git a/src/test/regress/expected/failure_insert_select_pushdown_9.out b/src/test/regress/expected/failure_insert_select_pushdown_9.out deleted file mode 100644 index a27290627..000000000 --- a/src/test/regress/expected/failure_insert_select_pushdown_9.out +++ /dev/null @@ -1,150 +0,0 @@ --- --- failure_insert_select_pushdown --- --- performs failure/cancellation test for insert/select pushed down to shards. --- -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE SCHEMA insert_select_pushdown; -SET SEARCH_PATH=insert_select_pushdown; -SET citus.shard_count to 2; -SET citus.shard_replication_factor to 1; -SELECT pg_backend_pid() as pid \gset -CREATE TABLE events_table(user_id int, event_id int, event_type int); -CREATE TABLE events_summary(user_id int, event_id int, event_count int); -SELECT create_distributed_table('events_table', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('events_summary', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO events_table VALUES (1, 1, 3 ), (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 5, 1), (4, 7, 1), (4, 1, 9), (4, 3, 2); -SELECT count(*) FROM events_summary; - count -------- - 0 -(1 row) - --- insert/select from one distributed table to another --- kill worker query -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT user_id, event_id, count(*) FROM events_table GROUP BY 1,2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_summary; - count -------- - 0 -(1 row) - --- cancel worker query -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT user_id, event_id, count(*) FROM events_table GROUP BY 1,2; -ERROR: canceling statement due to user request ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_summary; - count -------- - 0 -(1 row) - --- test self insert/select -SELECT count(*) FROM events_table; - count -------- - 8 -(1 row) - --- kill worker query -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_table SELECT * FROM events_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_table; - count -------- - 8 -(1 row) - --- cancel worker query -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT INTO insert_select_pushdown").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_table SELECT * FROM events_table; -ERROR: canceling statement due to user request ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_table; - count -------- - 8 -(1 row) - -RESET SEARCH_PATH; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP SCHEMA insert_select_pushdown CASCADE; -NOTICE: drop cascades to 2 other objects -DETAIL: drop cascades to table insert_select_pushdown.events_table -drop cascades to table insert_select_pushdown.events_summary diff --git a/src/test/regress/expected/failure_insert_select_via_coordinator.out b/src/test/regress/expected/failure_insert_select_via_coordinator.out index 983dfe3e3..735194327 100644 --- a/src/test/regress/expected/failure_insert_select_via_coordinator.out +++ b/src/test/regress/expected/failure_insert_select_via_coordinator.out @@ -53,10 +53,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); (1 row) INSERT INTO events_summary SELECT event_id, event_type, count(*) FROM events_table GROUP BY 1,2; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. +CONTEXT: while executing command on localhost:9060 -- kill data push SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").kill()'); mitmproxy @@ -109,10 +109,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); (1 row) INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. +CONTEXT: while executing command on localhost:9060 -- kill data push SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").kill()'); mitmproxy diff --git a/src/test/regress/expected/failure_insert_select_via_coordinator_9.out b/src/test/regress/expected/failure_insert_select_via_coordinator_9.out deleted file mode 100644 index 735194327..000000000 --- a/src/test/regress/expected/failure_insert_select_via_coordinator_9.out +++ /dev/null @@ -1,229 +0,0 @@ --- --- failure_insert_select_via_coordinator --- --- performs failure/cancellation test for insert/select executed by coordinator. --- test for insert using CTEs are done in failure_cte_subquery, not repeating them here --- -CREATE SCHEMA coordinator_insert_select; -SET SEARCH_PATH=coordinator_insert_select; -SET citus.shard_count to 2; -SET citus.shard_replication_factor to 1; -SELECT pg_backend_pid() as pid \gset -CREATE TABLE events_table(user_id int, event_id int, event_type int); -CREATE TABLE events_summary(event_id int, event_type int, event_count int); -CREATE TABLE events_reference(event_type int, event_count int); -CREATE TABLE events_reference_distributed(event_type int, event_count int); -SELECT create_distributed_table('events_table', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('events_summary', 'event_id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_reference_table('events_reference'); - create_reference_table ------------------------- - -(1 row) - -SELECT create_distributed_table('events_reference_distributed', 'event_type'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO events_table VALUES (1, 1, 3 ), (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 5, 1), (4, 7, 1), (4, 1, 9), (4, 3, 2); -SELECT count(*) FROM events_summary; - count -------- - 0 -(1 row) - --- insert/select from one distributed table to another --- kill coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT event_id, event_type, count(*) FROM events_table GROUP BY 1,2; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- kill data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT event_id, event_type, count(*) FROM events_table GROUP BY 1,2; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- cancel coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT event_id, event_type, count(*) FROM events_table GROUP BY 1,2; -ERROR: canceling statement due to user request --- cancel data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_summary SELECT event_id, event_type, count(*) FROM events_table GROUP BY 1,2; -ERROR: canceling statement due to user request ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_summary; - count -------- - 0 -(1 row) - --- insert into reference table from a distributed table --- kill coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- kill data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- cancel coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; -ERROR: canceling statement due to user request --- cancel data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; -ERROR: canceling statement due to user request ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_reference; - count -------- - 0 -(1 row) - --- insert/select from reference table to distributed --- fill up reference table first -INSERT INTO events_reference SELECT event_type, count(*) FROM events_table GROUP BY 1; --- kill coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference_distributed SELECT * FROM events_reference; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- kill data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference_distributed SELECT * FROM events_reference; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- cancel coordinator pull query -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference_distributed SELECT * FROM events_reference; -ERROR: canceling statement due to user request --- cancel data push -SELECT citus.mitmproxy('conn.onQuery(query="^COPY coordinator_insert_select").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO events_reference_distributed SELECT * FROM events_reference; -ERROR: canceling statement due to user request ---verify nothing is modified -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM events_reference_distributed; - count -------- - 0 -(1 row) - -RESET SEARCH_PATH; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP SCHEMA coordinator_insert_select CASCADE; -NOTICE: drop cascades to 4 other objects -DETAIL: drop cascades to table coordinator_insert_select.events_table -drop cascades to table coordinator_insert_select.events_summary -drop cascades to table coordinator_insert_select.events_reference -drop cascades to table coordinator_insert_select.events_reference_distributed diff --git a/src/test/regress/expected/failure_multi_dml.out b/src/test/regress/expected/failure_multi_dml.out index 734412fa9..0552e8e80 100644 --- a/src/test/regress/expected/failure_multi_dml.out +++ b/src/test/regress/expected/failure_multi_dml.out @@ -33,10 +33,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^DELETE").kill()'); BEGIN; DELETE FROM dml_test WHERE id = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 DELETE FROM dml_test WHERE id = 2; ERROR: current transaction is aborted, commands ignored until end of transaction block INSERT INTO dml_test VALUES (5, 'Epsilon'); @@ -96,10 +96,10 @@ BEGIN; DELETE FROM dml_test WHERE id = 1; DELETE FROM dml_test WHERE id = 2; INSERT INTO dml_test VALUES (5, 'Epsilon'); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 UPDATE dml_test SET name = 'alpha' WHERE id = 1; ERROR: current transaction is aborted, commands ignored until end of transaction block UPDATE dml_test SET name = 'gamma' WHERE id = 3; @@ -154,10 +154,10 @@ DELETE FROM dml_test WHERE id = 1; DELETE FROM dml_test WHERE id = 2; INSERT INTO dml_test VALUES (5, 'Epsilon'); UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 UPDATE dml_test SET name = 'gamma' WHERE id = 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; diff --git a/src/test/regress/expected/failure_multi_dml_9.out b/src/test/regress/expected/failure_multi_dml_9.out deleted file mode 100644 index 0552e8e80..000000000 --- a/src/test/regress/expected/failure_multi_dml_9.out +++ /dev/null @@ -1,490 +0,0 @@ -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 1; -- one shard per worker -SET citus.next_shard_id TO 103400; -ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 100; -CREATE TABLE dml_test (id integer, name text); -SELECT create_distributed_table('dml_test', 'id'); - create_distributed_table --------------------------- - -(1 row) - -COPY dml_test FROM STDIN WITH CSV; -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - ----- test multiple statements spanning multiple shards, ----- at each significant point. These transactions are 2pc --- fail at DELETE -SELECT citus.mitmproxy('conn.onQuery(query="^DELETE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -DELETE FROM dml_test WHERE id = 2; -ERROR: current transaction is aborted, commands ignored until end of transaction block -INSERT INTO dml_test VALUES (5, 'Epsilon'); -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes performed in failed transaction -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- cancel at DELETE -SELECT citus.mitmproxy('conn.onQuery(query="^DELETE").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -ERROR: canceling statement due to user request -DELETE FROM dml_test WHERE id = 2; -ERROR: current transaction is aborted, commands ignored until end of transaction block -INSERT INTO dml_test VALUES (5, 'Epsilon'); -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes performed in failed transaction -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- fail at INSERT -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes before failed INSERT -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- cancel at INSERT -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -ERROR: canceling statement due to user request -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes before failed INSERT -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- fail at UPDATE -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes after failed UPDATE -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- cancel at UPDATE -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -ERROR: canceling statement due to user request -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; ---- shouldn't see any changes after failed UPDATE -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- fail at PREPARE TRANSACTION -SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - --- this transaction block will be sent to the coordinator as a remote command to hide the --- error message that is caused during commit. --- we'll test for the txn side-effects to ensure it didn't run -SELECT master_run_on_worker( - ARRAY['localhost']::text[], - ARRAY[:master_port]::int[], - ARRAY[' -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, ''Epsilon''); -UPDATE dml_test SET name = ''alpha'' WHERE id = 1; -UPDATE dml_test SET name = ''gamma'' WHERE id = 3; -COMMIT; - '], - false -); - master_run_on_worker ---------------------------- - (localhost,57636,t,BEGIN) -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT shardid FROM pg_dist_shard_placement WHERE shardstate = 3; - shardid ---------- -(0 rows) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - --- shouldn't see any changes after failed PREPARE -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- cancel at PREPARE TRANSACTION -SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - --- we'll test for the txn side-effects to ensure it didn't run -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT shardid FROM pg_dist_shard_placement WHERE shardstate = 3; - shardid ---------- -(0 rows) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - --- shouldn't see any changes after failed PREPARE -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- fail at COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - --- hide the error message (it has the PID)... --- we'll test for the txn side-effects to ensure it didn't run -SET client_min_messages TO ERROR; -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; -SET client_min_messages TO DEFAULT; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT shardid FROM pg_dist_shard_placement WHERE shardstate = 3; - shardid ---------- -(0 rows) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - --- should see changes, because of txn recovery -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+--------- - 3 | gamma - 4 | Delta - 5 | Epsilon -(3 rows) - --- cancel at COMMITs are ignored by Postgres -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; --- should see changes, because cancellation is ignored -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+--------- - 3 | gamma - 4 | Delta - 5 | Epsilon - 5 | Epsilon -(4 rows) - --- drop table and recreate with different replication/sharding -DROP TABLE dml_test; -SET citus.shard_count = 1; -SET citus.shard_replication_factor = 2; -- two placements -CREATE TABLE dml_test (id integer, name text); -SELECT create_distributed_table('dml_test', 'id'); - create_distributed_table --------------------------- - -(1 row) - -COPY dml_test FROM STDIN WITH CSV; ----- test multiple statements against a single shard, but with two placements --- fail at COMMIT (actually COMMIT this time, as no 2pc in use) -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 ---- should see all changes, but they only went to one placement (other is unhealthy) -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+--------- - 3 | gamma - 4 | Delta - 5 | Epsilon -(3 rows) - -SELECT shardid FROM pg_dist_shard_placement WHERE shardstate = 3; - shardid ---------- - 103402 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- drop table and recreate as reference table -DROP TABLE dml_test; -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 1; -CREATE TABLE dml_test (id integer, name text); -SELECT create_reference_table('dml_test'); - create_reference_table ------------------------- - -(1 row) - -COPY dml_test FROM STDIN WITH CSV; --- fail at COMMIT (by failing to PREPARE) -SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 ---- shouldn't see any changes after failed COMMIT -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- cancel at COMMIT (by cancelling on PREPARE) -SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM dml_test WHERE id = 1; -DELETE FROM dml_test WHERE id = 2; -INSERT INTO dml_test VALUES (5, 'Epsilon'); -UPDATE dml_test SET name = 'alpha' WHERE id = 1; -UPDATE dml_test SET name = 'gamma' WHERE id = 3; -COMMIT; -ERROR: canceling statement due to user request ---- shouldn't see any changes after cancelled PREPARE -SELECT * FROM dml_test ORDER BY id ASC; - id | name -----+------- - 1 | Alpha - 2 | Beta - 3 | Gamma - 4 | Delta -(4 rows) - --- allow connection to allow DROP -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE dml_test; diff --git a/src/test/regress/expected/failure_multi_row_insert.out b/src/test/regress/expected/failure_multi_row_insert.out index a4b4878e7..9b5570333 100644 --- a/src/test/regress/expected/failure_multi_row_insert.out +++ b/src/test/regress/expected/failure_multi_row_insert.out @@ -43,10 +43,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO distributed_table VALUES (1,1), (1,2), (1,3); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- this test is broken, see https://github.com/citusdata/citus/issues/2460 -- SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); -- INSERT INTO distributed_table VALUES (1,4), (1,5), (1,6); @@ -58,10 +58,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO distributed_table VALUES (1,7), (5,8); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- this test is broken, see https://github.com/citusdata/citus/issues/2460 -- SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); -- INSERT INTO distributed_table VALUES (1,9), (5,10); @@ -73,10 +73,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO distributed_table VALUES (1,11), (6,12); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); mitmproxy ----------- @@ -93,10 +93,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").after(1).kill()'); (1 row) INSERT INTO distributed_table VALUES (1,15), (6,16); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").after(1).cancel(' || :pid || ')'); mitmproxy ----------- @@ -113,10 +113,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO distributed_table VALUES (2,19),(1,20); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); mitmproxy ----------- diff --git a/src/test/regress/expected/failure_multi_row_insert_9.out b/src/test/regress/expected/failure_multi_row_insert_9.out deleted file mode 100644 index 9b5570333..000000000 --- a/src/test/regress/expected/failure_multi_row_insert_9.out +++ /dev/null @@ -1,158 +0,0 @@ --- --- failure_multi_row_insert --- -CREATE SCHEMA IF NOT EXISTS failure_multi_row_insert; -SET SEARCH_PATH TO failure_multi_row_insert; --- this test is dependent on the shard count, so do not change --- whitout changing the test -SET citus.shard_count TO 4; -SET citus.next_shard_id TO 301000; -SET citus.shard_replication_factor TO 1; -SELECT pg_backend_pid() as pid \gset -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE distributed_table(key int, value int); -CREATE TABLE reference_table(value int); -SELECT create_distributed_table('distributed_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_reference_table('reference_table'); - create_reference_table ------------------------- - -(1 row) - --- we'll test failure cases of the following cases: --- (a) multi-row INSERT that hits the same shard with the same value --- (b) multi-row INSERT that hits the same shard with different values --- (c) multi-row INSERT that hits multiple shards in a single worker --- (d) multi-row INSERT that hits multiple shards in multiple workers --- (e) multi-row INSERT to a reference table --- Failure and cancellation on multi-row INSERT that hits the same shard with the same value -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,1), (1,2), (1,3); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- this test is broken, see https://github.com/citusdata/citus/issues/2460 --- SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); --- INSERT INTO distributed_table VALUES (1,4), (1,5), (1,6); --- Failure and cancellation on multi-row INSERT that hits the same shard with different values -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,7), (5,8); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- this test is broken, see https://github.com/citusdata/citus/issues/2460 --- SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); --- INSERT INTO distributed_table VALUES (1,9), (5,10); --- Failure and cancellation multi-row INSERT that hits multiple shards in a single worker -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,11), (6,12); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,13), (6,14); -ERROR: canceling statement due to user request --- Failure and cancellation multi-row INSERT that hits multiple shards in a single worker, happening on the second query -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,15), (6,16); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").after(1).cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (1,17), (6,18); -ERROR: canceling statement due to user request --- Failure and cancellation multi-row INSERT that hits multiple shards in multiple workers -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (2,19),(1,20); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO distributed_table VALUES (2,21), (1,22); -ERROR: canceling statement due to user request --- one test for the reference tables for completeness -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -INSERT INTO reference_table VALUES (1), (2), (3), (4); -ERROR: canceling statement due to user request --- we've either failed or cancelled all queries, so should be empty -SELECT * FROM distributed_table; - key | value ------+------- -(0 rows) - -SELECT * FROM reference_table; - value -------- -(0 rows) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -RESET SEARCH_PATH; -DROP SCHEMA failure_multi_row_insert CASCADE; -NOTICE: drop cascades to 2 other objects -DETAIL: drop cascades to table failure_multi_row_insert.distributed_table -drop cascades to table failure_multi_row_insert.reference_table diff --git a/src/test/regress/expected/failure_multi_shard_update_delete.out b/src/test/regress/expected/failure_multi_shard_update_delete.out index 853caa2f1..ff160802e 100644 --- a/src/test/regress/expected/failure_multi_shard_update_delete.out +++ b/src/test/regress/expected/failure_multi_shard_update_delete.out @@ -63,10 +63,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); -- issue a multi shard delete DELETE FROM t2 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FROM t2; count @@ -82,10 +82,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005"). (1 row) DELETE FROM t2 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FROM t2; count @@ -145,10 +145,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); -- issue a multi shard update UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; b2 | c4 @@ -164,10 +164,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").kill( (1 row) UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; b2 | c4 @@ -221,10 +221,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); -- issue a multi shard delete DELETE FROM t2 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FROM t2; count @@ -240,10 +240,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005"). (1 row) DELETE FROM t2 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FROM t2; count @@ -303,10 +303,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); -- issue a multi shard update UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; b2 | c4 @@ -322,10 +322,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").kill( (1 row) UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; b2 | c4 @@ -396,10 +396,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); (1 row) DELETE FROM r1 WHERE a = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FILTER (WHERE b = 2) AS b2 FROM t2; b2 @@ -414,10 +414,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); (1 row) DELETE FROM t2 WHERE b = 2; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is deleted SELECT count(*) FILTER (WHERE b = 2) AS b2 FROM t2; b2 @@ -496,10 +496,10 @@ UPDATE t3 SET c = q.c FROM ( SELECT b, max(c) as c FROM t2 GROUP BY b) q WHERE t3.b = q.b RETURNING *; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- verify nothing is updated SELECT citus.mitmproxy('conn.allow()'); mitmproxy @@ -552,10 +552,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t3_201013").kill( (1 row) UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; b1 | b2 @@ -587,10 +587,10 @@ SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FRO -- following will fail UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 END; -- verify everything is rolled back SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; @@ -606,10 +606,10 @@ SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FRO (1 row) UPDATE t3 SET b = 1 WHERE b = 2 RETURNING *; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; b1 | b2 @@ -626,10 +626,10 @@ SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FRO (1 row) UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 -- verify nothing is updated SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; b1 | b2 @@ -661,10 +661,10 @@ SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FRO -- following will fail UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 END; -- verify everything is rolled back SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; diff --git a/src/test/regress/expected/failure_multi_shard_update_delete_9.out b/src/test/regress/expected/failure_multi_shard_update_delete_9.out deleted file mode 100644 index ff160802e..000000000 --- a/src/test/regress/expected/failure_multi_shard_update_delete_9.out +++ /dev/null @@ -1,694 +0,0 @@ --- --- failure_multi_shard_update_delete --- -CREATE SCHEMA IF NOT EXISTS multi_shard; -SET SEARCH_PATH = multi_shard; -SET citus.shard_count TO 4; -SET citus.next_shard_id TO 201000; -SET citus.shard_replication_factor TO 1; --- do not cache any connections -SET citus.max_cached_conns_per_worker TO 0; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE t1(a int PRIMARY KEY, b int, c int); -CREATE TABLE r1(a int, b int PRIMARY KEY); -CREATE TABLE t2(a int REFERENCES t1(a) ON DELETE CASCADE, b int REFERENCES r1(b) ON DELETE CASCADE, c int); -SELECT create_distributed_table('t1', 'a'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_reference_table('r1'); - create_reference_table ------------------------- - -(1 row) - -SELECT create_distributed_table('t2', 'a'); - create_distributed_table --------------------------- - -(1 row) - --- insert some data -INSERT INTO r1 VALUES (1, 1), (2, 2), (3, 3); -INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3); -INSERT INTO t2 VALUES (1, 1, 1), (1, 2, 1), (2, 1, 2), (2, 2, 4), (3, 1, 3), (3, 2, 3), (3, 3, 3); -SELECT pg_backend_pid() as pid \gset -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - -SHOW citus.multi_shard_commit_protocol ; - citus.multi_shard_commit_protocol ------------------------------------ - 2pc -(1 row) - --- DELETION TESTS --- delete using a filter on non-partition column filter --- test both kill and cancellation -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard delete -DELETE FROM t2 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- kill just one connection -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005").kill()'); - mitmproxy ------------ - -(1 row) - -DELETE FROM t2 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- cancellation -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard delete -DELETE FROM t2 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- cancel just one connection -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -DELETE FROM t2 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- UPDATE TESTS --- update non-partition column based on a filter on another non-partition column --- DELETION TESTS --- delete using a filter on non-partition column filter --- test both kill and cancellation -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard update -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- kill just one connection -SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- cancellation -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard update -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- cancel just one connection -SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- switch to 1PC -SET citus.multi_shard_commit_protocol TO '1PC'; --- DELETION TESTS --- delete using a filter on non-partition column filter --- test both kill and cancellation -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard delete -DELETE FROM t2 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- kill just one connection -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005").kill()'); - mitmproxy ------------ - -(1 row) - -DELETE FROM t2 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- cancellation -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard delete -DELETE FROM t2 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- cancel just one connection -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM multi_shard.t2_201005").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -DELETE FROM t2 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is deleted -SELECT count(*) FROM t2; - count -------- - 7 -(1 row) - --- UPDATE TESTS --- update non-partition column based on a filter on another non-partition column --- DELETION TESTS --- delete using a filter on non-partition column filter --- test both kill and cancellation -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard update -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- kill just one connection -SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- cancellation -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - --- issue a multi shard update -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - --- cancel just one connection -SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t2_201005").cancel(' || :pid || ')'); - mitmproxy ------------ - -(1 row) - -UPDATE t2 SET c = 4 WHERE b = 2; -ERROR: canceling statement due to user request --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 2) AS b2, count(*) FILTER (WHERE c = 4) AS c4 FROM t2; - b2 | c4 -----+---- - 3 | 1 -(1 row) - -RESET citus.multi_shard_commit_protocol; --- --- fail when cascading deletes from foreign key --- unfortunately cascading deletes from foreign keys --- are done inside the worker only and do not --- generate any network output --- therefore we can't just fail cascade part --- following tests are added for completeness purposes --- it is safe to remove them without reducing any --- test coverage -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- check counts before delete -SELECT count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b2 ----- - 3 -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - -DELETE FROM r1 WHERE a = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b2 ----- - 3 -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="DELETE FROM").kill()'); - mitmproxy ------------ - -(1 row) - -DELETE FROM t2 WHERE b = 2; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is deleted -SELECT count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b2 ----- - 3 -(1 row) - --- test update with subquery pull -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE t3 AS SELECT * FROM t2; -SELECT create_distributed_table('t3', 'a'); -NOTICE: Copying data from local table... - create_distributed_table --------------------------- - -(1 row) - -SELECT * FROM t3 ORDER BY 1, 2, 3; - a | b | c ----+---+--- - 1 | 1 | 1 - 1 | 2 | 1 - 2 | 1 | 2 - 2 | 2 | 4 - 3 | 1 | 3 - 3 | 2 | 3 - 3 | 3 | 3 -(7 rows) - -SELECT citus.mitmproxy('conn.onQuery(query="^COPY").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE t3 SET c = q.c FROM ( - SELECT b, max(c) as c FROM t2 GROUP BY b) q -WHERE t3.b = q.b -RETURNING *; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 ---- verify nothing is updated -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM t3 ORDER BY 1, 2, 3; - a | b | c ----+---+--- - 1 | 1 | 1 - 1 | 2 | 1 - 2 | 1 | 2 - 2 | 2 | 4 - 3 | 1 | 3 - 3 | 2 | 3 - 3 | 3 | 3 -(7 rows) - --- kill update part -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE multi_shard.t3_201009").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE t3 SET c = q.c FROM ( - SELECT b, max(c) as c FROM t2 GROUP BY b) q -WHERE t3.b = q.b -RETURNING *; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. ---- verify nothing is updated -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM t3 ORDER BY 1, 2, 3; - a | b | c ----+---+--- - 1 | 1 | 1 - 1 | 2 | 1 - 2 | 1 | 2 - 2 | 2 | 4 - 3 | 1 | 3 - 3 | 2 | 3 - 3 | 3 | 3 -(7 rows) - --- test with replication_factor = 2 --- table can not have foreign reference with this setting so --- use a different set of table -SET citus.shard_replication_factor to 2; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE t3; -CREATE TABLE t3 AS SELECT * FROM t2; -SELECT create_distributed_table('t3', 'a'); -NOTICE: Copying data from local table... - create_distributed_table --------------------------- - -(1 row) - -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - --- prevent update of one replica of one shard -SELECT citus.mitmproxy('conn.onQuery(query="UPDATE multi_shard.t3_201013").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - --- fail only one update verify transaction is rolled back correctly -BEGIN; -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -UPDATE t2 SET b = 2 WHERE b = 1; --- verify update is performed on t2 -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 0 | 6 -(1 row) - --- following will fail -UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -END; --- verify everything is rolled back -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -UPDATE t3 SET b = 1 WHERE b = 2 RETURNING *; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - --- switch to 1PC -SET citus.multi_shard_commit_protocol TO '1PC'; -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- verify nothing is updated -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - --- fail only one update verify transaction is rolled back correctly -BEGIN; -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -UPDATE t2 SET b = 2 WHERE b = 1; --- verify update is performed on t2 -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 0 | 6 -(1 row) - --- following will fail -UPDATE t3 SET b = 2 WHERE b = 1; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -END; --- verify everything is rolled back -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t2; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -SELECT count(*) FILTER (WHERE b = 1) b1, count(*) FILTER (WHERE b = 2) AS b2 FROM t3; - b1 | b2 -----+---- - 3 | 3 -(1 row) - -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -RESET SEARCH_PATH; -DROP SCHEMA multi_shard CASCADE; -NOTICE: drop cascades to 4 other objects -DETAIL: drop cascades to table multi_shard.t1 -drop cascades to table multi_shard.r1 -drop cascades to table multi_shard.t2 -drop cascades to table multi_shard.t3 diff --git a/src/test/regress/expected/failure_real_time_select.out b/src/test/regress/expected/failure_real_time_select.out index 89318e521..2736cc9ca 100644 --- a/src/test/regress/expected/failure_real_time_select.out +++ b/src/test/regress/expected/failure_real_time_select.out @@ -33,7 +33,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); (1 row) SELECT count(*) FROM test_table; -ERROR: failed to execute task 1 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SET client_min_messages TO DEFAULT; -- Kill the connection with a CTE SELECT citus.mitmproxy('conn.onQuery(query=".*SELECT.*test_table.*").kill()'); @@ -46,13 +49,10 @@ WITH results AS (SELECT * FROM test_table) SELECT * FROM test_table, results WHERE test_table.id = results.id; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. -- Since the outer query uses the connection opened by the CTE, -- killing connection after first successful query should break. SET client_min_messages TO ERROR; @@ -141,12 +141,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); BEGIN; SELECT count(*) FROM test_table; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node -ERROR: failed to execute task 1 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. COMMIT; -- Cancel a real-time executor query - in sequential mode SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); @@ -209,8 +207,14 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); (1 row) SELECT count(*) FROM test_table; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. count ------- 6 @@ -226,8 +230,14 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); BEGIN; SELECT count(*) FROM test_table; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. count ------- 6 @@ -289,8 +299,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); BEGIN; SELECT count(*) FROM test_table; -WARNING: could not consume data from worker node -WARNING: could not consume data from worker node +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. count ------- 6 diff --git a/src/test/regress/expected/failure_real_time_select_9.out b/src/test/regress/expected/failure_real_time_select_9.out deleted file mode 100644 index 2736cc9ca..000000000 --- a/src/test/regress/expected/failure_real_time_select_9.out +++ /dev/null @@ -1,314 +0,0 @@ --- --- Failure tests for real time select queries --- -CREATE SCHEMA real_time_select_failure; -SET search_path TO 'real_time_select_failure'; -SET citus.next_shard_id TO 190000; --- Preparation -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_count to 4; -SET citus.shard_replication_factor to 1; --- create tables -CREATE TABLE test_table(id int, value_1 int, value_2 int); -SELECT create_distributed_table('test_table','id'); - create_distributed_table --------------------------- - -(1 row) - --- Populate data to the table -INSERT INTO test_table VALUES(1,1,1),(1,2,2),(2,1,1),(2,2,2),(3,1,1),(3,2,2); --- Kill when the first COPY command arrived, since we have a single placement --- it is expected to error out. -SET client_min_messages TO ERROR; -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SET client_min_messages TO DEFAULT; --- Kill the connection with a CTE -SELECT citus.mitmproxy('conn.onQuery(query=".*SELECT.*test_table.*").kill()'); - mitmproxy ------------ - -(1 row) - -WITH -results AS (SELECT * FROM test_table) -SELECT * FROM test_table, results -WHERE test_table.id = results.id; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. --- Since the outer query uses the connection opened by the CTE, --- killing connection after first successful query should break. -SET client_min_messages TO ERROR; -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -WITH results AS (SELECT * FROM test_table) -SELECT * FROM test_table, results -WHERE test_table.id = results.id; -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -SET client_min_messages TO DEFAULT; --- In parallel execution mode Citus opens separate connections for each shard --- so killing the connection after the first copy does not break it. -SET citus.force_max_query_parallelization=ON; -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 6 -(1 row) - --- set back the force flag to original value -SET citus.force_max_query_parallelization=OFF; --- Cancel a real-time executor query -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request --- Cancel a query within the transaction -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Cancel a query within the transaction after a multi-shard update -SELECT citus.mitmproxy('conn.onQuery(query=".*SELECT.*test_table.*").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -UPDATE test_table SET value_1 = value_1 + 1; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Cancel a query with CTE -SELECT citus.mitmproxy('conn.onQuery(query=".*SELECT.*test_table.*").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -WITH -results AS (SELECT * FROM test_table) -SELECT * FROM test_table -WHERE test_table.id > (SELECT id FROM results); -ERROR: canceling statement due to user request --- Citus fails if the connection that is already used fails afterwards -SET citus.multi_shard_modify_mode to sequential; -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -COMMIT; --- Cancel a real-time executor query - in sequential mode -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request --- Cancel a query within the transaction - in sequential mode -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Cancel the query within a transaction after a single succesful run -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Now, test with replication factor 2, tests are expected to pass --- since we have two placements for the same shard -DROP TABLE test_table; -SET citus.multi_shard_modify_mode to default; --- Create table with shard placements on each node -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_replication_factor to 2; -CREATE TABLE test_table(id int, value_1 int, value_2 int); -SELECT create_distributed_table('test_table','id'); - create_distributed_table --------------------------- - -(1 row) - --- Populate data to the table -INSERT INTO test_table VALUES(1,1,1),(1,2,2),(2,1,1),(2,2,2),(3,1,1),(3,2,2); --- Kill when the first SELECT command arrived, since we have placements on each node --- it shouldn't fail. -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. - count -------- - 6 -(1 row) - --- Kill within the transaction, since we have placements on each node --- it shouldn't fail. -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. - count -------- - 6 -(1 row) - -COMMIT; --- Cancel a real-time executor query -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request --- Cancel a query within the transaction -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Cancel a query within the transaction after a multi-shard update -SELECT citus.mitmproxy('conn.onQuery(query=".*SELECT.*test_table.*").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -UPDATE test_table SET value_1 = value_1 + 1; -SELECT count(*) FROM test_table; -ERROR: canceling statement due to user request -COMMIT; --- Cancel a query with CTE -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -WITH -results AS (SELECT * FROM test_table) -SELECT * FROM test_table -WHERE test_table.id > (SELECT id FROM results); -ERROR: canceling statement due to user request --- Since we have the placement on each node, test with sequential mode --- should pass as well. -SET citus.multi_shard_modify_mode to sequential; -SELECT citus.mitmproxy('conn.onQuery(query="SELECT|COPY").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SELECT count(*) FROM test_table; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. - count -------- - 6 -(1 row) - -COMMIT; -DROP SCHEMA real_time_select_failure CASCADE; -NOTICE: drop cascades to table test_table -SET search_path TO default; diff --git a/src/test/regress/expected/failure_ref_tables.out b/src/test/regress/expected/failure_ref_tables.out index dc1766c1d..5727cb90c 100644 --- a/src/test/regress/expected/failure_ref_tables.out +++ b/src/test/regress/expected/failure_ref_tables.out @@ -33,10 +33,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO ref_table VALUES (5, 6); -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT COUNT(*) FROM ref_table WHERE key=5; count ------- @@ -51,10 +51,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); (1 row) UPDATE ref_table SET key=7 RETURNING value; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT COUNT(*) FROM ref_table WHERE key=7; count ------- @@ -71,10 +71,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); BEGIN; DELETE FROM ref_table WHERE key=5; UPDATE ref_table SET key=value; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 COMMIT; SELECT COUNT(*) FROM ref_table WHERE key=value; count diff --git a/src/test/regress/expected/failure_ref_tables_9.out b/src/test/regress/expected/failure_ref_tables_9.out deleted file mode 100644 index 5727cb90c..000000000 --- a/src/test/regress/expected/failure_ref_tables_9.out +++ /dev/null @@ -1,99 +0,0 @@ -SET citus.next_shard_id TO 100500; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE ref_table (key int, value int); -SELECT create_reference_table('ref_table'); - create_reference_table ------------------------- - -(1 row) - -\copy ref_table FROM stdin delimiter ','; -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -SELECT COUNT(*) FROM ref_table; - count -------- - 4 -(1 row) - --- verify behavior of single INSERT; should fail to execute -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO ref_table VALUES (5, 6); -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT COUNT(*) FROM ref_table WHERE key=5; - count -------- - 0 -(1 row) - --- verify behavior of UPDATE ... RETURNING; should not execute -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE ref_table SET key=7 RETURNING value; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT COUNT(*) FROM ref_table WHERE key=7; - count -------- - 0 -(1 row) - --- verify fix to #2214; should raise error and fail to execute -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -DELETE FROM ref_table WHERE key=5; -UPDATE ref_table SET key=value; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -COMMIT; -SELECT COUNT(*) FROM ref_table WHERE key=value; - count -------- - 0 -(1 row) - --- all shards should still be healthy -SELECT COUNT(*) FROM pg_dist_shard_placement WHERE shardstate = 3; - count -------- - 0 -(1 row) - --- ==== Clean up, we're done here ==== -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE ref_table; diff --git a/src/test/regress/expected/failure_savepoints.out b/src/test/regress/expected/failure_savepoints.out index ccd6a4dfe..02163c4a3 100644 --- a/src/test/regress/expected/failure_savepoints.out +++ b/src/test/regress/expected/failure_savepoints.out @@ -40,18 +40,16 @@ INSERT INTO artists VALUES (5, 'Asher Lev'); SAVEPOINT s1; WARNING: connection not open CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -DELETE FROM artists WHERE id=4; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 WARNING: connection error: localhost:9060 DETAIL: connection not open WARNING: connection not open CONTEXT: while executing command on localhost:9060 WARNING: connection not open CONTEXT: while executing command on localhost:9060 -ERROR: could not modify any active placements +ERROR: connection not open +CONTEXT: while executing command on localhost:9060 +DELETE FROM artists WHERE id=4; +ERROR: current transaction is aborted, commands ignored until end of transaction block RELEASE SAVEPOINT s1; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; @@ -131,12 +129,18 @@ RELEASE SAVEPOINT s1; SAVEPOINT s2; INSERT INTO artists VALUES (5, 'Jacob Kahn'); RELEASE SAVEPOINT s2; +WARNING: AbortSubTransaction while in COMMIT state +WARNING: connection not open +CONTEXT: while executing command on localhost:9060 +WARNING: connection error: localhost:9060 +DETAIL: connection not open WARNING: connection not open CONTEXT: while executing command on localhost:9060 WARNING: connection not open CONTEXT: while executing command on localhost:9060 +ERROR: connection not open +CONTEXT: while executing command on localhost:9060 COMMIT; -ERROR: could not make changes to shard 100950 on any node SELECT * FROM artists WHERE id IN (4, 5); id | name ----+----------------- @@ -208,6 +212,10 @@ INSERT INTO artists VALUES (7, 'Emily Carr'); ROLLBACK TO SAVEPOINT s1; WARNING: connection not open WARNING: connection not open +WARNING: connection not open +WARNING: connection error: localhost:9060 +WARNING: connection not open +WARNING: connection not open COMMIT; ERROR: could not make changes to shard 100950 on any node SELECT * FROM artists WHERE id=6; @@ -240,24 +248,22 @@ BEGIN; INSERT INTO researchers VALUES (7, 4, 'Jan Plaza'); SAVEPOINT s1; WARNING: connection not open -WARNING: connection not open -INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); -ROLLBACK TO s1; -WARNING: connection not open WARNING: connection error: localhost:9060 WARNING: connection not open WARNING: connection not open +ERROR: connection not open +INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); +ERROR: current transaction is aborted, commands ignored until end of transaction block +ROLLBACK TO s1; +ERROR: savepoint "s1" does not exist RELEASE SAVEPOINT s1; +ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -WARNING: connection not open -WARNING: connection not open -WARNING: connection not open -- should see correct results from healthy placement and one bad placement SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+----------- - 7 | 4 | Jan Plaza -(1 row) + id | lab_id | name +----+--------+------ +(0 rows) UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE shardstate = 3 AND shardid IN ( @@ -265,8 +271,7 @@ WHERE shardstate = 3 AND shardid IN ( ) RETURNING placementid; placementid ------------- - 152 -(1 row) +(0 rows) TRUNCATE researchers; -- fail at rollback @@ -285,15 +290,12 @@ WARNING: connection not open WARNING: connection not open RELEASE SAVEPOINT s1; COMMIT; -WARNING: connection not open -WARNING: connection not open -WARNING: connection not open +ERROR: failure on connection marked as essential: localhost:9060 -- should see correct results from healthy placement and one bad placement SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+----------- - 7 | 4 | Jan Plaza -(1 row) + id | lab_id | name +----+--------+------ +(0 rows) UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE shardstate = 3 AND shardid IN ( @@ -301,8 +303,7 @@ WHERE shardstate = 3 AND shardid IN ( ) RETURNING placementid; placementid ------------- - 152 -(1 row) +(0 rows) TRUNCATE researchers; -- fail at release @@ -318,18 +319,19 @@ SAVEPOINT s1; INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); ROLLBACK TO s1; RELEASE SAVEPOINT s1; +WARNING: AbortSubTransaction while in COMMIT state +WARNING: connection not open +WARNING: connection error: localhost:9060 WARNING: connection not open WARNING: connection not open +WARNING: savepoint "savepoint_3" does not exist +ERROR: connection not open COMMIT; -WARNING: connection not open -WARNING: connection not open -WARNING: connection not open -- should see correct results from healthy placement and one bad placement SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+----------- - 7 | 4 | Jan Plaza -(1 row) + id | lab_id | name +----+--------+------ +(0 rows) UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE shardstate = 3 AND shardid IN ( @@ -337,8 +339,7 @@ WHERE shardstate = 3 AND shardid IN ( ) RETURNING placementid; placementid ------------- - 152 -(1 row) +(0 rows) TRUNCATE researchers; -- clean up diff --git a/src/test/regress/expected/failure_savepoints_9.out b/src/test/regress/expected/failure_savepoints_9.out deleted file mode 100644 index 02163c4a3..000000000 --- a/src/test/regress/expected/failure_savepoints_9.out +++ /dev/null @@ -1,353 +0,0 @@ --- We have two different output files for this failure test because the --- failure behaviour of SAVEPOINT and RELEASE commands are different if --- we use the executor. If we use it, these commands error out if any of --- the placement commands fail. Otherwise, we might mark the placement --- as invalid and continue with a WARNING. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 1; -- one shard per worker -SET citus.next_shard_id TO 100950; -ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 150; -CREATE TABLE artists ( - id bigint NOT NULL, - name text NOT NULL -); -SELECT create_distributed_table('artists', 'id'); - create_distributed_table --------------------------- - -(1 row) - --- add some data -INSERT INTO artists VALUES (1, 'Pablo Picasso'); -INSERT INTO artists VALUES (2, 'Vincent van Gogh'); -INSERT INTO artists VALUES (3, 'Claude Monet'); -INSERT INTO artists VALUES (4, 'William Kurelek'); --- simply fail at SAVEPOINT -SELECT citus.mitmproxy('conn.onQuery(query="^SAVEPOINT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO artists VALUES (5, 'Asher Lev'); -SAVEPOINT s1; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection error: localhost:9060 -DETAIL: connection not open -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -DELETE FROM artists WHERE id=4; -ERROR: current transaction is aborted, commands ignored until end of transaction block -RELEASE SAVEPOINT s1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; -SELECT * FROM artists WHERE id IN (4, 5); - id | name -----+----------------- - 4 | William Kurelek -(1 row) - --- fail at RELEASE -SELECT citus.mitmproxy('conn.onQuery(query="^RELEASE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -UPDATE artists SET name='a'; -SAVEPOINT s1; -DELETE FROM artists WHERE id=4; -RELEASE SAVEPOINT s1; -WARNING: AbortSubTransaction while in COMMIT state -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection error: localhost:9060 -DETAIL: connection not open -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: savepoint "savepoint_2" does not exist -CONTEXT: while executing command on localhost:57637 -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -ROLLBACK; -SELECT * FROM artists WHERE id IN (4, 5); - id | name -----+----------------- - 4 | William Kurelek -(1 row) - --- fail at ROLLBACK -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO artists VALUES (5, 'Asher Lev'); -SAVEPOINT s1; -DELETE FROM artists WHERE id=4; -ROLLBACK TO SAVEPOINT s1; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -COMMIT; -ERROR: could not make changes to shard 100950 on any node -SELECT * FROM artists WHERE id IN (4, 5); - id | name -----+----------------- - 4 | William Kurelek -(1 row) - --- fail at second RELEASE -SELECT citus.mitmproxy('conn.onQuery(query="^RELEASE").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SAVEPOINT s1; -DELETE FROM artists WHERE id=4; -RELEASE SAVEPOINT s1; -SAVEPOINT s2; -INSERT INTO artists VALUES (5, 'Jacob Kahn'); -RELEASE SAVEPOINT s2; -WARNING: AbortSubTransaction while in COMMIT state -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection error: localhost:9060 -DETAIL: connection not open -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -COMMIT; -SELECT * FROM artists WHERE id IN (4, 5); - id | name -----+----------------- - 4 | William Kurelek -(1 row) - --- fail at second ROLLBACK -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -SAVEPOINT s1; -UPDATE artists SET name='A' WHERE id=4; -ROLLBACK TO SAVEPOINT s1; -SAVEPOINT s2; -DELETE FROM artists WHERE id=5; -ROLLBACK TO SAVEPOINT s2; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -COMMIT; -ERROR: could not make changes to shard 100950 on any node -SELECT * FROM artists WHERE id IN (4, 5); - id | name -----+----------------- - 4 | William Kurelek -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="^RELEASE").after(1).kill()'); - mitmproxy ------------ - -(1 row) - --- Release after rollback -BEGIN; -SAVEPOINT s1; -ROLLBACK TO s1; -RELEASE SAVEPOINT s1; -SAVEPOINT s2; -INSERT INTO artists VALUES (6, 'John J. Audubon'); -INSERT INTO artists VALUES (7, 'Emily Carr'); -ROLLBACK TO s2; -RELEASE SAVEPOINT s2; -COMMIT; -SELECT * FROM artists WHERE id=7; - id | name -----+------ -(0 rows) - -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - --- Recover from errors -\set VERBOSITY terse -BEGIN; -SAVEPOINT s1; -SAVEPOINT s2; -INSERT INTO artists VALUES (6, 'John J. Audubon'); -INSERT INTO artists VALUES (7, 'Emily Carr'); -INSERT INTO artists VALUES (7, 'Emily Carr'); -ROLLBACK TO SAVEPOINT s1; -WARNING: connection not open -WARNING: connection not open -WARNING: connection not open -WARNING: connection error: localhost:9060 -WARNING: connection not open -WARNING: connection not open -COMMIT; -ERROR: could not make changes to shard 100950 on any node -SELECT * FROM artists WHERE id=6; - id | name -----+------ -(0 rows) - --- replication factor > 1 -CREATE TABLE researchers ( - id bigint NOT NULL, - lab_id int NOT NULL, - name text NOT NULL -); -SET citus.shard_count = 1; -SET citus.shard_replication_factor = 2; -- single shard, on both workers -SELECT create_distributed_table('researchers', 'lab_id', 'hash'); - create_distributed_table --------------------------- - -(1 row) - --- simply fail at SAVEPOINT -SELECT citus.mitmproxy('conn.onQuery(query="^SAVEPOINT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO researchers VALUES (7, 4, 'Jan Plaza'); -SAVEPOINT s1; -WARNING: connection not open -WARNING: connection error: localhost:9060 -WARNING: connection not open -WARNING: connection not open -ERROR: connection not open -INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); -ERROR: current transaction is aborted, commands ignored until end of transaction block -ROLLBACK TO s1; -ERROR: savepoint "s1" does not exist -RELEASE SAVEPOINT s1; -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; --- should see correct results from healthy placement and one bad placement -SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+------ -(0 rows) - -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardstate = 3 AND shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'researchers'::regclass -) RETURNING placementid; - placementid -------------- -(0 rows) - -TRUNCATE researchers; --- fail at rollback -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO researchers VALUES (7, 4, 'Jan Plaza'); -SAVEPOINT s1; -INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); -ROLLBACK TO s1; -WARNING: connection not open -WARNING: connection not open -RELEASE SAVEPOINT s1; -COMMIT; -ERROR: failure on connection marked as essential: localhost:9060 --- should see correct results from healthy placement and one bad placement -SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+------ -(0 rows) - -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardstate = 3 AND shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'researchers'::regclass -) RETURNING placementid; - placementid -------------- -(0 rows) - -TRUNCATE researchers; --- fail at release -SELECT citus.mitmproxy('conn.onQuery(query="^RELEASE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO researchers VALUES (7, 4, 'Jan Plaza'); -SAVEPOINT s1; -INSERT INTO researchers VALUES (8, 4, 'Alonzo Church'); -ROLLBACK TO s1; -RELEASE SAVEPOINT s1; -WARNING: AbortSubTransaction while in COMMIT state -WARNING: connection not open -WARNING: connection error: localhost:9060 -WARNING: connection not open -WARNING: connection not open -WARNING: savepoint "savepoint_3" does not exist -ERROR: connection not open -COMMIT; --- should see correct results from healthy placement and one bad placement -SELECT * FROM researchers WHERE lab_id = 4; - id | lab_id | name -----+--------+------ -(0 rows) - -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardstate = 3 AND shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'researchers'::regclass -) RETURNING placementid; - placementid -------------- -(0 rows) - -TRUNCATE researchers; --- clean up -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE artists; -DROP TABLE researchers; diff --git a/src/test/regress/expected/failure_single_mod.out b/src/test/regress/expected/failure_single_mod.out index 8f5ce272d..926682b7c 100644 --- a/src/test/regress/expected/failure_single_mod.out +++ b/src/test/regress/expected/failure_single_mod.out @@ -27,10 +27,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); (1 row) INSERT INTO mod_test VALUES (2, 6); -WARNING: server closed the connection unexpectedly +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT COUNT(*) FROM mod_test WHERE key=2; count ------- @@ -63,10 +63,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); (1 row) UPDATE mod_test SET value='ok' WHERE key=2 RETURNING key; -WARNING: server closed the connection unexpectedly +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 key ----- 2 @@ -102,17 +102,11 @@ INSERT INTO mod_test VALUES (2, 6); INSERT INTO mod_test VALUES (2, 7); DELETE FROM mod_test WHERE key=2 AND value = '7'; UPDATE mod_test SET value='ok' WHERE key=2; -WARNING: server closed the connection unexpectedly +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 COMMIT; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 SELECT COUNT(*) FROM mod_test WHERE key=2; count ------- diff --git a/src/test/regress/expected/failure_single_mod_9.out b/src/test/regress/expected/failure_single_mod_9.out deleted file mode 100644 index 926682b7c..000000000 --- a/src/test/regress/expected/failure_single_mod_9.out +++ /dev/null @@ -1,128 +0,0 @@ -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 2; -CREATE TABLE mod_test (key int, value text); -SELECT create_distributed_table('mod_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- verify behavior of single INSERT; should mark shard as failed -SELECT citus.mitmproxy('conn.onQuery(query="^INSERT").kill()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO mod_test VALUES (2, 6); -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT COUNT(*) FROM mod_test WHERE key=2; - count -------- - 1 -(1 row) - --- some clean up -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'mod_test'::regclass -) AND shardstate = 3 RETURNING placementid; - placementid -------------- - 137 -(1 row) - -TRUNCATE mod_test; --- verify behavior of UPDATE ... RETURNING; should mark as failed -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -INSERT INTO mod_test VALUES (2, 6); -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - -UPDATE mod_test SET value='ok' WHERE key=2 RETURNING key; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. - key ------ - 2 -(1 row) - -SELECT COUNT(*) FROM mod_test WHERE value='ok'; - count -------- - 1 -(1 row) - --- some clean up -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'mod_test'::regclass -) AND shardstate = 3 RETURNING placementid; - placementid -------------- - 137 -(1 row) - -TRUNCATE mod_test; --- verify behavior of multi-statement modifications to a single shard --- should succeed but mark a placement as failed -SELECT citus.mitmproxy('conn.onQuery(query="^UPDATE").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO mod_test VALUES (2, 6); -INSERT INTO mod_test VALUES (2, 7); -DELETE FROM mod_test WHERE key=2 AND value = '7'; -UPDATE mod_test SET value='ok' WHERE key=2; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -COMMIT; -SELECT COUNT(*) FROM mod_test WHERE key=2; - count -------- - 1 -(1 row) - --- some clean up -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'mod_test'::regclass -) AND shardstate = 3 RETURNING placementid; - placementid -------------- - 137 -(1 row) - -TRUNCATE mod_test; --- ==== Clean up, we're done here ==== -DROP TABLE mod_test; diff --git a/src/test/regress/expected/failure_single_select_9.out b/src/test/regress/expected/failure_single_select_9.out deleted file mode 100644 index fbe351d40..000000000 --- a/src/test/regress/expected/failure_single_select_9.out +++ /dev/null @@ -1,247 +0,0 @@ -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 2; -CREATE TABLE select_test (key int, value text); -SELECT create_distributed_table('select_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- put data in shard for which mitm node is first placement -INSERT INTO select_test VALUES (3, 'test data'); -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").kill()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM select_test WHERE key = 3; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 - key | value ------+----------- - 3 | test data -(1 row) - -SELECT * FROM select_test WHERE key = 3; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 - key | value ------+----------- - 3 | test data -(1 row) - --- kill after first SELECT; txn should work (though placement marked bad) -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO select_test VALUES (3, 'more data'); -SELECT * FROM select_test WHERE key = 3; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 - key | value ------+----------- - 3 | test data - 3 | more data -(2 rows) - -INSERT INTO select_test VALUES (3, 'even more data'); -SELECT * FROM select_test WHERE key = 3; - key | value ------+---------------- - 3 | test data - 3 | more data - 3 | even more data -(3 rows) - -COMMIT; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 --- some clean up -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'select_test'::regclass -); -TRUNCATE select_test; --- now the same tests with query cancellation --- put data in shard for which mitm node is first placement -INSERT INTO select_test VALUES (3, 'test data'); -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM select_test WHERE key = 3; -ERROR: canceling statement due to user request -SELECT * FROM select_test WHERE key = 3; -ERROR: canceling statement due to user request --- cancel after first SELECT; txn should fail and nothing should be marked as invalid -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO select_test VALUES (3, 'more data'); -SELECT * FROM select_test WHERE key = 3; -ERROR: canceling statement due to user request -COMMIT; --- show that all placements are OK -SELECT DISTINCT shardstate FROM pg_dist_shard_placement -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'select_test'::regclass -); - shardstate ------------- - 1 -(1 row) - -TRUNCATE select_test; --- cancel the second query --- error after second SELECT; txn should fail -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").after(1).cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO select_test VALUES (3, 'more data'); -SELECT * FROM select_test WHERE key = 3; - key | value ------+----------- - 3 | more data -(1 row) - -INSERT INTO select_test VALUES (3, 'even more data'); -SELECT * FROM select_test WHERE key = 3; -ERROR: canceling statement due to user request -COMMIT; --- error after second SELECT; txn should work (though placement marked bad) -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").after(1).reset()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -INSERT INTO select_test VALUES (3, 'more data'); -SELECT * FROM select_test WHERE key = 3; - key | value ------+----------- - 3 | more data -(1 row) - -INSERT INTO select_test VALUES (3, 'even more data'); -SELECT * FROM select_test WHERE key = 3; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 - key | value ------+---------------- - 3 | more data - 3 | even more data -(2 rows) - -COMMIT; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").after(2).kill()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT recover_prepared_transactions(); -ERROR: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 --- bug from https://github.com/citusdata/citus/issues/1926 -SET citus.max_cached_conns_per_worker TO 0; -- purge cache -DROP TABLE select_test; -SET citus.shard_count = 2; -SET citus.shard_replication_factor = 1; -CREATE TABLE select_test (key int, value text); -SELECT create_distributed_table('select_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - -SET citus.max_cached_conns_per_worker TO 1; -- allow connection to be cached -INSERT INTO select_test VALUES (1, 'test data'); -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").after(1).kill()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM select_test WHERE key = 1; - key | value ------+----------- - 1 | test data -(1 row) - -SELECT * FROM select_test WHERE key = 1; -WARNING: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -CONTEXT: while executing command on localhost:9060 -ERROR: could not receive query results --- now the same test with query cancellation -SELECT citus.mitmproxy('conn.onQuery(query="^SELECT").after(1).cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM select_test WHERE key = 1; - key | value ------+----------- - 1 | test data -(1 row) - -SELECT * FROM select_test WHERE key = 1; -ERROR: canceling statement due to user request --- ==== Clean up, we're done here ==== -DROP TABLE select_test; diff --git a/src/test/regress/expected/failure_truncate.out b/src/test/regress/expected/failure_truncate.out index b9208ccac..4c86ff171 100644 --- a/src/test/regress/expected/failure_truncate.out +++ b/src/test/regress/expected/failure_truncate.out @@ -102,7 +102,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) TRUNCATE test_table; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -156,10 +159,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test (1 row) TRUNCATE test_table; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -430,10 +433,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE").after(2).kill()'); (1 row) TRUNCATE reference_table CASCADE; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -632,7 +635,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) TRUNCATE test_table; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -686,10 +692,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE truncate_failure.tes (1 row) TRUNCATE test_table; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -1008,7 +1014,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL R (1 row) TRUNCATE test_table; -ERROR: failure on connection marked as essential: localhost:9060 +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly + This probably means the server terminated abnormally + before or while processing the request. SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- @@ -1062,10 +1071,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test (1 row) TRUNCATE test_table; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- diff --git a/src/test/regress/expected/failure_truncate_9.out b/src/test/regress/expected/failure_truncate_9.out deleted file mode 100644 index 4c86ff171..000000000 --- a/src/test/regress/expected/failure_truncate_9.out +++ /dev/null @@ -1,1299 +0,0 @@ --- --- Test TRUNCATE command failures --- -CREATE SCHEMA truncate_failure; -SET search_path TO 'truncate_failure'; -SET citus.next_shard_id TO 120000; --- we don't want to see the prepared transaction numbers in the warnings -SET client_min_messages TO ERROR; --- do not cache any connections -SET citus.max_cached_conns_per_worker TO 0; --- use a predictable number of connections per task -SET citus.force_max_query_parallelization TO on; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- we'll start with replication factor 1, 1PC and parallel mode -SET citus.multi_shard_commit_protocol TO '1pc'; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 1; -CREATE TABLE test_table (key int, value int); -SELECT create_distributed_table('test_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid - WHERE logicalrelid='truncate_failure.test_table'::regclass AND shardstate != 1; --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test_table").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test_table").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends COMMIT --- One shard should not get truncated but the other should --- since it is sent from another connection. --- Thus, we should see a partially successful truncate --- Note: This is the result of using 1pc and there is no way to recover from it -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 8 -(1 row) - --- refill the table -TRUNCATE test_table; -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- cancel as soon as the coordinator sends COMMIT --- interrupts are held during COMMIT/ROLLBACK, so the command --- should have been applied without any issues since cancel is ignored -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - --- refill the table -TRUNCATE test_table; -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -SET client_min_messages TO WARNING; --- now kill just after the worker sends response to --- COMMIT command, so we'll have lots of warnings but the command --- should have been committed both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: could not commit transaction for shard 120002 on any active node -WARNING: could not commit transaction for shard 120000 on any active node -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -SET client_min_messages TO ERROR; -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- now cancel just after the worker sends response to --- but Postgres doesn't accept interrupts during COMMIT and ROLLBACK --- so should not cancel at all, so not an effective test but adding in --- case Citus messes up this behaviour -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- Let's test Truncate on reference tables with a FK from a hash distributed table -CREATE TABLE reference_table(i int UNIQUE); -INSERT INTO reference_table SELECT x FROM generate_series(1,20) as f(x); -SELECT create_reference_table('reference_table'); - create_reference_table ------------------------- - -(1 row) - -ALTER TABLE test_table ADD CONSTRAINT foreign_key FOREIGN KEY (value) REFERENCES reference_table(i); --- immediately kill when we see prepare transaction to see if the command --- still cascaded to referencing table or failed successfuly -SELECT citus.mitmproxy('conn.onQuery(query="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - -SELECT count(*) FROM reference_table; - count -------- - 20 -(1 row) - --- immediately cancel when we see prepare transaction to see if the command --- still cascaded to referencing table or failed successfuly -SELECT citus.mitmproxy('conn.onQuery(query="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - -SELECT count(*) FROM reference_table; - count -------- - 20 -(1 row) - --- immediately kill when we see cascading TRUNCATE on the hash table to see --- rollbacked properly -SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE").after(2).kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - -SELECT count(*) FROM reference_table; - count -------- - 20 -(1 row) - --- immediately cancel when we see cascading TRUNCATE on the hash table to see --- if the command still cascaded to referencing table or failed successfuly -SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE").after(2).cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - -SELECT count(*) FROM reference_table; - count -------- - 20 -(1 row) - --- immediately kill after we get prepare transaction complete --- to see if the command still cascaded to referencing table or --- failed successfuly -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- immediately cancel after we get prepare transaction complete --- to see if the command still cascaded to referencing table or --- failed successfuly -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE reference_table CASCADE; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- now, lets test with 2PC -SET citus.multi_shard_commit_protocol TO '2pc'; --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE truncate_failure.test_table").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE truncate_failure.test_table").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- killing on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="^PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - --- we should be able to revocer the transaction and --- see that the command is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 2 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancelling on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="^PREPARE TRANSACTION").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - --- we should be able to revocer the transaction and --- see that the command is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 1 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- killing on command complete of COMMIT PREPARE, we should see that the command succeeds --- and all the workers committed -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- we shouldn't have any prepared transactions in the workers -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- kill as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - --- Since we kill connections to one worker after commit arrives but the --- other worker connections are healthy, we cannot commit on 1 worker --- which has 2 active shard placements, but the other does. That's why --- we expect to see 2 recovered prepared transactions. -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 2 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- finally, test failing on ROLLBACK with 2CPC --- fail just after the coordinator sends the ROLLBACK --- so the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -TRUNCATE test_table; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- but now kill just after the worker sends response to --- ROLLBACK command, so we'll have lots of warnings but the command --- should have been rollbacked both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -TRUNCATE test_table; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- final set of tests with 2PC and replication factor = 2 -SET citus.multi_shard_commit_protocol TO '2pc'; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 2; --- re-create the table with replication factor 2 -DROP TABLE test_table CASCADE; -CREATE TABLE test_table (key int, value int); -SELECT create_distributed_table('test_table', 'key'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid - WHERE logicalrelid='truncate_failure.test_table'::regclass AND shardstate != 1; --- in the first test, kill just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel just in the first --- response we get from the worker -SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends begin -SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- kill as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test_table").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- cancel as soon as the coordinator sends TRUNCATE TABLE command -SELECT citus.mitmproxy('conn.onQuery(query="TRUNCATE TABLE truncate_failure.test_table").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- killing on PREPARE should be fine, everything should be rollbacked -SELECT citus.mitmproxy('conn.onCommandComplete(command="PREPARE TRANSACTION").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -ERROR: connection not open -CONTEXT: while executing command on localhost:9060 -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - --- we should be able to revocer the transaction and --- see that the command is rollbacked -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 4 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- killing on command complete of COMMIT PREPARE, we should see that the command succeeds --- and all the workers committed -SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - --- we shouldn't have any prepared transactions in the workers -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- kill as soon as the coordinator sends COMMIT -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); - mitmproxy ------------ - -(1 row) - -TRUNCATE test_table; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - --- Since we kill connections to one worker after commit arrives but the --- other worker connections are healthy, we cannot commit on 1 worker --- which has 4 active shard placements (2 shards, replication factor=2), --- but the other does. That's why we expect to see 4 recovered prepared --- transactions. -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 4 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 0 -(1 row) - -INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- finally, test failing on ROLLBACK with 2CPC --- fail just after the coordinator sends the ROLLBACK --- so the command can be rollbacked -SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -TRUNCATE test_table; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - --- but now kill just after the worker sends response to --- ROLLBACK command, so we'll have lots of warnings but the command --- should have been rollbacked both on the distributed table and the placements -SELECT citus.mitmproxy('conn.onCommandComplete(command="^ROLLBACK").kill()'); - mitmproxy ------------ - -(1 row) - -BEGIN; -TRUNCATE test_table; -ROLLBACK; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SELECT * FROM unhealthy_shard_count; - count -------- - 0 -(1 row) - -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -SELECT count(*) FROM test_table; - count -------- - 20 -(1 row) - -DROP SCHEMA truncate_failure CASCADE; -SET search_path TO default; diff --git a/src/test/regress/expected/failure_vacuum.out b/src/test/regress/expected/failure_vacuum.out index 50fde6940..430d21b6d 100644 --- a/src/test/regress/expected/failure_vacuum.out +++ b/src/test/regress/expected/failure_vacuum.out @@ -31,10 +31,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM").kill()'); (1 row) VACUUM vacuum_test; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^ANALYZE").kill()'); mitmproxy ----------- @@ -42,10 +42,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^ANALYZE").kill()'); (1 row) ANALYZE vacuum_test; -ERROR: server closed the connection unexpectedly +WARNING: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); mitmproxy ----------- @@ -53,11 +53,6 @@ SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); (1 row) ANALYZE vacuum_test; -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -WARNING: failed to commit transaction on localhost:9060 -WARNING: connection not open -CONTEXT: while executing command on localhost:9060 -- ANALYZE transactions being critical is an open question, see #2430 -- show that we marked as INVALID on COMMIT FAILURE SELECT shardid, shardstate FROM pg_dist_shard_placement where shardstate != 1 AND @@ -116,10 +111,10 @@ SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM.*other").kill()'); (1 row) VACUUM vacuum_test, other_vacuum_test; -ERROR: server closed the connection unexpectedly +ERROR: connection error: localhost:9060 +DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -CONTEXT: while executing command on localhost:9060 SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM.*other").cancel(' || pg_backend_pid() || ')'); mitmproxy ----------- diff --git a/src/test/regress/expected/failure_vacuum_8.out b/src/test/regress/expected/failure_vacuum_1.out similarity index 100% rename from src/test/regress/expected/failure_vacuum_8.out rename to src/test/regress/expected/failure_vacuum_1.out diff --git a/src/test/regress/expected/failure_vacuum_9.out b/src/test/regress/expected/failure_vacuum_9.out deleted file mode 100644 index 430d21b6d..000000000 --- a/src/test/regress/expected/failure_vacuum_9.out +++ /dev/null @@ -1,133 +0,0 @@ --- We have different output files for the executor. This is because --- we don't mark transactions with ANALYZE as critical anymore, and --- get WARNINGs instead of ERRORs. -SET citus.next_shard_id TO 12000000; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -SET citus.shard_count = 1; -SET citus.shard_replication_factor = 2; -- one shard per worker -SET citus.multi_shard_commit_protocol TO '1pc'; -CREATE TABLE vacuum_test (key int, value int); -SELECT create_distributed_table('vacuum_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - -SELECT citus.clear_network_traffic(); - clear_network_traffic ------------------------ - -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM").kill()'); - mitmproxy ------------ - -(1 row) - -VACUUM vacuum_test; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^ANALYZE").kill()'); - mitmproxy ------------ - -(1 row) - -ANALYZE vacuum_test; -WARNING: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); - mitmproxy ------------ - -(1 row) - -ANALYZE vacuum_test; --- ANALYZE transactions being critical is an open question, see #2430 --- show that we marked as INVALID on COMMIT FAILURE -SELECT shardid, shardstate FROM pg_dist_shard_placement where shardstate != 1 AND -shardid in ( SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'vacuum_test'::regclass); - shardid | shardstate -----------+------------ - 12000000 | 3 -(1 row) - -UPDATE pg_dist_shard_placement SET shardstate = 1 -WHERE shardid IN ( - SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'vacuum_test'::regclass -); --- the same tests with cancel -SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -VACUUM vacuum_test; -ERROR: canceling statement due to user request -SELECT citus.mitmproxy('conn.onQuery(query="^ANALYZE").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ANALYZE vacuum_test; -ERROR: canceling statement due to user request --- cancel during COMMIT should be ignored -SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -ANALYZE vacuum_test; -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -CREATE TABLE other_vacuum_test (key int, value int); -SELECT create_distributed_table('other_vacuum_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - -SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM.*other").kill()'); - mitmproxy ------------ - -(1 row) - -VACUUM vacuum_test, other_vacuum_test; -ERROR: connection error: localhost:9060 -DETAIL: server closed the connection unexpectedly - This probably means the server terminated abnormally - before or while processing the request. -SELECT citus.mitmproxy('conn.onQuery(query="^VACUUM.*other").cancel(' || pg_backend_pid() || ')'); - mitmproxy ------------ - -(1 row) - -VACUUM vacuum_test, other_vacuum_test; -ERROR: canceling statement due to user request --- ==== Clean up, we're done here ==== -SELECT citus.mitmproxy('conn.allow()'); - mitmproxy ------------ - -(1 row) - -DROP TABLE vacuum_test, other_vacuum_test; diff --git a/src/test/regress/expected/isolation_citus_dist_activity_9.out b/src/test/regress/expected/isolation_citus_dist_activity_9.out deleted file mode 100644 index 3c6cea3c3..000000000 --- a/src/test/regress/expected/isolation_citus_dist_activity_9.out +++ /dev/null @@ -1,229 +0,0 @@ -Parsed test spec with 3 sessions - -starting permutation: s1-cache-connections s1-begin s2-begin s3-begin s1-alter-table s2-sleep s2-view-dist s3-view-worker s2-rollback s1-commit s3-rollback -create_distributed_table - - -step s1-cache-connections: - SET citus.max_cached_conns_per_worker TO 4; - SET citus.force_max_query_parallelization TO on; - UPDATE test_table SET column2 = 0; - -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s3-begin: - BEGIN; - -step s1-alter-table: - ALTER TABLE test_table ADD COLUMN x INT; - -step s2-sleep: - SELECT pg_sleep(0.5); - -pg_sleep - - -step s2-view-dist: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - - - ALTER TABLE test_table ADD COLUMN x INT; -coordinator_host57636 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s3-view-worker: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_worker_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - -SELECT worker_apply_shard_ddl_command (1300004, 'public', ' - ALTER TABLE test_table ADD COLUMN x INT; -')localhost 57638 coordinator_host57636 idle in transactionClient ClientRead postgres regression -SELECT worker_apply_shard_ddl_command (1300003, 'public', ' - ALTER TABLE test_table ADD COLUMN x INT; -')localhost 57637 coordinator_host57636 idle in transactionClient ClientRead postgres regression -SELECT worker_apply_shard_ddl_command (1300002, 'public', ' - ALTER TABLE test_table ADD COLUMN x INT; -')localhost 57638 coordinator_host57636 idle in transactionClient ClientRead postgres regression -SELECT worker_apply_shard_ddl_command (1300001, 'public', ' - ALTER TABLE test_table ADD COLUMN x INT; -')localhost 57637 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s2-rollback: - ROLLBACK; - -step s1-commit: - COMMIT; - -step s3-rollback: - ROLLBACK; - - -starting permutation: s1-cache-connections s1-begin s2-begin s3-begin s1-insert s2-sleep s2-view-dist s3-view-worker s2-rollback s1-commit s3-rollback -create_distributed_table - - -step s1-cache-connections: - SET citus.max_cached_conns_per_worker TO 4; - SET citus.force_max_query_parallelization TO on; - UPDATE test_table SET column2 = 0; - -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s3-begin: - BEGIN; - -step s1-insert: - INSERT INTO test_table VALUES (100, 100); - -step s2-sleep: - SELECT pg_sleep(0.5); - -pg_sleep - - -step s2-view-dist: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - - - INSERT INTO test_table VALUES (100, 100); -coordinator_host57636 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s3-view-worker: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_worker_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - -INSERT INTO public.test_table_1300008 (column1, column2) VALUES (100, 100)localhost 57637 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s2-rollback: - ROLLBACK; - -step s1-commit: - COMMIT; - -step s3-rollback: - ROLLBACK; - - -starting permutation: s1-cache-connections s1-begin s2-begin s3-begin s1-select s2-sleep s2-view-dist s3-view-worker s2-rollback s1-commit s3-rollback -create_distributed_table - - -step s1-cache-connections: - SET citus.max_cached_conns_per_worker TO 4; - SET citus.force_max_query_parallelization TO on; - UPDATE test_table SET column2 = 0; - -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s3-begin: - BEGIN; - -step s1-select: - SELECT count(*) FROM test_table; - -count - -0 -step s2-sleep: - SELECT pg_sleep(0.5); - -pg_sleep - - -step s2-view-dist: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - - - SELECT count(*) FROM test_table; -coordinator_host57636 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s3-view-worker: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_worker_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - -COPY (SELECT count(*) AS count FROM test_table_1300014 test_table WHERE true) TO STDOUTlocalhost 57638 coordinator_host57636 idle in transactionClient ClientRead postgres regression -COPY (SELECT count(*) AS count FROM test_table_1300013 test_table WHERE true) TO STDOUTlocalhost 57637 coordinator_host57636 idle in transactionClient ClientRead postgres regression -COPY (SELECT count(*) AS count FROM test_table_1300012 test_table WHERE true) TO STDOUTlocalhost 57638 coordinator_host57636 idle in transactionClient ClientRead postgres regression -COPY (SELECT count(*) AS count FROM test_table_1300011 test_table WHERE true) TO STDOUTlocalhost 57637 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s2-rollback: - ROLLBACK; - -step s1-commit: - COMMIT; - -step s3-rollback: - ROLLBACK; - - -starting permutation: s1-cache-connections s1-begin s2-begin s3-begin s1-select-router s2-sleep s2-view-dist s3-view-worker s2-rollback s1-commit s3-rollback -create_distributed_table - - -step s1-cache-connections: - SET citus.max_cached_conns_per_worker TO 4; - SET citus.force_max_query_parallelization TO on; - UPDATE test_table SET column2 = 0; - -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s3-begin: - BEGIN; - -step s1-select-router: - SELECT count(*) FROM test_table WHERE column1 = 55; - -count - -0 -step s2-sleep: - SELECT pg_sleep(0.5); - -pg_sleep - - -step s2-view-dist: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - - - SELECT count(*) FROM test_table WHERE column1 = 55; -coordinator_host57636 coordinator_host57636 idle in transactionClient ClientRead postgres regression -step s3-view-worker: - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_worker_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - -query query_hostname query_hostport master_query_host_namemaster_query_host_portstate wait_event_typewait_event usename datname - -SELECT count(*) AS count FROM public.test_table_1300017 test_table WHERE (column1 OPERATOR(pg_catalog.=) 55)localhost 57638 0 idle Client ClientRead postgres regression -step s2-rollback: - ROLLBACK; - -step s1-commit: - COMMIT; - -step s3-rollback: - ROLLBACK; - diff --git a/src/test/regress/expected/isolation_dump_global_wait_edges_9.out b/src/test/regress/expected/isolation_dump_global_wait_edges_9.out deleted file mode 100644 index 8dfe80286..000000000 --- a/src/test/regress/expected/isolation_dump_global_wait_edges_9.out +++ /dev/null @@ -1,98 +0,0 @@ -Parsed test spec with 4 sessions - -starting permutation: s1-begin s2-begin s1-update s2-update detector-dump-wait-edges s1-abort s2-abort -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s1-update: - UPDATE distributed_table SET y = 1 WHERE x = 1; - -step s2-update: - UPDATE distributed_table SET y = 2 WHERE x = 1; - -step detector-dump-wait-edges: - SELECT - waiting_transaction_num, - blocking_transaction_num, - blocking_transaction_waiting - FROM - dump_global_wait_edges() - ORDER BY - waiting_transaction_num, - blocking_transaction_num, - blocking_transaction_waiting; - - SELECT * FROM get_adjacency_list_wait_graph() ORDER BY 1; - -waiting_transaction_numblocking_transaction_numblocking_transaction_waiting - -275 274 f -transactionnumberwaitingtransactionnumbers - -274 -275 274 -step s1-abort: - ABORT; - -step s2-update: <... completed> -step s2-abort: - ABORT; - - -starting permutation: s1-begin s2-begin s3-begin s1-update s2-update s3-update detector-dump-wait-edges s1-abort s2-abort s3-abort -step s1-begin: - BEGIN; - -step s2-begin: - BEGIN; - -step s3-begin: - BEGIN; - -step s1-update: - UPDATE distributed_table SET y = 1 WHERE x = 1; - -step s2-update: - UPDATE distributed_table SET y = 2 WHERE x = 1; - -step s3-update: - UPDATE distributed_table SET y = 3 WHERE x = 1; - -step detector-dump-wait-edges: - SELECT - waiting_transaction_num, - blocking_transaction_num, - blocking_transaction_waiting - FROM - dump_global_wait_edges() - ORDER BY - waiting_transaction_num, - blocking_transaction_num, - blocking_transaction_waiting; - - SELECT * FROM get_adjacency_list_wait_graph() ORDER BY 1; - -waiting_transaction_numblocking_transaction_numblocking_transaction_waiting - -279 278 f -280 278 f -280 279 t -transactionnumberwaitingtransactionnumbers - -278 -279 278 -280 278,279 -step s1-abort: - ABORT; - -step s2-update: <... completed> -step s2-abort: - ABORT; - -step s3-update: <... completed> -step s3-abort: - ABORT; - diff --git a/src/test/regress/expected/local_shard_execution.out b/src/test/regress/expected/local_shard_execution.out index e97c6dde5..172a4cc46 100644 --- a/src/test/regress/expected/local_shard_execution.out +++ b/src/test/regress/expected/local_shard_execution.out @@ -959,68 +959,6 @@ LOG: executing the command locally: DELETE FROM local_shard_execution.reference DELETE FROM reference_table; LOG: executing the command locally: DELETE FROM local_shard_execution.reference_table_1470000 reference_table ROLLBACK; --- mix with other executors should fail --- router modify execution should error -BEGIN; - DELETE FROM distributed_table WHERE key = 500; -LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (key OPERATOR(pg_catalog.=) 500) - SET LOCAL citus.task_executor_type = 'real-time'; - DELETE FROM distributed_table; -ERROR: cannot execute command because a local execution has already been done in the transaction -DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally -HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;" -ROLLBACK; --- local execution should not be executed locally --- becase a multi-shard router query has already been executed -BEGIN; - SET LOCAL citus.task_executor_type = 'real-time'; - DELETE FROM distributed_table; - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; --- router select execution -BEGIN; - DELETE FROM distributed_table WHERE key = 500; -LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (key OPERATOR(pg_catalog.=) 500) - SET LOCAL citus.task_executor_type = 'real-time'; - SELECT count(*) FROM distributed_table WHERE key = 500; -ERROR: cannot execute command because a local execution has already been done in the transaction -DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally -HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;" -ROLLBACK; --- local execution should not be executed locally --- becase a single-shard router query has already been executed -BEGIN; - SET LOCAL citus.task_executor_type = 'real-time'; - SELECT count(*) FROM distributed_table WHERE key = 500; - count -------- - 1 -(1 row) - - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; --- real-time select execution -BEGIN; - DELETE FROM distributed_table WHERE key = 500; -LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (key OPERATOR(pg_catalog.=) 500) - SET LOCAL citus.task_executor_type = 'real-time'; - SELECT count(*) FROM distributed_table; -ERROR: cannot execute command because a local execution has already been done in the transaction -DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally -HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;" -ROLLBACK; --- local execution should not be executed locally --- becase a real-time query has already been executed -BEGIN; - SET LOCAL citus.task_executor_type = 'real-time'; - SELECT count(*) FROM distributed_table; - count -------- - 101 -(1 row) - - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; -- task-tracker select execution BEGIN; DELETE FROM distributed_table WHERE key = 500; diff --git a/src/test/regress/expected/multi_insert_select.out b/src/test/regress/expected/multi_insert_select.out index 39b031c3b..f836dc664 100644 --- a/src/test/regress/expected/multi_insert_select.out +++ b/src/test/regress/expected/multi_insert_select.out @@ -143,7 +143,6 @@ FROM raw_events_first WHERE user_id = 0; -WARNING: function public.evaluate_on_master(integer) does not exist ERROR: function public.evaluate_on_master(integer) does not exist -- add one more row INSERT INTO raw_events_first (user_id, time) VALUES @@ -1748,7 +1747,6 @@ BEGIN; ALTER TABLE reference_table ADD COLUMN z int; INSERT INTO raw_events_first (user_id) SELECT user_id FROM raw_events_second JOIN reference_table USING (user_id); -ERROR: cannot establish a new connection for placement 13300025, since DDL has been executed on a connection that is in use ROLLBACK; -- the same test with sequential DDL should work fine BEGIN; diff --git a/src/test/regress/expected/multi_insert_select_9.out b/src/test/regress/expected/multi_insert_select_9.out deleted file mode 100644 index f836dc664..000000000 --- a/src/test/regress/expected/multi_insert_select_9.out +++ /dev/null @@ -1,2820 +0,0 @@ --- --- MULTI_INSERT_SELECT --- -SET citus.next_shard_id TO 13300000; -SET citus.next_placement_id TO 13300000; --- create co-located tables -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 2; --- order of execution might change in parallel executions --- and the error details might contain the worker node --- so be less verbose with \set VERBOSITY TERSE when necessary -CREATE TABLE raw_events_first (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1)); -SELECT create_distributed_table('raw_events_first', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE raw_events_second (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1)); -SELECT create_distributed_table('raw_events_second', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE agg_events (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp, UNIQUE(user_id, value_1_agg)); -SELECT create_distributed_table('agg_events', 'user_id');; - create_distributed_table --------------------------- - -(1 row) - --- create the reference table as well -CREATE TABLE reference_table (user_id int); -SELECT create_reference_table('reference_table'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE insert_select_varchar_test (key varchar, value int); -SELECT create_distributed_table('insert_select_varchar_test', 'key', 'hash'); - create_distributed_table --------------------------- - -(1 row) - --- set back to the defaults -SET citus.shard_count = DEFAULT; -SET citus.shard_replication_factor = DEFAULT; -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (1, now(), 10, 100, 1000.1, 10000); -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (2, now(), 20, 200, 2000.1, 20000); -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (3, now(), 30, 300, 3000.1, 30000); -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (4, now(), 40, 400, 4000.1, 40000); -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (5, now(), 50, 500, 5000.1, 50000); -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (6, now(), 60, 600, 6000.1, 60000); -SET client_min_messages TO DEBUG2; --- raw table to raw table -INSERT INTO raw_events_second SELECT * FROM raw_events_first; -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- see that our first multi shard INSERT...SELECT works expected -SET client_min_messages TO INFO; -SELECT - raw_events_first.user_id -FROM - raw_events_first, raw_events_second -WHERE - raw_events_first.user_id = raw_events_second.user_id -ORDER BY - user_id DESC; - user_id ---------- - 6 - 5 - 4 - 3 - 2 - 1 -(6 rows) - --- see that we get unique vialitons -\set VERBOSITY TERSE -INSERT INTO raw_events_second SELECT * FROM raw_events_first; -ERROR: duplicate key value violates unique constraint "raw_events_second_user_id_value_1_key_13300004" -\set VERBOSITY DEFAULT --- stable functions should be allowed -INSERT INTO raw_events_second (user_id, time) -SELECT - user_id, now() -FROM - raw_events_first -WHERE - user_id < 0; -INSERT INTO raw_events_second (user_id) -SELECT - user_id -FROM - raw_events_first -WHERE - time > now() + interval '1 day'; --- hide version-dependent PL/pgSQL context messages -\set VERBOSITY terse --- make sure we evaluate stable functions on the master, once -CREATE OR REPLACE FUNCTION evaluate_on_master() -RETURNS int LANGUAGE plpgsql STABLE -AS $function$ -BEGIN - RAISE NOTICE 'evaluating on master'; - RETURN 0; -END; -$function$; -INSERT INTO raw_events_second (user_id, value_1) -SELECT - user_id, evaluate_on_master() -FROM - raw_events_first -WHERE - user_id < 0; -NOTICE: evaluating on master --- make sure we don't evaluate stable functions with column arguments -CREATE OR REPLACE FUNCTION evaluate_on_master(x int) -RETURNS int LANGUAGE plpgsql STABLE -AS $function$ -BEGIN - RAISE NOTICE 'evaluating on master'; - RETURN x; -END; -$function$; -INSERT INTO raw_events_second (user_id, value_1) -SELECT - user_id, evaluate_on_master(value_1) -FROM - raw_events_first -WHERE - user_id = 0; -ERROR: function public.evaluate_on_master(integer) does not exist --- add one more row -INSERT INTO raw_events_first (user_id, time) VALUES - (7, now()); --- try a single shard query -SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (user_id, time) SELECT user_id, time FROM raw_events_first WHERE user_id = 7; -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, "time") SELECT user_id, "time" FROM public.raw_events_first_13300001 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) 7) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable -SET client_min_messages TO INFO; --- add one more row -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (8, now(), 80, 800, 8000, 80000); --- reorder columns -SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM - raw_events_first -WHERE - user_id = 8; -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_first_13300000 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) 8) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable --- a zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM - raw_events_first -WHERE - false; -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable --- another zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM - raw_events_first -WHERE - 0 != 0; -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable --- add one more row -SET client_min_messages TO INFO; -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (9, now(), 90, 900, 9000, 90000); --- show that RETURNING also works -SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT - user_id, value_1, value_3 -FROM - raw_events_first -WHERE - value_3 = 9000 -RETURNING *; -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300000 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300001 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300002 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300003 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: Plan is router executable - user_id | time | value_1 | value_2 | value_3 | value_4 ----------+------+---------+---------+---------+--------- - 9 | | 90 | | 9000 | -(1 row) - --- hits two shards -\set VERBOSITY TERSE -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT - user_id, value_1, value_3 -FROM - raw_events_first -WHERE - user_id = 9 OR user_id = 16 -RETURNING *; -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300001 raw_events_first WHERE (((user_id OPERATOR(pg_catalog.=) 9) OR (user_id OPERATOR(pg_catalog.=) 16)) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300003 raw_events_first WHERE (((user_id OPERATOR(pg_catalog.=) 9) OR (user_id OPERATOR(pg_catalog.=) 16)) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: Plan is router executable -ERROR: duplicate key value violates unique constraint "raw_events_second_user_id_value_1_key_13300007" --- now do some aggregations -INSERT INTO agg_events -SELECT - user_id, sum(value_1), avg(value_2), sum(value_3), count(value_4) -FROM - raw_events_first -GROUP BY - user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg, value_2_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, avg(value_2) AS avg, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg, value_2_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, avg(value_2) AS avg, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg, value_2_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, avg(value_2) AS avg, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg, value_2_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, avg(value_2) AS avg, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY user_id -DEBUG: Plan is router executable --- group by column not exists on the SELECT target list -INSERT INTO agg_events (value_3_agg, value_4_agg, value_1_agg, user_id) -SELECT - sum(value_3), count(value_4), sum(value_1), user_id -FROM - raw_events_first -GROUP BY - value_2, user_id -RETURNING *; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY value_2, user_id RETURNING citus_table_alias.user_id, citus_table_alias.value_1_agg, citus_table_alias.value_2_agg, citus_table_alias.value_3_agg, citus_table_alias.value_4_agg, citus_table_alias.agg_time -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY value_2, user_id RETURNING citus_table_alias.user_id, citus_table_alias.value_1_agg, citus_table_alias.value_2_agg, citus_table_alias.value_3_agg, citus_table_alias.value_4_agg, citus_table_alias.agg_time -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY value_2, user_id RETURNING citus_table_alias.user_id, citus_table_alias.value_1_agg, citus_table_alias.value_2_agg, citus_table_alias.value_3_agg, citus_table_alias.value_4_agg, citus_table_alias.agg_time -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY value_2, user_id RETURNING citus_table_alias.user_id, citus_table_alias.value_1_agg, citus_table_alias.value_2_agg, citus_table_alias.value_3_agg, citus_table_alias.value_4_agg, citus_table_alias.agg_time -DEBUG: Plan is router executable -ERROR: duplicate key value violates unique constraint "agg_events_user_id_value_1_agg_key_13300008" --- some subquery tests -INSERT INTO agg_events - (value_1_agg, - user_id) -SELECT SUM(value_1), - id -FROM (SELECT raw_events_second.user_id AS id, - raw_events_second.value_1 - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id) AS foo -GROUP BY id -ORDER BY id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY id ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY id ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY id ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY id ORDER BY id -DEBUG: Plan is router executable -ERROR: duplicate key value violates unique constraint "agg_events_user_id_value_1_agg_key_13300008" --- subquery one more level depth -INSERT INTO agg_events - (value_4_agg, - value_1_agg, - user_id) -SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id) AS foo -ORDER BY id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg, value_4_agg) SELECT id, v1, v4 FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg, value_4_agg) SELECT id, v1, v4 FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1'::integer)) ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg, value_4_agg) SELECT id, v1, v4 FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 1073741823)) ORDER BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg, value_4_agg) SELECT id, v1, v4 FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 2147483647)) ORDER BY id -DEBUG: Plan is router executable -ERROR: duplicate key value violates unique constraint "agg_events_user_id_value_1_agg_key_13300008" -\set VERBOSITY DEFAULT --- join between subqueries -INSERT INTO agg_events - (user_id) -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id); -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- add one more level subqueris on top of subquery JOINs -INSERT INTO agg_events - (user_id, value_4_agg) -SELECT - outer_most.id, max(outer_most.value) -FROM -( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id)) as outer_most -GROUP BY - outer_most.id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY id -DEBUG: Plan is router executable --- subqueries in WHERE clause -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT user_id - FROM raw_events_second - WHERE user_id = 2); -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) 2))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT user_id - FROM raw_events_second - WHERE user_id != 2 AND value_1 = 2000) -ON conflict (user_id, value_1) DO NOTHING; -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300004 raw_events_second WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.<>) 2) AND (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) ON CONFLICT(user_id, value_1) DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300001 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300005 raw_events_second WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.<>) 2) AND (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) ON CONFLICT(user_id, value_1) DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300006 raw_events_second WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.<>) 2) AND (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) ON CONFLICT(user_id, value_1) DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.<>) 2) AND (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) ON CONFLICT(user_id, value_1) DO NOTHING -DEBUG: Plan is router executable -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT user_id - FROM raw_events_second WHERE false); -DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT user_id - FROM raw_events_second - WHERE value_1 = 1000 OR value_1 = 2000 OR value_1 = 3000); -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300004 raw_events_second WHERE ((raw_events_second.value_1 OPERATOR(pg_catalog.=) 1000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 3000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300001 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300005 raw_events_second WHERE ((raw_events_second.value_1 OPERATOR(pg_catalog.=) 1000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 3000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300006 raw_events_second WHERE ((raw_events_second.value_1 OPERATOR(pg_catalog.=) 1000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 3000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second WHERE ((raw_events_second.value_1 OPERATOR(pg_catalog.=) 1000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 2000) OR (raw_events_second.value_1 OPERATOR(pg_catalog.=) 3000)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable --- lets mix subqueries in FROM clause and subqueries in WHERE -INSERT INTO agg_events - (user_id) -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 1000) AS foo2 ) as f2 -ON (f.id = f2.id) -WHERE f.id IN (SELECT user_id - FROM raw_events_second); -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (1000)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300004 raw_events_second)) AND ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (1000)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300005 raw_events_second)) AND ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (1000)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300006 raw_events_second)) AND ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (1000)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second)) AND ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable --- some UPSERTS -INSERT INTO agg_events AS ae - ( - user_id, - value_1_agg, - agg_time - ) -SELECT user_id, - value_1, - time -FROM raw_events_first -ON conflict (user_id, value_1_agg) -DO UPDATE - SET agg_time = EXCLUDED.agg_time - WHERE ae.agg_time < EXCLUDED.agg_time; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) -DEBUG: Plan is router executable --- upserts with returning -INSERT INTO agg_events AS ae - ( - user_id, - value_1_agg, - agg_time - ) -SELECT user_id, - value_1, - time -FROM raw_events_first -ON conflict (user_id, value_1_agg) -DO UPDATE - SET agg_time = EXCLUDED.agg_time - WHERE ae.agg_time < EXCLUDED.agg_time -RETURNING user_id, value_1_agg; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) RETURNING ae.user_id, ae.value_1_agg -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) RETURNING ae.user_id, ae.value_1_agg -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) RETURNING ae.user_id, ae.value_1_agg -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) RETURNING ae.user_id, ae.value_1_agg -DEBUG: Plan is router executable - user_id | value_1_agg ----------+------------- - 7 | -(1 row) - -INSERT INTO agg_events (user_id, value_1_agg) -SELECT - user_id, sum(value_1 + value_2) -FROM - raw_events_first GROUP BY user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) AS sum FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) AS sum FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) AS sum FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) AS sum FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY user_id -DEBUG: Plan is router executable --- FILTER CLAUSE -INSERT INTO agg_events (user_id, value_1_agg) -SELECT - user_id, sum(value_1 + value_2) FILTER (where value_3 = 15) -FROM - raw_events_first GROUP BY user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) FILTER (WHERE (value_3 OPERATOR(pg_catalog.=) (15)::double precision)) AS sum FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) FILTER (WHERE (value_3 OPERATOR(pg_catalog.=) (15)::double precision)) AS sum FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) FILTER (WHERE (value_3 OPERATOR(pg_catalog.=) (15)::double precision)) AS sum FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT user_id, sum((value_1 OPERATOR(pg_catalog.+) value_2)) FILTER (WHERE (value_3 OPERATOR(pg_catalog.=) (15)::double precision)) AS sum FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY user_id -DEBUG: Plan is router executable --- a test with reference table JOINs -INSERT INTO - agg_events (user_id, value_1_agg) -SELECT - raw_events_first.user_id, sum(value_1) -FROM - reference_table, raw_events_first -WHERE - raw_events_first.user_id = reference_table.user_id -GROUP BY - raw_events_first.user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT raw_events_first.user_id, sum(raw_events_first.value_1) AS sum FROM public.reference_table_13300012 reference_table, public.raw_events_first_13300000 raw_events_first WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) GROUP BY raw_events_first.user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT raw_events_first.user_id, sum(raw_events_first.value_1) AS sum FROM public.reference_table_13300012 reference_table, public.raw_events_first_13300001 raw_events_first WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) GROUP BY raw_events_first.user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT raw_events_first.user_id, sum(raw_events_first.value_1) AS sum FROM public.reference_table_13300012 reference_table, public.raw_events_first_13300002 raw_events_first WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) GROUP BY raw_events_first.user_id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT raw_events_first.user_id, sum(raw_events_first.value_1) AS sum FROM public.reference_table_13300012 reference_table, public.raw_events_first_13300003 raw_events_first WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) GROUP BY raw_events_first.user_id -DEBUG: Plan is router executable --- a note on the outer joins is that --- we filter out outer join results --- where partition column returns --- NULL. Thus, we could INSERT less rows --- than we expect from subquery result. --- see the following tests -SET client_min_messages TO INFO; --- we don't want to see constraint violations, so truncate first -TRUNCATE agg_events; --- add a row to first table to make table contents different -INSERT INTO raw_events_second (user_id, time, value_1, value_2, value_3, value_4) VALUES - (10, now(), 100, 10000, 10000, 100000); -DELETE FROM raw_events_second WHERE user_id = 2; --- we select 11 rows -SELECT t1.user_id AS col1, - t2.user_id AS col2 - FROM raw_events_first t1 - FULL JOIN raw_events_second t2 - ON t1.user_id = t2.user_id - ORDER BY t1.user_id, - t2.user_id; - col1 | col2 -------+------ - 1 | 1 - 2 | - 3 | 3 - 4 | 4 - 5 | 5 - 6 | 6 - 7 | 7 - 8 | 8 - 9 | 9 - | 10 -(10 rows) - -SET client_min_messages TO DEBUG2; --- we insert 10 rows since we filtered out --- NULL partition column values -INSERT INTO agg_events (user_id, value_1_agg) -SELECT t1.user_id AS col1, - t2.user_id AS col2 -FROM raw_events_first t1 - FULL JOIN raw_events_second t2 - ON t1.user_id = t2.user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT t1.user_id AS col1, t2.user_id AS col2 FROM (public.raw_events_first_13300000 t1 FULL JOIN public.raw_events_second_13300004 t2 ON ((t1.user_id OPERATOR(pg_catalog.=) t2.user_id))) WHERE ((worker_hash(t1.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(t1.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT t1.user_id AS col1, t2.user_id AS col2 FROM (public.raw_events_first_13300001 t1 FULL JOIN public.raw_events_second_13300005 t2 ON ((t1.user_id OPERATOR(pg_catalog.=) t2.user_id))) WHERE ((worker_hash(t1.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(t1.user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT t1.user_id AS col1, t2.user_id AS col2 FROM (public.raw_events_first_13300002 t1 FULL JOIN public.raw_events_second_13300006 t2 ON ((t1.user_id OPERATOR(pg_catalog.=) t2.user_id))) WHERE ((worker_hash(t1.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(t1.user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT t1.user_id AS col1, t2.user_id AS col2 FROM (public.raw_events_first_13300003 t1 FULL JOIN public.raw_events_second_13300007 t2 ON ((t1.user_id OPERATOR(pg_catalog.=) t2.user_id))) WHERE ((worker_hash(t1.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(t1.user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable -SET client_min_messages TO INFO; --- see that the results are different from the SELECT query -SELECT - user_id, value_1_agg -FROM - agg_events -ORDER BY - user_id, value_1_agg; - user_id | value_1_agg ----------+------------- - 1 | 1 - 2 | - 3 | 3 - 4 | 4 - 5 | 5 - 6 | 6 - 7 | 7 - 8 | 8 - 9 | 9 -(9 rows) - --- we don't want to see constraint violations, so truncate first -SET client_min_messages TO INFO; -TRUNCATE agg_events; -SET client_min_messages TO DEBUG2; --- DISTINCT clause -INSERT INTO agg_events (value_1_agg, user_id) - SELECT - DISTINCT value_1, user_id - FROM - raw_events_first; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT user_id, value_1 FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT user_id, value_1 FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT user_id, value_1 FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT user_id, value_1 FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- we don't want to see constraint violations, so truncate first -SET client_min_messages TO INFO; -truncate agg_events; -SET client_min_messages TO DEBUG2; --- DISTINCT ON clauses are supported --- distinct on(non-partition column) --- values are pulled to master -INSERT INTO agg_events (value_1_agg, user_id) - SELECT - DISTINCT ON (value_1) value_1, user_id - FROM - raw_events_first; -DEBUG: DISTINCT ON (non-partition column) clauses are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -SELECT user_id, value_1_agg FROM agg_events ORDER BY 1,2; -DEBUG: Router planner cannot handle multi-shard select queries - user_id | value_1_agg ----------+------------- - 1 | 10 - 2 | 20 - 3 | 30 - 4 | 40 - 5 | 50 - 6 | 60 - 7 | - 8 | 80 - 9 | 90 -(9 rows) - --- we don't want to see constraint violations, so truncate first -SET client_min_messages TO INFO; -truncate agg_events; -SET client_min_messages TO DEBUG2; --- distinct on(partition column) --- queries are forwared to workers -INSERT INTO agg_events (value_1_agg, user_id) - SELECT - DISTINCT ON (user_id) value_1, user_id - FROM - raw_events_first; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT ON (user_id) user_id, value_1 FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT ON (user_id) user_id, value_1 FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT ON (user_id) user_id, value_1 FROM public.raw_events_first_13300002 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT DISTINCT ON (user_id) user_id, value_1 FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable -SELECT user_id, value_1_agg FROM agg_events ORDER BY 1,2; -DEBUG: Router planner cannot handle multi-shard select queries - user_id | value_1_agg ----------+------------- - 1 | 10 - 2 | 20 - 3 | 30 - 4 | 40 - 5 | 50 - 6 | 60 - 7 | - 8 | 80 - 9 | 90 -(9 rows) - --- We support CTEs -BEGIN; -WITH fist_table_agg AS - (SELECT max(value_1)+1 as v1_agg, user_id FROM raw_events_first GROUP BY user_id) -INSERT INTO agg_events - (value_1_agg, user_id) - SELECT - v1_agg, user_id - FROM - fist_table_agg; -DEBUG: distributed INSERT ... SELECT can only select from distributed tables -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: generating subplan 51_1 for CTE fist_table_agg: SELECT (max(value_1) OPERATOR(pg_catalog.+) 1) AS v1_agg, user_id FROM public.raw_events_first GROUP BY user_id -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: Plan 51 query after replacing subqueries and CTEs: SELECT user_id, v1_agg FROM (SELECT fist_table_agg.v1_agg, fist_table_agg.user_id FROM (SELECT intermediate_result.v1_agg, intermediate_result.user_id FROM read_intermediate_result('51_1'::text, 'binary'::citus_copy_format) intermediate_result(v1_agg integer, user_id integer)) fist_table_agg) citus_insert_select_subquery -DEBUG: Creating router plan -DEBUG: Plan is router executable -ROLLBACK; --- We don't support CTEs that are referenced in the target list -INSERT INTO agg_events - WITH sub_cte AS (SELECT 1) - SELECT - raw_events_first.user_id, (SELECT * FROM sub_cte) - FROM - raw_events_first; -DEBUG: Subqueries without relations are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: generating subplan 54_1 for CTE sub_cte: SELECT 1 -DEBUG: Plan 54 query after replacing subqueries and CTEs: SELECT user_id, (SELECT sub_cte."?column?" FROM (SELECT intermediate_result."?column?" FROM read_intermediate_result('54_1'::text, 'binary'::citus_copy_format) intermediate_result("?column?" integer)) sub_cte) FROM public.raw_events_first -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: could not run distributed query with subquery outside the FROM, WHERE and HAVING clauses -HINT: Consider using an equality filter on the distributed table's partition column. --- We support set operations via the coordinator -BEGIN; -INSERT INTO - raw_events_first(user_id) -SELECT - user_id -FROM - ((SELECT user_id FROM raw_events_first) UNION - (SELECT user_id FROM raw_events_second)) as foo; -DEBUG: Set operations are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ROLLBACK; --- We do support set operations through recursive planning -BEGIN; -SET LOCAL client_min_messages TO DEBUG; -INSERT INTO - raw_events_first(user_id) - (SELECT user_id FROM raw_events_first) INTERSECT - (SELECT user_id FROM raw_events_first); -DEBUG: Set operations are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: generating subplan 58_1 for subquery SELECT user_id FROM public.raw_events_first -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: generating subplan 58_2 for subquery SELECT user_id FROM public.raw_events_first -DEBUG: Creating router plan -DEBUG: Plan is router executable -DEBUG: generating subplan 58_3 for subquery SELECT intermediate_result.user_id FROM read_intermediate_result('58_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer) INTERSECT SELECT intermediate_result.user_id FROM read_intermediate_result('58_2'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer) -DEBUG: Plan 58 query after replacing subqueries and CTEs: SELECT user_id FROM (SELECT intermediate_result.user_id FROM read_intermediate_result('58_3'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) citus_insert_select_subquery -DEBUG: Creating router plan -DEBUG: Plan is router executable -ROLLBACK; --- If the query is router plannable then it is executed via the coordinator -INSERT INTO - raw_events_first(user_id) -SELECT - user_id -FROM - ((SELECT user_id FROM raw_events_first WHERE user_id = 15) EXCEPT - (SELECT user_id FROM raw_events_second where user_id = 17)) as foo; -DEBUG: Set operations are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Creating router plan -DEBUG: Plan is router executable --- some supported LEFT joins - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300000 raw_events_first LEFT JOIN public.raw_events_second_13300004 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300001 raw_events_first LEFT JOIN public.raw_events_second_13300005 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_second.user_id - FROM - reference_table LEFT JOIN raw_events_second ON reference_table.user_id = raw_events_second.user_id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300004 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300005 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_first.user_id = 10; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300000 raw_events_first LEFT JOIN public.raw_events_second_13300004 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) 10) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_second.user_id = 10 OR raw_events_second.user_id = 11; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300000 raw_events_first LEFT JOIN public.raw_events_second_13300004 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300001 raw_events_first LEFT JOIN (SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_second(user_id, "time", value_1, value_2, value_3, value_4) ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN (SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_second(user_id, "time", value_1, value_2, value_3, value_4) ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_first.user_id = 10 AND raw_events_first.user_id = 20; -DEBUG: Skipping target shard interval 13300008 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_first.user_id = 10 AND raw_events_second.user_id = 20; -DEBUG: Skipping target shard interval 13300008 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_first.user_id IN (19, 20, 21); -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300000 raw_events_first LEFT JOIN public.raw_events_second_13300004 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300001 raw_events_first LEFT JOIN public.raw_events_second_13300005 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM ((SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_first(user_id, "time", value_1, value_2, value_3, value_4) LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable - - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id - WHERE raw_events_second.user_id IN (19, 20, 21); -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300000 raw_events_first JOIN public.raw_events_second_13300004 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300001 raw_events_first JOIN public.raw_events_second_13300005 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first JOIN (SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_second(user_id, "time", value_1, value_2, value_3, value_4) ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable - - -- the following is a very tricky query for Citus - -- although we do not support pushing down JOINs on non-partition - -- columns here it is safe to push it down given that we're looking for - -- a specific value (i.e., value_1 = 12) on the joining column. - -- Note that the query always hits the same shard on raw_events_second - -- and this query wouldn't have worked if we're to use different worker - -- count or shard replication factor - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 - AND raw_events_first.value_1 = 12; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- some unsupported LEFT/INNER JOINs - -- JOIN on one table with partition column other is not - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- same as the above with INNER JOIN - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- a not meaningful query - INSERT INTO agg_events - (user_id) - SELECT raw_events_second.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_first.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- both tables joined on non-partition columns - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- same as the above with INNER JOIN - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - --- even if there is a filter on the partition key, since the join is not on the partition key we reject --- this query -INSERT INTO agg_events (user_id) -SELECT - raw_events_first.user_id -FROM - raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 -WHERE - raw_events_first.user_id = 10; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- same as the above with INNER JOIN - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 - WHERE raw_events_first.user_id = 10; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- make things a bit more complicate with IN clauses - INSERT INTO agg_events (user_id) - SELECT - raw_events_first.user_id - FROM - raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 - WHERE raw_events_first.value_1 IN (10, 11,12) OR raw_events_second.user_id IN (1,2,3,4); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- implicit join on non partition column should also not be pushed down - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- the following is again a tricky query for Citus - -- if the given filter was on value_1 as shown in the above, Citus could - -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 - AND raw_events_first.value_2 = 12; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - - -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not - -- pushed down - INSERT INTO agg_events - (user_id, value_4_agg) - SELECT - outer_most.id, max(outer_most.value) - FROM - ( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first LEFT JOIN - reference_table - ON (raw_events_first.value_1 = reference_table.user_id)) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 - ON (f.id = f2.id)) as outer_most - GROUP BY - outer_most.id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - -- if the given filter was on value_1 as shown in the above, Citus could - -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 - AND raw_events_first.value_2 = 12; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. - -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not - -- pushed down - INSERT INTO agg_events - (user_id, value_4_agg) - SELECT - outer_most.id, max(outer_most.value) - FROM - ( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first LEFT JOIN - reference_table - ON (raw_events_first.value_1 = reference_table.user_id)) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 - ON (f.id = f2.id)) as outer_most - GROUP BY - outer_most.id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. -INSERT INTO agg_events - (value_4_agg, - value_1_agg, - user_id) -SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id != raw_events_second.user_id - GROUP BY raw_events_second.user_id) AS foo; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- INSERT returns NULL partition key value via coordinator -INSERT INTO agg_events - (value_4_agg, - value_1_agg, - user_id) -SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.value_3 AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.value_3) AS foo; -DEBUG: Group by list without distribution column is not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [-1073741824,-1] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [0,1073741823] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [1073741824,2147483647] -DEBUG: join prunable for intervals [-1073741824,-1] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [-1073741824,-1] and [0,1073741823] -DEBUG: join prunable for intervals [-1073741824,-1] and [1073741824,2147483647] -DEBUG: join prunable for intervals [0,1073741823] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [0,1073741823] and [-1073741824,-1] -DEBUG: join prunable for intervals [0,1073741823] and [1073741824,2147483647] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-1073741824,-1] -DEBUG: join prunable for intervals [1073741824,2147483647] and [0,1073741823] -DEBUG: generating subplan 88_1 for subquery SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.value_3 AS id FROM public.raw_events_first, public.raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.value_3 -DEBUG: Plan 88 query after replacing subqueries and CTEs: SELECT id, v1, v4 FROM (SELECT intermediate_result.v4, intermediate_result.v1, intermediate_result.id FROM read_intermediate_result('88_1'::text, 'binary'::citus_copy_format) intermediate_result(v4 numeric, v1 bigint, id double precision)) foo -DEBUG: Creating router plan -DEBUG: Plan is router executable -ERROR: the partition column of table public.agg_events cannot be NULL --- error cases --- no part column at all -INSERT INTO raw_events_second - (value_1) -SELECT value_1 -FROM raw_events_first; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: the query doesn't include the target table's partition column -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: the partition column of table public.raw_events_second should have a value -INSERT INTO raw_events_second - (value_1) -SELECT user_id -FROM raw_events_first; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: the query doesn't include the target table's partition column -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: the partition column of table public.raw_events_second should have a value -INSERT INTO raw_events_second - (user_id) -SELECT value_1 -FROM raw_events_first; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: The target table's partition column should correspond to a partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: the partition column of table public.raw_events_second cannot be NULL -INSERT INTO raw_events_second - (user_id) -SELECT user_id * 2 -FROM raw_events_first; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an operator in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO raw_events_second - (user_id) -SELECT user_id :: bigint -FROM raw_events_first; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an explicit cast in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO agg_events - (value_3_agg, - value_4_agg, - value_1_agg, - value_2_agg, - user_id) -SELECT SUM(value_3), - Count(value_4), - user_id, - SUM(value_1), - Avg(value_2) -FROM raw_events_first -GROUP BY user_id; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an aggregation in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: the partition column of table public.agg_events cannot be NULL -INSERT INTO agg_events - (value_3_agg, - value_4_agg, - value_1_agg, - value_2_agg, - user_id) -SELECT SUM(value_3), - Count(value_4), - user_id, - SUM(value_1), - value_2 -FROM raw_events_first -GROUP BY user_id, - value_2; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: The target table's partition column should correspond to a partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: the partition column of table public.agg_events cannot be NULL --- tables should be co-located -INSERT INTO agg_events (user_id) -SELECT - user_id -FROM - reference_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: The target table's partition column should correspond to a partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Distributed planning for a fast-path router query -DEBUG: Creating router plan -DEBUG: Plan is router executable --- foo2 is recursively planned and INSERT...SELECT is done via coordinator -INSERT INTO agg_events - (user_id) -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - raw_events_second.value_1 AS v1, - SUM(raw_events_second.user_id) AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.value_1 - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id); -DEBUG: Group by list without distribution column is not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [-1073741824,-1] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [0,1073741823] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [1073741824,2147483647] -DEBUG: join prunable for intervals [-1073741824,-1] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [-1073741824,-1] and [0,1073741823] -DEBUG: join prunable for intervals [-1073741824,-1] and [1073741824,2147483647] -DEBUG: join prunable for intervals [0,1073741823] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [0,1073741823] and [-1073741824,-1] -DEBUG: join prunable for intervals [0,1073741823] and [1073741824,2147483647] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-1073741824,-1] -DEBUG: join prunable for intervals [1073741824,2147483647] and [0,1073741823] -DEBUG: generating subplan 107_1 for subquery SELECT sum(raw_events_second.value_4) AS v4, raw_events_second.value_1 AS v1, sum(raw_events_second.user_id) AS id FROM public.raw_events_first, public.raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.value_1 HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric) -DEBUG: Plan 107 query after replacing subqueries and CTEs: SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first, public.reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT intermediate_result.v4, intermediate_result.v1, intermediate_result.id FROM read_intermediate_result('107_1'::text, 'binary'::citus_copy_format) intermediate_result(v4 numeric, v1 integer, id bigint)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) -DEBUG: Router planner cannot handle multi-shard select queries --- the second part of the query is not routable since --- GROUP BY not on the partition column (i.e., value_1) and thus join --- on f.id = f2.id is not on the partition key (instead on the sum of partition key) --- but we still recursively plan foo2 and run the query -INSERT INTO agg_events - (user_id) -SELECT f.id FROM -(SELECT - id -FROM (SELECT raw_events_first.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - raw_events_second.value_1 AS v1, - SUM(raw_events_second.user_id) AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.value_1 - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id); -DEBUG: Group by list without distribution column is not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: Router planner cannot handle multi-shard select queries -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [-1073741824,-1] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [0,1073741823] -DEBUG: join prunable for intervals [-2147483648,-1073741825] and [1073741824,2147483647] -DEBUG: join prunable for intervals [-1073741824,-1] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [-1073741824,-1] and [0,1073741823] -DEBUG: join prunable for intervals [-1073741824,-1] and [1073741824,2147483647] -DEBUG: join prunable for intervals [0,1073741823] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [0,1073741823] and [-1073741824,-1] -DEBUG: join prunable for intervals [0,1073741823] and [1073741824,2147483647] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-2147483648,-1073741825] -DEBUG: join prunable for intervals [1073741824,2147483647] and [-1073741824,-1] -DEBUG: join prunable for intervals [1073741824,2147483647] and [0,1073741823] -DEBUG: generating subplan 110_1 for subquery SELECT sum(raw_events_second.value_4) AS v4, raw_events_second.value_1 AS v1, sum(raw_events_second.user_id) AS id FROM public.raw_events_first, public.raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.value_1 HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric) -DEBUG: Plan 110 query after replacing subqueries and CTEs: SELECT f.id FROM ((SELECT foo.id FROM (SELECT raw_events_first.user_id AS id FROM public.raw_events_first, public.reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT intermediate_result.v4, intermediate_result.v1, intermediate_result.id FROM read_intermediate_result('110_1'::text, 'binary'::citus_copy_format) intermediate_result(v4 numeric, v1 integer, id bigint)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) -DEBUG: Router planner cannot handle multi-shard select queries --- cannot pushdown the query since the JOIN is not equi JOIN -INSERT INTO agg_events - (user_id, value_4_agg) -SELECT -outer_most.id, max(outer_most.value) - FROM -( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id != f2.id)) as outer_most -GROUP BY outer_most.id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- cannot pushdown since foo2 is not join on partition key -INSERT INTO agg_events - (user_id, value_4_agg) -SELECT - outer_most.id, max(outer_most.value) -FROM -( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.value_1 - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id)) as outer_most -GROUP BY - outer_most.id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- cannot push down since foo doesn't have en equi join -INSERT INTO agg_events - (user_id, value_4_agg) -SELECT - outer_most.id, max(outer_most.value) -FROM -( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id != reference_table.user_id ) AS foo) as f - INNER JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id)) as outer_most -GROUP BY - outer_most.id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- some unsupported LATERAL JOINs --- join on averages is not on the partition key -INSERT INTO agg_events (user_id, value_4_agg) -SELECT - averages.user_id, avg(averages.value_4) -FROM - (SELECT - raw_events_second.user_id - FROM - reference_table JOIN raw_events_second on (reference_table.user_id = raw_events_second.user_id) - ) reference_ids - JOIN LATERAL - (SELECT - user_id, value_4 - FROM - raw_events_first WHERE - value_4 = reference_ids.user_id) as averages ON true - GROUP BY averages.user_id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- join among reference_ids and averages is not on the partition key -INSERT INTO agg_events (user_id, value_4_agg) -SELECT - averages.user_id, avg(averages.value_4) -FROM - (SELECT - raw_events_second.user_id - FROM - reference_table JOIN raw_events_second on (reference_table.user_id = raw_events_second.user_id) - ) reference_ids - JOIN LATERAL - (SELECT - user_id, value_4 - FROM - raw_events_first) as averages ON averages.value_4 = reference_ids.user_id - GROUP BY averages.user_id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- join among the agg_ids and averages is not on the partition key -INSERT INTO agg_events (user_id, value_4_agg) -SELECT - averages.user_id, avg(averages.value_4) -FROM - (SELECT - raw_events_second.user_id - FROM - reference_table JOIN raw_events_second on (reference_table.user_id = raw_events_second.user_id) - ) reference_ids - JOIN LATERAL - (SELECT - user_id, value_4 - FROM - raw_events_first) as averages ON averages.user_id = reference_ids.user_id -JOIN LATERAL - (SELECT user_id, value_4 FROM agg_events) as agg_ids ON (agg_ids.value_4 = averages.user_id) - GROUP BY averages.user_id; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- not supported subqueries in WHERE clause --- since the selected value in the WHERE is not --- partition key -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT value_1 - FROM raw_events_second); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- same as above but slightly more complex --- since it also includes subquery in FROM as well -INSERT INTO agg_events - (user_id) -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id) -WHERE f.id IN (SELECT value_1 - FROM raw_events_second); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- some more semi-anti join tests --- join in where -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN (SELECT raw_events_second.user_id - FROM raw_events_second, raw_events_first - WHERE raw_events_second.user_id = raw_events_first.user_id AND raw_events_first.user_id = 200); -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300004 raw_events_second, public.raw_events_first_13300000 raw_events_first_1 WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first_1.user_id) AND (raw_events_first_1.user_id OPERATOR(pg_catalog.=) 200)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: Skipping target shard interval 13300005 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away -DEBUG: Plan is router executable --- we cannot push this down since it is NOT IN -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id NOT IN (SELECT raw_events_second.user_id - FROM raw_events_second, raw_events_first - WHERE raw_events_second.user_id = raw_events_first.user_id AND raw_events_first.user_id = 200); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- safe to push down -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE EXISTS (SELECT 1 - FROM raw_events_second - WHERE raw_events_second.user_id =raw_events_first.user_id); -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((EXISTS (SELECT 1 FROM public.raw_events_second_13300004 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300001 raw_events_first WHERE ((EXISTS (SELECT 1 FROM public.raw_events_second_13300005 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((EXISTS (SELECT 1 FROM public.raw_events_second_13300006 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((EXISTS (SELECT 1 FROM public.raw_events_second_13300007 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable --- we cannot push down -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE NOT EXISTS (SELECT 1 - FROM raw_events_second - WHERE raw_events_second.user_id =raw_events_first.user_id); -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300004 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300001 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300005 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300006 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300007 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable --- more complex LEFT JOINs - INSERT INTO agg_events - (user_id, value_4_agg) - SELECT - outer_most.id, max(outer_most.value) - FROM - ( - SELECT f2.id as id, f2.v4 as value FROM - (SELECT - id - FROM (SELECT raw_events_first.user_id AS id - FROM raw_events_first LEFT JOIN - reference_table - ON (raw_events_first.user_id = reference_table.user_id)) AS foo) as f - LEFT JOIN - (SELECT v4, - v1, - id - FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 - ON (f.id = f2.id)) as outer_most - GROUP BY - outer_most.id; -DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT raw_events_first.user_id AS id FROM (public.raw_events_first_13300000 raw_events_first LEFT JOIN public.reference_table_13300012 reference_table ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)))) foo) f LEFT JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT raw_events_first.user_id AS id FROM (public.raw_events_first_13300001 raw_events_first LEFT JOIN public.reference_table_13300012 reference_table ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)))) foo) f LEFT JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT raw_events_first.user_id AS id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN public.reference_table_13300012 reference_table ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)))) foo) f LEFT JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 1073741823)) GROUP BY id -DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_4_agg) SELECT id, max(value) AS max FROM (SELECT f2.id, f2.v4 AS value FROM ((SELECT foo.id FROM (SELECT raw_events_first.user_id AS id FROM (public.raw_events_first_13300003 raw_events_first LEFT JOIN public.reference_table_13300012 reference_table ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)))) foo) f LEFT JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id)))) outer_most WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY id -DEBUG: Plan is router executable --- cannot push down since the f.id IN is matched with value_1 -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN ( -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id) -WHERE f.id IN (SELECT value_1 - FROM raw_events_second)); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- same as above, but this time is it safe to push down since --- f.id IN is matched with user_id -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN ( -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id) -WHERE f.id IN (SELECT user_id - FROM raw_events_second)); -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300000 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300000 raw_events_first_1, public.reference_table_13300012 reference_table WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first_1.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first_1, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE (f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300004 raw_events_second)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300001 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300001 raw_events_first_1, public.reference_table_13300012 reference_table WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first_1.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300001 raw_events_first_1, public.raw_events_second_13300005 raw_events_second WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE (f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300005 raw_events_second)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300002 raw_events_first_1, public.reference_table_13300012 reference_table WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first_1.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300002 raw_events_first_1, public.raw_events_second_13300006 raw_events_second WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE (f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300006 raw_events_second)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((user_id OPERATOR(pg_catalog.=) ANY (SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300003 raw_events_first_1, public.reference_table_13300012 reference_table WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first_1.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first_1, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first_1.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (10)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE (f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) -DEBUG: Plan is router executable --- cannot push down since top level user_id is matched with NOT IN -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id NOT IN ( -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id = f2.id) -WHERE f.id IN (SELECT user_id - FROM raw_events_second)); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- cannot push down since join is not equi join (f.id > f2.id) -INSERT INTO raw_events_second - (user_id) -SELECT user_id -FROM raw_events_first -WHERE user_id IN ( -SELECT f2.id FROM -(SELECT - id -FROM (SELECT reference_table.user_id AS id - FROM raw_events_first, - reference_table - WHERE raw_events_first.user_id = reference_table.user_id ) AS foo) as f -INNER JOIN -(SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id - GROUP BY raw_events_second.user_id - HAVING SUM(raw_events_second.value_4) > 10) AS foo2 ) as f2 -ON (f.id > f2.id) -WHERE f.id IN (SELECT user_id - FROM raw_events_second)); -ERROR: cannot perform distributed planning for the given modification -DETAIL: Select query cannot be pushed down to the worker. --- we currently not support grouping sets -INSERT INTO agg_events - (user_id, - value_1_agg, - value_2_agg) -SELECT user_id, - Sum(value_1) AS sum_val1, - Sum(value_2) AS sum_val2 -FROM raw_events_second -GROUP BY grouping sets ( ( user_id ), ( value_1 ), ( user_id, value_1 ), ( ) ); -DEBUG: grouping sets are not allowed in distributed INSERT ... SELECT queries -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -ERROR: could not run distributed query with GROUPING SETS, CUBE, or ROLLUP -HINT: Consider using an equality filter on the distributed table's partition column. --- set back to INFO -SET client_min_messages TO INFO; --- avoid constraint violations -TRUNCATE raw_events_first; --- we don't support LIMIT for subquery pushdown, but --- we recursively plan the query and run it via coordinator -INSERT INTO agg_events(user_id) -SELECT user_id -FROM users_table -WHERE user_id - IN (SELECT - user_id - FROM ( - ( - SELECT - user_id - FROM - ( - SELECT - e1.user_id - FROM - users_table u1, events_table e1 - WHERE - e1.user_id = u1.user_id LIMIT 3 - ) as f_inner - ) - ) AS f2); --- Altering a table and selecting from it using a multi-shard statement --- in the same transaction is allowed because we will use the same --- connections for all co-located placements. -BEGIN; -ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -ROLLBACK; --- Alterating a table and selecting from it using a single-shard statement --- in the same transaction is disallowed because we will use a different --- connection. -BEGIN; -ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; -ROLLBACK; --- Altering a reference table and then performing an INSERT ... SELECT which --- joins with the reference table is allowed, since the INSERT ... SELECT --- would read from the reference table over the same connections with the ones --- that performed the parallel DDL. -BEGIN; -ALTER TABLE reference_table ADD COLUMN z int; -INSERT INTO raw_events_first (user_id) -SELECT user_id FROM raw_events_second JOIN reference_table USING (user_id); -ROLLBACK; --- the same test with sequential DDL should work fine -BEGIN; -SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; -ALTER TABLE reference_table ADD COLUMN z int; -INSERT INTO raw_events_first (user_id) -SELECT user_id FROM raw_events_second JOIN reference_table USING (user_id); -ROLLBACK; --- Insert after copy is allowed -BEGIN; -COPY raw_events_second (user_id, value_1) FROM STDIN DELIMITER ','; -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -ROLLBACK; --- Insert after copy is currently allowed for single-shard operation. --- Both insert and copy are rolled back successfully. -BEGIN; -COPY raw_events_second (user_id, value_1) FROM STDIN DELIMITER ','; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 101; -SELECT user_id FROM raw_events_first WHERE user_id = 101; - user_id ---------- - 101 -(1 row) - -ROLLBACK; -BEGIN; -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -COPY raw_events_first (user_id, value_1) FROM STDIN DELIMITER ','; -ROLLBACK; -BEGIN; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; -COPY raw_events_first (user_id, value_1) FROM STDIN DELIMITER ','; -ROLLBACK; --- Similarly, multi-row INSERTs will take part in transactions and reuse connections... -BEGIN; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; -COPY raw_events_first (user_id, value_1) FROM STDIN DELIMITER ','; -INSERT INTO raw_events_first (user_id, value_1) VALUES (105, 105), (106, 106); -ROLLBACK; --- selecting from views works -CREATE VIEW test_view AS SELECT * FROM raw_events_first; -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (16, now(), 60, 600, 6000.1, 60000); -SELECT count(*) FROM raw_events_second; - count -------- - 36 -(1 row) - -INSERT INTO raw_events_second SELECT * FROM test_view; -INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES - (17, now(), 60, 600, 6000.1, 60000); -INSERT INTO raw_events_second SELECT * FROM test_view WHERE user_id = 17 GROUP BY 1,2,3,4,5,6; -SELECT count(*) FROM raw_events_second; - count -------- - 38 -(1 row) - --- intermediate results (CTEs) should be allowed when doing INSERT...SELECT within a CTE -WITH series AS ( - SELECT s AS val FROM generate_series(60,70) s -), -inserts AS ( - INSERT INTO raw_events_second (user_id) - SELECT - user_id - FROM - raw_events_first JOIN series ON (value_1 = val) - RETURNING - NULL -) -SELECT count(*) FROM inserts; - count -------- - 2 -(1 row) - --- we need this in our next test -truncate raw_events_first; -SET client_min_messages TO DEBUG2; --- first show that the query works now -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300004 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300001 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300005 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300002 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300006 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300003 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300007 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable -SET client_min_messages TO INFO; -truncate raw_events_first; -SET client_min_messages TO DEBUG2; --- now show that it works for a single shard query as well -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 5; -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300004 raw_events_second WHERE ((user_id OPERATOR(pg_catalog.=) 5) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: Skipping target shard interval 13300001 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300002 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300003 since SELECT query for it pruned away -DEBUG: Plan is router executable -SET client_min_messages TO INFO; --- if a single shard of the SELECT is unhealty, the query should fail -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = 13300004 AND nodeport = :worker_1_port; -truncate raw_events_first; -SET client_min_messages TO DEBUG2; --- this should fail -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Insert query cannot be executed on all placements for shard 13300000 --- this should also fail -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 5; -ERROR: cannot perform distributed planning for the given modification -DETAIL: Insert query cannot be executed on all placements for shard 13300000 --- but this should work given that it hits different shard -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 6; -DEBUG: Skipping target shard interval 13300000 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300001 since SELECT query for it pruned away -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300002 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300006 raw_events_second WHERE ((user_id OPERATOR(pg_catalog.=) 6) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) -DEBUG: Skipping target shard interval 13300003 since SELECT query for it pruned away -DEBUG: Plan is router executable -SET client_min_messages TO INFO; --- mark the unhealthy placement as healthy again for the next tests -UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE shardid = 13300004 AND nodeport = :worker_1_port; --- now that we should show that it works if one of the target shard interval is not healthy -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = 13300000 AND nodeport = :worker_1_port; -truncate raw_events_first; -SET client_min_messages TO DEBUG2; --- this should work -INSERT INTO raw_events_first SELECT * FROM raw_events_second; -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300004 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300001 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300005 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300002 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300006 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823)) -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300003 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300007 raw_events_second WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable -SET client_min_messages TO INFO; -truncate raw_events_first; -SET client_min_messages TO DEBUG2; --- this should also work -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 5; -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, "time", value_1, value_2, value_3, value_4) SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM public.raw_events_second_13300004 raw_events_second WHERE ((user_id OPERATOR(pg_catalog.=) 5) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) -DEBUG: Skipping target shard interval 13300001 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300002 since SELECT query for it pruned away -DEBUG: Skipping target shard interval 13300003 since SELECT query for it pruned away -DEBUG: Plan is router executable -SET client_min_messages TO INFO; --- now do some tests with varchars -INSERT INTO insert_select_varchar_test VALUES ('test_1', 10); -INSERT INTO insert_select_varchar_test VALUES ('test_2', 30); -INSERT INTO insert_select_varchar_test (key, value) -SELECT *, 100 -FROM (SELECT f1.key - FROM (SELECT key - FROM insert_select_varchar_test - GROUP BY 1 - HAVING Count(key) < 3) AS f1, - (SELECT key - FROM insert_select_varchar_test - GROUP BY 1 - HAVING Sum(COALESCE(insert_select_varchar_test.value, 0)) > - 20.0) - AS f2 - WHERE f1.key = f2.key - GROUP BY 1) AS foo; -SELECT * FROM insert_select_varchar_test ORDER BY 1 DESC, 2 DESC; - key | value ---------+------- - test_2 | 100 - test_2 | 30 - test_1 | 10 -(3 rows) - --- some tests with DEFAULT columns and constant values --- this test is mostly importantly intended for deparsing the query correctly --- but still it is preferable to have this test here instead of multi_deparse_shard_query -CREATE TABLE table_with_defaults -( - store_id int, - first_name text, - default_1 int DEFAULT 1, - last_name text, - default_2 text DEFAULT '2' -); --- we don't need many shards -SET citus.shard_count = 2; -SELECT create_distributed_table('table_with_defaults', 'store_id'); - create_distributed_table --------------------------- - -(1 row) - --- let's see the queries -SET client_min_messages TO DEBUG2; --- a very simple query -INSERT INTO table_with_defaults SELECT * FROM table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, default_1, last_name, default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, default_1, last_name, default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- see that defaults are filled -INSERT INTO table_with_defaults (store_id, first_name) -SELECT - store_id, first_name -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, '2'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, '2'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- shuffle one of the defaults and skip the other -INSERT INTO table_with_defaults (default_2, store_id, first_name) -SELECT - default_2, store_id, first_name -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- shuffle both defaults -INSERT INTO table_with_defaults (default_2, store_id, default_1, first_name) -SELECT - default_2, store_id, default_1, first_name -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, default_1, default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, default_1, default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- use constants instead of non-default column -INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name) -SELECT - default_2, 'Freund', store_id, 'Andres' -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- use constants instead of non-default column and skip both defauls -INSERT INTO table_with_defaults (last_name, store_id, first_name) -SELECT - 'Freund', store_id, 'Andres' -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, '2'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, '2'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- use constants instead of default columns -INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1) -SELECT - 20, last_name, store_id, first_name, 10 -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, 10, last_name, 20 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, 10, last_name, 20 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- use constants instead of both default columns and non-default columns -INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1) -SELECT - 20, 'Freund', store_id, 'Andres', 10 -FROM - table_with_defaults; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 10, 'Freund'::text AS last_name, 20 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 10, 'Freund'::text AS last_name, 20 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) -DEBUG: Plan is router executable --- some of the the ultimate queries where we have constants, --- defaults and group by entry is not on the target entry -INSERT INTO table_with_defaults (default_2, store_id, first_name) -SELECT - '2000', store_id, 'Andres' -FROM - table_with_defaults -GROUP BY - last_name, store_id; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, '2000'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY last_name, store_id -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, '2000'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY last_name, store_id -DEBUG: Plan is router executable -INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2) -SELECT - 1000, store_id, 'Andres', '2000' -FROM - table_with_defaults -GROUP BY - last_name, store_id, first_name; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY last_name, store_id, first_name -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY last_name, store_id, first_name -DEBUG: Plan is router executable -INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2) -SELECT - 1000, store_id, 'Andres', '2000' -FROM - table_with_defaults -GROUP BY - last_name, store_id, first_name, default_2; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY last_name, store_id, first_name, default_2 -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY last_name, store_id, first_name, default_2 -DEBUG: Plan is router executable -INSERT INTO table_with_defaults (default_1, store_id, first_name) -SELECT - 1000, store_id, 'Andres' -FROM - table_with_defaults -GROUP BY - last_name, store_id, first_name, default_2; -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300017 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2'::text AS default_2 FROM public.table_with_defaults_13300017 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) '-1'::integer)) GROUP BY last_name, store_id, first_name, default_2 -DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300018 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2'::text AS default_2 FROM public.table_with_defaults_13300018 table_with_defaults WHERE ((worker_hash(store_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(store_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY last_name, store_id, first_name, default_2 -DEBUG: Plan is router executable -RESET client_min_messages; --- Stable function in default should be allowed -ALTER TABLE table_with_defaults ADD COLUMN t timestamptz DEFAULT now(); -INSERT INTO table_with_defaults (store_id, first_name, last_name) -SELECT - store_id, 'first '||store_id, 'last '||store_id -FROM - table_with_defaults -GROUP BY - store_id, first_name, last_name; --- Volatile function in default should be disallowed -CREATE TABLE table_with_serial ( - store_id int, - s bigserial -); -SELECT create_distributed_table('table_with_serial', 'store_id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO table_with_serial (store_id) -SELECT - store_id -FROM - table_with_defaults -GROUP BY - store_id; -ERROR: INSERT ... SELECT cannot generate sequence values when selecting from a distributed table --- do some more error/error message checks -SET citus.shard_count TO 4; -SET citus.shard_replication_factor TO 1; -CREATE TABLE text_table (part_col text, val int); -CREATE TABLE char_table (part_col char[], val int); -create table table_with_starts_with_defaults (a int DEFAULT 5, b int, c int); -SELECT create_distributed_table('text_table', 'part_col'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('char_table','part_col'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('table_with_starts_with_defaults', 'c'); - create_distributed_table --------------------------- - -(1 row) - -SET client_min_messages TO DEBUG; -INSERT INTO text_table (part_col) - SELECT - CASE WHEN part_col = 'onder' THEN 'marco' - END -FROM text_table ; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains a case expression in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT COALESCE(part_col, 'onder') FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains a coalesce expression in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT GREATEST(part_col, 'jason') FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains a min/max expression in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT LEAST(part_col, 'andres') FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains a min/max expression in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT NULLIF(part_col, 'metin') FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT part_col isnull FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT part_col::text from char_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an explicit coercion in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT (part_col = 'burak') is true FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an expression that is not a simple column reference in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT val FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: The data type of the target table's partition column should exactly match the data type of the corresponding simple column reference in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -INSERT INTO text_table (part_col) SELECT val::text FROM text_table; -DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match -DETAIL: Subquery contains an explicit coercion in the same position as the target table's partition column. -HINT: Ensure the target table's partition column has a corresponding simple column reference to a distributed table's partition column in the subquery. -DEBUG: Collecting INSERT ... SELECT results on coordinator -DEBUG: Router planner cannot handle multi-shard select queries -RESET client_min_messages; -insert into table_with_starts_with_defaults (b,c) select b,c FROM table_with_starts_with_defaults; --- Test on partition column without native hash function -CREATE TABLE raw_table -( - id BIGINT, - time DATE -); -CREATE TABLE summary_table -( - time DATE, - count BIGINT -); -SELECT create_distributed_table('raw_table', 'time'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('summary_table', 'time'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO raw_table VALUES(1, '11-11-1980'); -INSERT INTO summary_table SELECT time, COUNT(*) FROM raw_table GROUP BY time; -SELECT * FROM summary_table; - time | count -------------+------- - 11-11-1980 | 1 -(1 row) - --- Test INSERT ... SELECT via coordinator --- Select from constants -TRUNCATE raw_events_first; -INSERT INTO raw_events_first (user_id, value_1) -SELECT * FROM (VALUES (1,2), (3,4), (5,6)) AS v(int,int); -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id; - user_id | value_1 ----------+--------- - 1 | 2 - 3 | 4 - 5 | 6 -(3 rows) - --- Select from local functions -TRUNCATE raw_events_first; -CREATE SEQUENCE insert_select_test_seq; -SET client_min_messages TO DEBUG; -INSERT INTO raw_events_first (user_id, value_1, value_2) -SELECT - s, nextval('insert_select_test_seq'), (random()*10)::int -FROM - generate_series(1, 5) s; -DEBUG: distributed INSERT ... SELECT can only select from distributed tables -DEBUG: Collecting INSERT ... SELECT results on coordinator -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; -DEBUG: Router planner cannot handle multi-shard select queries - user_id | value_1 ----------+--------- - 1 | 1 - 2 | 2 - 3 | 3 - 4 | 4 - 5 | 5 -(5 rows) - --- ON CONFLICT is supported -INSERT INTO raw_events_first (user_id, value_1) -SELECT s, nextval('insert_select_test_seq') FROM generate_series(1, 5) s -ON CONFLICT DO NOTHING; -DEBUG: distributed INSERT ... SELECT can only select from distributed tables -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_206_13300000'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) ON CONFLICT DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300001 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_206_13300001'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) ON CONFLICT DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300002 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_206_13300002'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) ON CONFLICT DO NOTHING -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300003 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_206_13300003'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) ON CONFLICT DO NOTHING -DEBUG: Collecting INSERT ... SELECT results on coordinator --- RETURNING is supported -INSERT INTO raw_events_first (user_id, value_1) -SELECT s, nextval('insert_select_test_seq') FROM generate_series(1, 5) s -RETURNING *; -DEBUG: distributed INSERT ... SELECT can only select from distributed tables -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300000 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_207_13300000'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300001 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_207_13300001'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300002 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_207_13300002'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: distributed statement: INSERT INTO public.raw_events_first_13300003 AS citus_table_alias (user_id, value_1) SELECT user_id, value_1 FROM read_intermediate_result('insert_select_207_13300003'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_1 integer) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 -DEBUG: Collecting INSERT ... SELECT results on coordinator - user_id | time | value_1 | value_2 | value_3 | value_4 ----------+------+---------+---------+---------+--------- - 1 | | 11 | | | - 2 | | 12 | | | - 3 | | 13 | | | - 4 | | 14 | | | - 5 | | 15 | | | -(5 rows) - -RESET client_min_messages; --- INSERT ... SELECT and multi-shard SELECT in the same transaction is supported -TRUNCATE raw_events_first; -BEGIN; -INSERT INTO raw_events_first (user_id, value_1) -SELECT s, s FROM generate_series(1, 5) s; -SELECT user_id, value_1 FROM raw_events_first ORDER BY 1; - user_id | value_1 ----------+--------- - 1 | 1 - 2 | 2 - 3 | 3 - 4 | 4 - 5 | 5 -(5 rows) - -ROLLBACK; --- INSERT ... SELECT and single-shard SELECT in the same transaction is supported -TRUNCATE raw_events_first; -BEGIN; -INSERT INTO raw_events_first (user_id, value_1) -SELECT s, s FROM generate_series(1, 5) s; -SELECT user_id, value_1 FROM raw_events_first WHERE user_id = 1; - user_id | value_1 ----------+--------- - 1 | 1 -(1 row) - -COMMIT; --- Select from local table -TRUNCATE raw_events_first; -CREATE TEMPORARY TABLE raw_events_first_local AS -SELECT s AS u, 2*s AS v FROM generate_series(1, 5) s; -INSERT INTO raw_events_first (user_id, value_1) -SELECT u, v FROM raw_events_first_local; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | 2 - 2 | 4 - 3 | 6 - 4 | 8 - 5 | 10 -(5 rows) - --- Use columns in opposite order -TRUNCATE raw_events_first; -INSERT INTO raw_events_first (value_1, user_id) -SELECT u, v FROM raw_events_first_local; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 2 | 1 - 4 | 2 - 6 | 3 - 8 | 4 - 10 | 5 -(5 rows) - --- Set operations can work with opposite column order -TRUNCATE raw_events_first; -INSERT INTO raw_events_first (value_3, user_id) -( SELECT v, u::bigint FROM raw_events_first_local ) -UNION ALL -( SELECT v, u FROM raw_events_first_local ); -SELECT user_id, value_3 FROM raw_events_first ORDER BY user_id, value_3; - user_id | value_3 ----------+--------- - 1 | 2 - 1 | 2 - 2 | 4 - 2 | 4 - 3 | 6 - 3 | 6 - 4 | 8 - 4 | 8 - 5 | 10 - 5 | 10 -(10 rows) - --- Select from other distributed table with limit -TRUNCATE raw_events_first; -TRUNCATE raw_events_second; -INSERT INTO raw_events_second (user_id, value_4) -SELECT s, 3*s FROM generate_series (1,5) s; -INSERT INTO raw_events_first (user_id, value_1) -SELECT user_id, value_4 FROM raw_events_second LIMIT 5; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | 3 - 2 | 6 - 3 | 9 - 4 | 12 - 5 | 15 -(5 rows) - --- CTEs are supported in local queries -TRUNCATE raw_events_first; -WITH removed_rows AS ( - DELETE FROM raw_events_first_local RETURNING u -) -INSERT INTO raw_events_first (user_id, value_1) -WITH value AS (SELECT 1) -SELECT * FROM removed_rows, value; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | 1 - 2 | 1 - 3 | 1 - 4 | 1 - 5 | 1 -(5 rows) - --- nested CTEs are also supported -TRUNCATE raw_events_first; -INSERT INTO raw_events_first_local SELECT s, 2*s FROM generate_series(0, 10) s; -WITH rows_to_remove AS ( - SELECT u FROM raw_events_first_local WHERE u > 0 -), -removed_rows AS ( - DELETE FROM raw_events_first_local - WHERE u IN (SELECT * FROM rows_to_remove) - RETURNING u, v -) -INSERT INTO raw_events_first (user_id, value_1) -WITH ultra_rows AS ( - WITH numbers AS ( - SELECT s FROM generate_series(1,10) s - ), - super_rows AS ( - SELECT u, v FROM removed_rows JOIN numbers ON (u = s) - ) - SELECT * FROM super_rows LIMIT 5 -) -SELECT u, v FROM ultra_rows; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | 2 - 2 | 4 - 3 | 6 - 4 | 8 - 5 | 10 -(5 rows) - --- CTEs with duplicate names are also supported -TRUNCATE raw_events_first; -WITH super_rows AS ( - SELECT u FROM raw_events_first_local -) -INSERT INTO raw_events_first (user_id, value_1) -WITH super_rows AS ( - SELECT * FROM super_rows GROUP BY u -) -SELECT u, 5 FROM super_rows; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 0 | 5 -(1 row) - --- CTEs are supported in router queries -TRUNCATE raw_events_first; -WITH user_two AS ( - SELECT user_id, value_4 FROM raw_events_second WHERE user_id = 2 -) -INSERT INTO raw_events_first (user_id, value_1) -SELECT * FROM user_two; -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 2 | 6 -(1 row) - --- CTEs are supported when there are name collisions -WITH numbers AS ( - SELECT s FROM generate_series(1,10) s -) -INSERT INTO raw_events_first(user_id, value_1) -WITH numbers AS ( - SELECT s, s FROM generate_series(1,5) s -) -SELECT * FROM numbers; --- Select into distributed table with a sequence -CREATE TABLE "CaseSensitiveTable" ("UserID" int, "Value1" int); -SELECT create_distributed_table('"CaseSensitiveTable"', 'UserID'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO "CaseSensitiveTable" -SELECT s, s FROM generate_series(1,10) s; -SELECT * FROM "CaseSensitiveTable" ORDER BY "UserID"; - UserID | Value1 ---------+-------- - 1 | 1 - 2 | 2 - 3 | 3 - 4 | 4 - 5 | 5 - 6 | 6 - 7 | 7 - 8 | 8 - 9 | 9 - 10 | 10 -(10 rows) - -DROP TABLE "CaseSensitiveTable"; --- Select into distributed table with a sequence -CREATE TABLE dist_table_with_sequence (user_id serial, value_1 serial); -SELECT create_distributed_table('dist_table_with_sequence', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - --- from local query -INSERT INTO dist_table_with_sequence (value_1) -SELECT s FROM generate_series(1,5) s; -SELECT * FROM dist_table_with_sequence ORDER BY user_id; - user_id | value_1 ----------+--------- - 1 | 1 - 2 | 2 - 3 | 3 - 4 | 4 - 5 | 5 -(5 rows) - --- from a distributed query -INSERT INTO dist_table_with_sequence (value_1) -SELECT value_1 FROM dist_table_with_sequence; -ERROR: INSERT ... SELECT cannot generate sequence values when selecting from a distributed table -SELECT * FROM dist_table_with_sequence ORDER BY user_id; - user_id | value_1 ----------+--------- - 1 | 1 - 2 | 2 - 3 | 3 - 4 | 4 - 5 | 5 -(5 rows) - --- Select from distributed table into reference table -CREATE TABLE ref_table (user_id int, value_1 int); -SELECT create_reference_table('ref_table'); - create_reference_table ------------------------- - -(1 row) - -INSERT INTO ref_table -SELECT user_id, value_1 FROM raw_events_second; -SELECT * FROM ref_table ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | - 2 | - 3 | - 4 | - 5 | -(5 rows) - -DROP TABLE ref_table; --- Select from reference table into reference table -CREATE TABLE ref1 (d timestamptz); -SELECT create_reference_table('ref1'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE ref2 (d date); -SELECT create_reference_table('ref2'); - create_reference_table ------------------------- - -(1 row) - -INSERT INTO ref2 VALUES ('2017-10-31'); -INSERT INTO ref1 SELECT * FROM ref2; -SELECT count(*) from ref1; - count -------- - 1 -(1 row) - --- also test with now() -INSERT INTO ref1 SELECT now() FROM ref2; -SELECT count(*) from ref1; - count -------- - 2 -(1 row) - -DROP TABLE ref1; -DROP TABLE ref2; --- Select into an append-partitioned table is not supported -CREATE TABLE insert_append_table (user_id int, value_4 bigint); -SELECT create_distributed_table('insert_append_table', 'user_id', 'append'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO insert_append_table (user_id, value_4) -SELECT user_id, 1 FROM raw_events_second LIMIT 5; -ERROR: INSERT ... SELECT into an append-distributed table is not supported -DROP TABLE insert_append_table; --- Insert from other distributed table as prepared statement -TRUNCATE raw_events_first; -PREPARE insert_prep(int) AS -INSERT INTO raw_events_first (user_id, value_1) -SELECT $1, value_4 FROM raw_events_second ORDER BY value_4 LIMIT 1; -EXECUTE insert_prep(1); -EXECUTE insert_prep(2); -EXECUTE insert_prep(3); -EXECUTE insert_prep(4); -EXECUTE insert_prep(5); -EXECUTE insert_prep(6); -SELECT user_id, value_1 FROM raw_events_first ORDER BY user_id, value_1; - user_id | value_1 ----------+--------- - 1 | 3 - 2 | 3 - 3 | 3 - 4 | 3 - 5 | 3 - 6 | 3 -(6 rows) - --- Inserting into views is handled via coordinator -TRUNCATE raw_events_first; -INSERT INTO test_view -SELECT * FROM raw_events_second; -SELECT user_id, value_4 FROM test_view ORDER BY user_id, value_4; - user_id | value_4 ----------+--------- - 1 | 3 - 2 | 6 - 3 | 9 - 4 | 12 - 5 | 15 -(5 rows) - --- Drop the view now, because the column we are about to drop depends on it -DROP VIEW test_view; --- Make sure we handle dropped columns correctly -CREATE TABLE drop_col_table (col1 text, col2 text, col3 text); -SELECT create_distributed_table('drop_col_table', 'col2'); - create_distributed_table --------------------------- - -(1 row) - -ALTER TABLE drop_col_table DROP COLUMN col1; -INSERT INTO drop_col_table (col3, col2) -SELECT value_4, user_id FROM raw_events_second LIMIT 5; -SELECT * FROM drop_col_table ORDER BY col2, col3; - col2 | col3 -------+------ - 1 | 3 - 2 | 6 - 3 | 9 - 4 | 12 - 5 | 15 -(5 rows) - --- make sure the tuple went to the right shard -SELECT * FROM drop_col_table WHERE col2 = '1'; - col2 | col3 -------+------ - 1 | 3 -(1 row) - -RESET client_min_messages; --- make sure casts are handled correctly -CREATE TABLE coerce_events(user_id int, time timestamp, value_1 numeric); -SELECT create_distributed_table('coerce_events', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE coerce_agg (user_id int, value_1_agg int); -SELECT create_distributed_table('coerce_agg', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO coerce_events(user_id, value_1) VALUES (1, 1), (2, 2), (10, 10); --- numeric -> int (straight function) -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -ORDER BY 2 DESC, 1 DESC -LIMIT 5; --- int -> text -ALTER TABLE coerce_agg ALTER COLUMN value_1_agg TYPE text; -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -LIMIT 5; -SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; - user_id | value_1_agg ----------+------------- - 10 | 10 - 10 | 10 - 2 | 2 - 2 | 2 - 1 | 1 - 1 | 1 -(6 rows) - -TRUNCATE coerce_agg; --- int -> char(1) -ALTER TABLE coerce_agg ALTER COLUMN value_1_agg TYPE char(1); -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -LIMIT 5; -ERROR: value too long for type character(1) -SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; - user_id | value_1_agg ----------+------------- -(0 rows) - -TRUNCATE coerce_agg; -TRUNCATE coerce_events; --- char(5) -> char(1) -ALTER TABLE coerce_events ALTER COLUMN value_1 TYPE char(5); -INSERT INTO coerce_events(user_id, value_1) VALUES (1, 'aaaaa'), (2, 'bbbbb'); -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -LIMIT 5; -ERROR: value too long for type character(1) --- char(1) -> char(5) -ALTER TABLE coerce_events ALTER COLUMN value_1 TYPE char(1) USING value_1::char(1); -ALTER TABLE coerce_agg ALTER COLUMN value_1_agg TYPE char(5); -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -LIMIT 5; -SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; - user_id | value_1_agg ----------+------------- - 2 | b - 1 | a -(2 rows) - -TRUNCATE coerce_agg; -TRUNCATE coerce_events; --- integer -> integer (check VALUE < 5) -ALTER TABLE coerce_events ALTER COLUMN value_1 TYPE integer USING NULL; -ALTER TABLE coerce_agg ALTER COLUMN value_1_agg TYPE integer USING NULL; -ALTER TABLE coerce_agg ADD CONSTRAINT small_number CHECK (value_1_agg < 5); -INSERT INTO coerce_events (user_id, value_1) VALUES (1, 1), (10, 10); -\set VERBOSITY TERSE -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop; -ERROR: new row for relation "coerce_agg_13300060" violates check constraint "small_number_13300060" -\set VERBOSITY DEFAULT -SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; - user_id | value_1_agg ----------+------------- -(0 rows) - --- integer[3] -> text[3] -TRUNCATE coerce_events; -ALTER TABLE coerce_events ALTER COLUMN value_1 TYPE integer[3] USING NULL; -INSERT INTO coerce_events(user_id, value_1) VALUES (1, '{1,1,1}'), (2, '{2,2,2}'); -ALTER TABLE coerce_agg DROP COLUMN value_1_agg; -ALTER TABLE coerce_agg ADD COLUMN value_1_agg text[3]; -INSERT INTO coerce_agg(user_id, value_1_agg) -SELECT * -FROM ( - SELECT user_id, value_1 - FROM coerce_events -) AS ftop -LIMIT 5; -SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; - user_id | value_1_agg ----------+------------- - 2 | {2,2,2} - 1 | {1,1,1} -(2 rows) - --- INSERT..SELECT + prepared statements + recursive planning -BEGIN; -PREPARE prepared_recursive_insert_select AS -INSERT INTO users_table -SELECT * FROM users_table -WHERE value_1 IN (SELECT value_2 FROM events_table OFFSET 0); -EXECUTE prepared_recursive_insert_select; -EXECUTE prepared_recursive_insert_select; -EXECUTE prepared_recursive_insert_select; -EXECUTE prepared_recursive_insert_select; -EXECUTE prepared_recursive_insert_select; -EXECUTE prepared_recursive_insert_select; -ROLLBACK; --- upsert with on conflict update distribution column is unsupported -INSERT INTO agg_events AS ae - ( - user_id, - value_1_agg, - agg_time - ) -SELECT user_id, - value_1, - time -FROM raw_events_first -ON conflict (user_id, value_1_agg) -DO UPDATE - SET user_id = 42 -RETURNING user_id, value_1_agg; -ERROR: modifying the partition value of rows is not allowed --- wrap in a transaction to improve performance -BEGIN; -DROP TABLE coerce_events; -DROP TABLE coerce_agg; -DROP TABLE drop_col_table; -DROP TABLE raw_table; -DROP TABLE summary_table; -DROP TABLE raw_events_first CASCADE; -DROP TABLE raw_events_second; -DROP TABLE reference_table; -DROP TABLE agg_events; -DROP TABLE table_with_defaults; -DROP TABLE table_with_serial; -DROP TABLE text_table; -DROP TABLE char_table; -DROP TABLE table_with_starts_with_defaults; -COMMIT; diff --git a/src/test/regress/expected/multi_join_pruning.out b/src/test/regress/expected/multi_join_pruning.out index 829f38b29..7a0e933d9 100644 --- a/src/test/regress/expected/multi_join_pruning.out +++ b/src/test/regress/expected/multi_join_pruning.out @@ -74,10 +74,10 @@ EXPLAIN SELECT count(*) DEBUG: Router planner does not support append-partitioned tables. DEBUG: join prunable for intervals [{},{AZZXSP27F21T6,AZZXSP27F21T6}] and [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}] DEBUG: join prunable for intervals [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}] and [{},{AZZXSP27F21T6,AZZXSP27F21T6}] - QUERY PLAN ------------------------------------------------------------------------ + QUERY PLAN +---------------------------------------------------------------------- Aggregate (cost=0.00..0.00 rows=0 width=0) - -> Custom Scan (Citus Real-Time) (cost=0.00..0.00 rows=0 width=0) + -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) explain statements for distributed queries are not enabled (3 rows) @@ -87,10 +87,10 @@ EXPLAIN SELECT count(*) DEBUG: Router planner does not support append-partitioned tables. DEBUG: join prunable for intervals [(a,3,b),(b,4,c)] and [(c,5,d),(d,6,e)] DEBUG: join prunable for intervals [(c,5,d),(d,6,e)] and [(a,3,b),(b,4,c)] - QUERY PLAN ------------------------------------------------------------------------ + QUERY PLAN +---------------------------------------------------------------------- Aggregate (cost=0.00..0.00 rows=0 width=0) - -> Custom Scan (Citus Real-Time) (cost=0.00..0.00 rows=0 width=0) + -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) explain statements for distributed queries are not enabled (3 rows) @@ -101,10 +101,10 @@ EXPLAIN SELECT count(*) DEBUG: Router planner does not support append-partitioned tables. DEBUG: join prunable for intervals [AA1000U2AMO4ZGX,AZZXSP27F21T6] and [BA1000U2AMO4ZGX,BZZXSP27F21T6] DEBUG: join prunable for intervals [BA1000U2AMO4ZGX,BZZXSP27F21T6] and [AA1000U2AMO4ZGX,AZZXSP27F21T6] - QUERY PLAN ------------------------------------------------------------------------ + QUERY PLAN +---------------------------------------------------------------------- Aggregate (cost=0.00..0.00 rows=0 width=0) - -> Custom Scan (Citus Real-Time) (cost=0.00..0.00 rows=0 width=0) + -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) explain statements for distributed queries are not enabled (3 rows) diff --git a/src/test/regress/expected/multi_modifications.out b/src/test/regress/expected/multi_modifications.out index 7c55359a3..8367a5b01 100644 --- a/src/test/regress/expected/multi_modifications.out +++ b/src/test/regress/expected/multi_modifications.out @@ -348,7 +348,7 @@ ALTER TABLE limit_orders_750000 RENAME TO renamed_orders; -- the whole transaction should fail \set VERBOSITY terse INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -WARNING: relation "public.limit_orders_750000" does not exist +ERROR: relation "public.limit_orders_750000" does not exist -- set the shard name back \c - - - :worker_2_port -- Second: Move aside limit_orders shard on the second worker node @@ -359,7 +359,7 @@ ALTER TABLE renamed_orders RENAME TO limit_orders_750000; SELECT count(*) FROM limit_orders_750000 WHERE id = 276; count ------- - 1 + 0 (1 row) \c - - - :worker_2_port @@ -373,7 +373,7 @@ SELECT count(*) FROM limit_orders_750000 WHERE id = 276; SELECT count(*) FROM limit_orders WHERE id = 276; count ------- - 1 + 0 (1 row) SELECT count(*) @@ -384,7 +384,7 @@ AND sp.shardstate = 3 AND s.logicalrelid = 'limit_orders'::regclass; count ------- - 1 + 0 (1 row) -- Test that if all shards miss a modification, no state change occurs diff --git a/src/test/regress/expected/multi_modifications_9.out b/src/test/regress/expected/multi_modifications_9.out deleted file mode 100644 index 8367a5b01..000000000 --- a/src/test/regress/expected/multi_modifications_9.out +++ /dev/null @@ -1,1291 +0,0 @@ -SET citus.shard_count TO 32; -SET citus.next_shard_id TO 750000; -SET citus.next_placement_id TO 750000; --- some failure messages that comes from the worker nodes --- might change due to parallel executions, so suppress those --- using \set VERBOSITY terse --- =================================================================== --- test end-to-end modification functionality --- =================================================================== -CREATE TYPE order_side AS ENUM ('buy', 'sell'); -CREATE TABLE limit_orders ( - id bigint PRIMARY KEY, - symbol text NOT NULL, - bidder_id bigint NOT NULL, - placed_at timestamp NOT NULL, - kind order_side NOT NULL, - limit_price decimal NOT NULL DEFAULT 0.00 CHECK (limit_price >= 0.00) -); -CREATE TABLE multiple_hash ( - category text NOT NULL, - data text NOT NULL -); -CREATE TABLE insufficient_shards ( LIKE limit_orders ); -CREATE TABLE range_partitioned ( LIKE limit_orders ); -CREATE TABLE append_partitioned ( LIKE limit_orders ); -SET citus.shard_count TO 2; -SELECT create_distributed_table('limit_orders', 'id', 'hash'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('multiple_hash', 'id', 'hash'); -ERROR: column "id" of relation "multiple_hash" does not exist -SELECT create_distributed_table('range_partitioned', 'id', 'range'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('append_partitioned', 'id', 'append'); - create_distributed_table --------------------------- - -(1 row) - -SET citus.shard_count TO 1; -SET citus.shard_replication_factor TO 1; --- make a single shard that covers no partition values -SELECT create_distributed_table('insufficient_shards', 'id', 'hash'); - create_distributed_table --------------------------- - -(1 row) - -UPDATE pg_dist_shard SET shardminvalue = 0, shardmaxvalue = 0 -WHERE logicalrelid = 'insufficient_shards'::regclass; --- create range-partitioned shards -SELECT master_create_empty_shard('range_partitioned') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 0, shardmaxvalue = 49999 -WHERE shardid = :new_shard_id; -SELECT master_create_empty_shard('range_partitioned') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 50000, shardmaxvalue = 99999 -WHERE shardid = :new_shard_id; --- create append-partitioned shards -SELECT master_create_empty_shard('append_partitioned') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 0, shardmaxvalue = 500000 -WHERE shardid = :new_shard_id; -SELECT master_create_empty_shard('append_partitioned') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 500000, shardmaxvalue = 1000000 -WHERE shardid = :new_shard_id; --- basic single-row INSERT -INSERT INTO limit_orders VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); -SELECT COUNT(*) FROM limit_orders WHERE id = 32743; - count -------- - 1 -(1 row) - --- basic single-row INSERT with RETURNING -INSERT INTO limit_orders VALUES (32744, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', 20.69) RETURNING *; - id | symbol | bidder_id | placed_at | kind | limit_price --------+--------+-----------+--------------------------+------+------------- - 32744 | AAPL | 9580 | Tue Oct 19 10:23:54 2004 | buy | 20.69 -(1 row) - --- try a single-row INSERT with no shard to receive it -INSERT INTO insufficient_shards VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); -ERROR: cannot find shard interval -DETAIL: Hash of the partition column value does not fall into any shards. --- try an insert to a range-partitioned table -INSERT INTO range_partitioned VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); --- also insert to an append-partitioned table -INSERT INTO append_partitioned VALUES (414123, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); --- ensure the values are where we put them and query to ensure they are properly pruned -SET client_min_messages TO 'DEBUG2'; -SELECT * FROM range_partitioned WHERE id = 32743; -DEBUG: Creating router plan -DEBUG: Plan is router executable - id | symbol | bidder_id | placed_at | kind | limit_price --------+--------+-----------+--------------------------+------+------------- - 32743 | AAPL | 9580 | Tue Oct 19 10:23:54 2004 | buy | 20.69 -(1 row) - -SELECT * FROM append_partitioned WHERE id = 414123; -DEBUG: Router planner does not support append-partitioned tables. -DEBUG: Plan is router executable - id | symbol | bidder_id | placed_at | kind | limit_price ---------+--------+-----------+--------------------------+------+------------- - 414123 | AAPL | 9580 | Tue Oct 19 10:23:54 2004 | buy | 20.69 -(1 row) - -SET client_min_messages TO DEFAULT; --- try inserting without a range-partitioned shard to receive the value -INSERT INTO range_partitioned VALUES (999999, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); -ERROR: cannot run INSERT command which targets no shards -HINT: Make sure you have created a shard which can receive this partition column value. --- and insert into an append-partitioned table with a value that spans shards: -INSERT INTO append_partitioned VALUES (500000, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', - 20.69); -ERROR: cannot run INSERT command which targets multiple shards -HINT: Make sure the value for partition column "id" falls into a single shard. --- INSERT with DEFAULT in the target list -INSERT INTO limit_orders VALUES (12756, 'MSFT', 10959, '2013-05-08 07:29:23', 'sell', - DEFAULT); -SELECT COUNT(*) FROM limit_orders WHERE id = 12756; - count -------- - 1 -(1 row) - --- INSERT with expressions in target list -INSERT INTO limit_orders VALUES (430, upper('ibm'), 214, timestamp '2003-01-28 10:31:17' + - interval '5 hours', 'buy', sqrt(2)); -SELECT COUNT(*) FROM limit_orders WHERE id = 430; - count -------- - 1 -(1 row) - --- INSERT without partition key -INSERT INTO limit_orders DEFAULT VALUES; -ERROR: cannot perform an INSERT without a partition column value --- squelch WARNINGs that contain worker_port -SET client_min_messages TO ERROR; --- INSERT violating NOT NULL constraint -INSERT INTO limit_orders VALUES (NULL, 'T', 975234, DEFAULT); -ERROR: cannot perform an INSERT with NULL in the partition column --- INSERT violating column constraint -\set VERBOSITY terse -INSERT INTO limit_orders VALUES (18811, 'BUD', 14962, '2014-04-05 08:32:16', 'sell', - -5.00); -ERROR: new row for relation "limit_orders_750000" violates check constraint "limit_orders_limit_price_check" --- INSERT violating primary key constraint -INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58); -ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001" --- INSERT violating primary key constraint, with RETURNING specified. -INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING *; -ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001" --- INSERT, with RETURNING specified, failing with a non-constraint error -INSERT INTO limit_orders VALUES (34153, 'LEE', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING id / 0; -ERROR: division by zero -\set VERBOSITY DEFAULT -SET client_min_messages TO DEFAULT; --- commands with non-constant partition values are supported -INSERT INTO limit_orders VALUES (random() * 100, 'ORCL', 152, '2011-08-25 11:50:45', - 'sell', 0.58); --- values for other columns are totally fine -INSERT INTO limit_orders VALUES (2036, 'GOOG', 5634, now(), 'buy', random()); --- commands with mutable functions in their quals -DELETE FROM limit_orders WHERE id = 246 AND bidder_id = (random() * 1000); -ERROR: functions used in the WHERE clause of modification queries on distributed tables must not be VOLATILE --- commands with mutable but non-volatile functions(ie: stable func.) in their quals --- (the cast to timestamp is because the timestamp_eq_timestamptz operator is stable) -DELETE FROM limit_orders WHERE id = 246 AND placed_at = current_timestamp::timestamp; --- multi-row inserts are supported -INSERT INTO limit_orders VALUES (12037, 'GOOG', 5634, '2001-04-16 03:37:28', 'buy', 0.50), - (12038, 'GOOG', 5634, '2001-04-17 03:37:28', 'buy', 2.50), - (12039, 'GOOG', 5634, '2001-04-18 03:37:28', 'buy', 1.50); -SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 12037 AND 12039; - count -------- - 3 -(1 row) - --- even those with functions and returning -INSERT INTO limit_orders VALUES (22037, 'GOOG', 5634, now(), 'buy', 0.50), - (22038, 'GOOG', 5634, now(), 'buy', 2.50), - (22039, 'GOOG', 5634, now(), 'buy', 1.50) -RETURNING id; - id -------- - 22037 - 22038 - 22039 -(3 rows) - -SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 22037 AND 22039; - count -------- - 3 -(1 row) - --- even those with functions in their partition columns -INSERT INTO limit_orders VALUES (random() * 10 + 70000, 'GOOG', 5634, now(), 'buy', 0.50), - (random() * 10 + 80000, 'GOOG', 5634, now(), 'buy', 2.50), - (random() * 10 + 80090, 'GOOG', 5634, now(), 'buy', 1.50); -SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 70000 AND 90000; - count -------- - 3 -(1 row) - --- commands containing a CTE are supported -WITH deleted_orders AS (DELETE FROM limit_orders WHERE id < 0 RETURNING *) -INSERT INTO limit_orders SELECT * FROM deleted_orders; --- test simple DELETE -INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69); -SELECT COUNT(*) FROM limit_orders WHERE id = 246; - count -------- - 1 -(1 row) - -DELETE FROM limit_orders WHERE id = 246; -SELECT COUNT(*) FROM limit_orders WHERE id = 246; - count -------- - 0 -(1 row) - --- test simple DELETE with RETURNING -DELETE FROM limit_orders WHERE id = 430 RETURNING *; - id | symbol | bidder_id | placed_at | kind | limit_price ------+--------+-----------+--------------------------+------+----------------- - 430 | IBM | 214 | Tue Jan 28 15:31:17 2003 | buy | 1.4142135623731 -(1 row) - -SELECT COUNT(*) FROM limit_orders WHERE id = 430; - count -------- - 0 -(1 row) - --- DELETE with expression in WHERE clause -INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69); -SELECT COUNT(*) FROM limit_orders WHERE id = 246; - count -------- - 1 -(1 row) - -DELETE FROM limit_orders WHERE id = (2 * 123); -SELECT COUNT(*) FROM limit_orders WHERE id = 246; - count -------- - 0 -(1 row) - --- commands with a USING clause are supported -CREATE TABLE bidders ( name text, id bigint ); -DELETE FROM limit_orders USING bidders WHERE limit_orders.id = 246 AND - limit_orders.bidder_id = bidders.id AND - bidders.name = 'Bernie Madoff'; -ERROR: relation bidders is not distributed --- commands containing a CTE are supported -WITH new_orders AS (INSERT INTO limit_orders VALUES (411, 'FLO', 12, '2017-07-02 16:32:15', 'buy', 66)) -DELETE FROM limit_orders WHERE id < 0; --- we have to be careful that modifying CTEs are part of the transaction and can thus roll back -\set VERBOSITY terse -WITH new_orders AS (INSERT INTO limit_orders VALUES (412, 'FLO', 12, '2017-07-02 16:32:15', 'buy', 66)) -DELETE FROM limit_orders RETURNING id / 0; -ERROR: division by zero -\set VERBOSITY default -SELECT * FROM limit_orders WHERE id = 412; - id | symbol | bidder_id | placed_at | kind | limit_price -----+--------+-----------+-----------+------+------------- -(0 rows) - -INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69); --- simple UPDATE -UPDATE limit_orders SET symbol = 'GM' WHERE id = 246; -SELECT symbol FROM limit_orders WHERE id = 246; - symbol --------- - GM -(1 row) - --- simple UPDATE with RETURNING -UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *; - id | symbol | bidder_id | placed_at | kind | limit_price ------+--------+-----------+--------------------------+------+------------- - 246 | GM | 162 | Mon Jul 02 16:32:15 2007 | sell | 20.69 -(1 row) - --- expression UPDATE -UPDATE limit_orders SET bidder_id = 6 * 3 WHERE id = 246; -SELECT bidder_id FROM limit_orders WHERE id = 246; - bidder_id ------------ - 18 -(1 row) - --- expression UPDATE with RETURNING -UPDATE limit_orders SET bidder_id = 6 * 5 WHERE id = 246 RETURNING *; - id | symbol | bidder_id | placed_at | kind | limit_price ------+--------+-----------+--------------------------+------+------------- - 246 | GM | 30 | Mon Jul 02 16:32:15 2007 | sell | 20.69 -(1 row) - --- multi-column UPDATE -UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246; -SELECT kind, limit_price FROM limit_orders WHERE id = 246; - kind | limit_price -------+------------- - buy | 0.00 -(1 row) - --- multi-column UPDATE with RETURNING -UPDATE limit_orders SET (kind, limit_price) = ('buy', 999) WHERE id = 246 RETURNING *; - id | symbol | bidder_id | placed_at | kind | limit_price ------+--------+-----------+--------------------------+------+------------- - 246 | GM | 30 | Mon Jul 02 16:32:15 2007 | buy | 999 -(1 row) - --- Test that on unique contraint violations, we fail fast -\set VERBOSITY terse -INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001" --- Test that shards which miss a modification are marked unhealthy --- First: Connect to the second worker node -\c - - - :worker_2_port --- Second: Move aside limit_orders shard on the second worker node -ALTER TABLE limit_orders_750000 RENAME TO renamed_orders; --- Third: Connect back to master node -\c - - - :master_port --- Fourth: Perform an INSERT on the remaining node --- the whole transaction should fail -\set VERBOSITY terse -INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -ERROR: relation "public.limit_orders_750000" does not exist --- set the shard name back -\c - - - :worker_2_port --- Second: Move aside limit_orders shard on the second worker node -ALTER TABLE renamed_orders RENAME TO limit_orders_750000; --- Verify the insert failed and both placements are healthy --- or the insert succeeded and placement marked unhealthy -\c - - - :worker_1_port -SELECT count(*) FROM limit_orders_750000 WHERE id = 276; - count -------- - 0 -(1 row) - -\c - - - :worker_2_port -SELECT count(*) FROM limit_orders_750000 WHERE id = 276; - count -------- - 0 -(1 row) - -\c - - - :master_port -SELECT count(*) FROM limit_orders WHERE id = 276; - count -------- - 0 -(1 row) - -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.shardstate = 3 -AND s.logicalrelid = 'limit_orders'::regclass; - count -------- - 0 -(1 row) - --- Test that if all shards miss a modification, no state change occurs --- First: Connect to the first worker node -\c - - - :worker_1_port --- Second: Move aside limit_orders shard on the second worker node -ALTER TABLE limit_orders_750000 RENAME TO renamed_orders; --- Third: Connect back to master node -\c - - - :master_port --- Fourth: Perform an INSERT on the remaining node -\set VERBOSITY terse -INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -ERROR: relation "public.limit_orders_750000" does not exist -\set VERBOSITY DEFAULT --- Last: Verify worker is still healthy -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.nodename = 'localhost' -AND sp.nodeport = :worker_1_port -AND sp.shardstate = 1 -AND s.logicalrelid = 'limit_orders'::regclass; - count -------- - 2 -(1 row) - --- Undo our change... --- First: Connect to the first worker node -\c - - - :worker_1_port --- Second: Move aside limit_orders shard on the second worker node -ALTER TABLE renamed_orders RENAME TO limit_orders_750000; --- Third: Connect back to master node -\c - - - :master_port --- attempting to change the partition key is unsupported -UPDATE limit_orders SET id = 0 WHERE id = 246; -ERROR: modifying the partition value of rows is not allowed -UPDATE limit_orders SET id = 0 WHERE id = 0 OR id = 246; -ERROR: modifying the partition value of rows is not allowed --- setting the partition column value to itself is allowed -UPDATE limit_orders SET id = 246 WHERE id = 246; -UPDATE limit_orders SET id = 246 WHERE id = 246 AND symbol = 'GM'; -UPDATE limit_orders SET id = limit_orders.id WHERE id = 246; --- UPDATEs with a FROM clause are unsupported -UPDATE limit_orders SET limit_price = 0.00 FROM bidders - WHERE limit_orders.id = 246 AND - limit_orders.bidder_id = bidders.id AND - bidders.name = 'Bernie Madoff'; -ERROR: relation bidders is not distributed --- should succeed with a CTE -WITH deleted_orders AS (INSERT INTO limit_orders VALUES (399, 'PDR', 14, '2017-07-02 16:32:15', 'sell', 43)) -UPDATE limit_orders SET symbol = 'GM'; -SELECT symbol, bidder_id FROM limit_orders WHERE id = 246; - symbol | bidder_id ---------+----------- - GM | 30 -(1 row) - --- updates referencing just a var are supported -UPDATE limit_orders SET bidder_id = id WHERE id = 246; --- updates referencing a column are supported -UPDATE limit_orders SET bidder_id = bidder_id + 1 WHERE id = 246; --- IMMUTABLE functions are allowed -UPDATE limit_orders SET symbol = LOWER(symbol) WHERE id = 246; -SELECT symbol, bidder_id FROM limit_orders WHERE id = 246; - symbol | bidder_id ---------+----------- - gm | 247 -(1 row) - --- IMMUTABLE functions are allowed -- even in returning -UPDATE limit_orders SET symbol = UPPER(symbol) WHERE id = 246 RETURNING id, LOWER(symbol), symbol; - id | lower | symbol ------+-------+-------- - 246 | gm | GM -(1 row) - -ALTER TABLE limit_orders ADD COLUMN array_of_values integer[]; --- updates referencing STABLE functions are allowed -UPDATE limit_orders SET placed_at = LEAST(placed_at, now()::timestamp) WHERE id = 246; --- so are binary operators -UPDATE limit_orders SET array_of_values = 1 || array_of_values WHERE id = 246; -CREATE FUNCTION immutable_append(old_values int[], new_value int) -RETURNS int[] AS $$ SELECT old_values || new_value $$ LANGUAGE SQL IMMUTABLE; -\c - - - :worker_1_port -CREATE FUNCTION immutable_append(old_values int[], new_value int) -RETURNS int[] AS $$ SELECT old_values || new_value $$ LANGUAGE SQL IMMUTABLE; -\c - - - :worker_2_port -CREATE FUNCTION immutable_append(old_values int[], new_value int) -RETURNS int[] AS $$ SELECT old_values || new_value $$ LANGUAGE SQL IMMUTABLE; -\c - - - :master_port --- immutable function calls with vars are also allowed -UPDATE limit_orders -SET array_of_values = immutable_append(array_of_values, 2) WHERE id = 246; -CREATE FUNCTION stable_append(old_values int[], new_value int) -RETURNS int[] AS $$ BEGIN RETURN old_values || new_value; END; $$ -LANGUAGE plpgsql STABLE; --- but STABLE function calls with vars are not allowed -UPDATE limit_orders -SET array_of_values = stable_append(array_of_values, 3) WHERE id = 246; -ERROR: STABLE functions used in UPDATE queries cannot be called with column references -SELECT array_of_values FROM limit_orders WHERE id = 246; - array_of_values ------------------ - {1,2} -(1 row) - --- STRICT functions work as expected -CREATE FUNCTION temp_strict_func(integer,integer) RETURNS integer AS -'SELECT COALESCE($1, 2) + COALESCE($1, 3);' LANGUAGE SQL STABLE STRICT; -\set VERBOSITY terse -UPDATE limit_orders SET bidder_id = temp_strict_func(1, null) WHERE id = 246; -ERROR: null value in column "bidder_id" violates not-null constraint -\set VERBOSITY default -SELECT array_of_values FROM limit_orders WHERE id = 246; - array_of_values ------------------ - {1,2} -(1 row) - -ALTER TABLE limit_orders DROP array_of_values; --- even in RETURNING -UPDATE limit_orders SET placed_at = placed_at WHERE id = 246 RETURNING NOW(); -ERROR: non-IMMUTABLE functions are not allowed in the RETURNING clause --- check that multi-row UPDATE/DELETEs with RETURNING work -INSERT INTO multiple_hash VALUES ('0', '1'); -INSERT INTO multiple_hash VALUES ('0', '2'); -INSERT INTO multiple_hash VALUES ('0', '3'); -INSERT INTO multiple_hash VALUES ('0', '4'); -INSERT INTO multiple_hash VALUES ('0', '5'); -INSERT INTO multiple_hash VALUES ('0', '6'); -UPDATE multiple_hash SET data = data ||'-1' WHERE category = '0' RETURNING *; - category | data -----------+------ - 0 | 1-1 - 0 | 2-1 - 0 | 3-1 - 0 | 4-1 - 0 | 5-1 - 0 | 6-1 -(6 rows) - -DELETE FROM multiple_hash WHERE category = '0' RETURNING *; - category | data -----------+------ - 0 | 1-1 - 0 | 2-1 - 0 | 3-1 - 0 | 4-1 - 0 | 5-1 - 0 | 6-1 -(6 rows) - --- ensure returned row counters are correct -\set QUIET off -INSERT INTO multiple_hash VALUES ('1', '1'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('1', '2'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('1', '3'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('2', '1'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('2', '2'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('2', '3'); -INSERT 0 1 -INSERT INTO multiple_hash VALUES ('2', '3') RETURNING *; - category | data -----------+------ - 2 | 3 -(1 row) - -INSERT 0 1 --- check that update return the right number of rows --- one row -UPDATE multiple_hash SET data = data ||'-1' WHERE category = '1' AND data = '1'; -UPDATE 1 --- three rows -UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1'; -UPDATE 3 --- three rows, with RETURNING -UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1' RETURNING category; - category ----------- - 1 - 1 - 1 -(3 rows) - -UPDATE 3 --- check -SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data; - category | data -----------+--------- - 1 | 1-1-2-2 - 1 | 2-2-2 - 1 | 3-2-2 -(3 rows) - --- check that deletes return the right number of rows --- one row -DELETE FROM multiple_hash WHERE category = '2' AND data = '1'; -DELETE 1 --- two rows -DELETE FROM multiple_hash WHERE category = '2'; -DELETE 3 --- three rows, with RETURNING -DELETE FROM multiple_hash WHERE category = '1' RETURNING category; - category ----------- - 1 - 1 - 1 -(3 rows) - -DELETE 3 --- check -SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data; - category | data -----------+------ -(0 rows) - -SELECT * FROM multiple_hash WHERE category = '2' ORDER BY category, data; - category | data -----------+------ -(0 rows) - --- verify interaction of default values, SERIAL, and RETURNING -\set QUIET on -CREATE TABLE app_analytics_events (id serial, app_id integer, name text); -SET citus.shard_count TO 4; -SELECT create_distributed_table('app_analytics_events', 'app_id', 'hash'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO app_analytics_events VALUES (DEFAULT, 101, 'Fauxkemon Geaux') RETURNING id; - id ----- - 1 -(1 row) - -INSERT INTO app_analytics_events (app_id, name) VALUES (102, 'Wayz') RETURNING id; - id ----- - 2 -(1 row) - -INSERT INTO app_analytics_events (app_id, name) VALUES (103, 'Mynt') RETURNING *; - id | app_id | name -----+--------+------ - 3 | 103 | Mynt -(1 row) - -DROP TABLE app_analytics_events; --- again with serial in the partition column -CREATE TABLE app_analytics_events (id serial, app_id integer, name text); -SELECT create_distributed_table('app_analytics_events', 'id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO app_analytics_events VALUES (DEFAULT, 101, 'Fauxkemon Geaux') RETURNING id; - id ----- - 1 -(1 row) - -INSERT INTO app_analytics_events (app_id, name) VALUES (102, 'Wayz') RETURNING id; - id ----- - 2 -(1 row) - -INSERT INTO app_analytics_events (app_id, name) VALUES (103, 'Mynt') RETURNING *; - id | app_id | name -----+--------+------ - 3 | 103 | Mynt -(1 row) - --- Test multi-row insert with serial in the partition column -INSERT INTO app_analytics_events (app_id, name) -VALUES (104, 'Wayz'), (105, 'Mynt') RETURNING *; - id | app_id | name -----+--------+------ - 4 | 104 | Wayz - 5 | 105 | Mynt -(2 rows) - -INSERT INTO app_analytics_events (id, name) -VALUES (DEFAULT, 'Foo'), (300, 'Wah') RETURNING *; - id | app_id | name ------+--------+------ - 6 | | Foo - 300 | | Wah -(2 rows) - -PREPARE prep(varchar) AS -INSERT INTO app_analytics_events (id, name) -VALUES (DEFAULT, $1 || '.1'), (400 , $1 || '.2') RETURNING *; -EXECUTE prep('version-1'); - id | app_id | name ------+--------+------------- - 7 | | version-1.1 - 400 | | version-1.2 -(2 rows) - -EXECUTE prep('version-2'); - id | app_id | name ------+--------+------------- - 8 | | version-2.1 - 400 | | version-2.2 -(2 rows) - -EXECUTE prep('version-3'); - id | app_id | name ------+--------+------------- - 9 | | version-3.1 - 400 | | version-3.2 -(2 rows) - -EXECUTE prep('version-4'); - id | app_id | name ------+--------+------------- - 10 | | version-4.1 - 400 | | version-4.2 -(2 rows) - -EXECUTE prep('version-5'); - id | app_id | name ------+--------+------------- - 11 | | version-5.1 - 400 | | version-5.2 -(2 rows) - -EXECUTE prep('version-6'); - id | app_id | name ------+--------+------------- - 12 | | version-6.1 - 400 | | version-6.2 -(2 rows) - -SELECT * FROM app_analytics_events ORDER BY id, name; - id | app_id | name ------+--------+----------------- - 1 | 101 | Fauxkemon Geaux - 2 | 102 | Wayz - 3 | 103 | Mynt - 4 | 104 | Wayz - 5 | 105 | Mynt - 6 | | Foo - 7 | | version-1.1 - 8 | | version-2.1 - 9 | | version-3.1 - 10 | | version-4.1 - 11 | | version-5.1 - 12 | | version-6.1 - 300 | | Wah - 400 | | version-1.2 - 400 | | version-2.2 - 400 | | version-3.2 - 400 | | version-4.2 - 400 | | version-5.2 - 400 | | version-6.2 -(19 rows) - -TRUNCATE app_analytics_events; --- Test multi-row insert with a dropped column -ALTER TABLE app_analytics_events DROP COLUMN app_id; -INSERT INTO app_analytics_events (name) -VALUES ('Wayz'), ('Mynt') RETURNING *; - id | name -----+------ - 13 | Wayz - 14 | Mynt -(2 rows) - -SELECT * FROM app_analytics_events ORDER BY id; - id | name -----+------ - 13 | Wayz - 14 | Mynt -(2 rows) - -DROP TABLE app_analytics_events; --- Test multi-row insert with a dropped column before the partition column -CREATE TABLE app_analytics_events (id int default 3, app_id integer, name text); -SELECT create_distributed_table('app_analytics_events', 'name', colocate_with => 'none'); - create_distributed_table --------------------------- - -(1 row) - -ALTER TABLE app_analytics_events DROP COLUMN app_id; -INSERT INTO app_analytics_events (name) -VALUES ('Wayz'), ('Mynt') RETURNING *; - id | name -----+------ - 3 | Mynt - 3 | Wayz -(2 rows) - -SELECT * FROM app_analytics_events WHERE name = 'Wayz'; - id | name -----+------ - 3 | Wayz -(1 row) - -DROP TABLE app_analytics_events; --- Test multi-row insert with serial in a reference table -CREATE TABLE app_analytics_events (id serial, app_id integer, name text); -SELECT create_reference_table('app_analytics_events'); - create_reference_table ------------------------- - -(1 row) - -INSERT INTO app_analytics_events (app_id, name) -VALUES (104, 'Wayz'), (105, 'Mynt') RETURNING *; - id | app_id | name -----+--------+------ - 1 | 104 | Wayz - 2 | 105 | Mynt -(2 rows) - -SELECT * FROM app_analytics_events ORDER BY id; - id | app_id | name -----+--------+------ - 1 | 104 | Wayz - 2 | 105 | Mynt -(2 rows) - -DROP TABLE app_analytics_events; --- Test multi-row insert with serial in a non-partition column -CREATE TABLE app_analytics_events (id int, app_id serial, name text); -SELECT create_distributed_table('app_analytics_events', 'id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO app_analytics_events (id, name) -VALUES (99, 'Wayz'), (98, 'Mynt') RETURNING name, app_id; - name | app_id -------+-------- - Mynt | 2 - Wayz | 1 -(2 rows) - -SELECT * FROM app_analytics_events ORDER BY id; - id | app_id | name -----+--------+------ - 98 | 2 | Mynt - 99 | 1 | Wayz -(2 rows) - -DROP TABLE app_analytics_events; --- test UPDATE with subqueries -CREATE TABLE raw_table (id bigint, value bigint); -CREATE TABLE summary_table ( - id bigint, - min_value numeric, - average_value numeric, - count int, - uniques int); -SELECT create_distributed_table('raw_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('summary_table', 'id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO raw_table VALUES (1, 100); -INSERT INTO raw_table VALUES (1, 200); -INSERT INTO raw_table VALUES (1, 200); -INSERT INTO raw_table VALUES (1, 300); -INSERT INTO raw_table VALUES (2, 400); -INSERT INTO raw_table VALUES (2, 500); -INSERT INTO summary_table VALUES (1); -INSERT INTO summary_table VALUES (2); -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+---------------+-------+--------- - 1 | | | | - 2 | | | | -(2 rows) - -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 - ) average_query -WHERE id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | | 200.0000000000000000 | | - 2 | | | | -(2 rows) - --- try different syntax -UPDATE summary_table SET (min_value, average_value) = - (SELECT min(value), avg(value) FROM raw_table WHERE id = 2) -WHERE id = 2; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - -UPDATE summary_table SET min_value = 100 - WHERE id IN (SELECT id FROM raw_table WHERE id = 1 and value > 100) AND id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- indeed, we don't need filter on UPDATE explicitly if SELECT already prunes to one shard -UPDATE summary_table SET uniques = 2 - WHERE id IN (SELECT id FROM raw_table WHERE id = 1 and value IN (100, 200)); -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | | 2 - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- use inner results for non-partition column -UPDATE summary_table SET uniques = NULL - WHERE min_value IN (SELECT value FROM raw_table WHERE id = 1) AND id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- these should not update anything -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 AND id = 4 - ) average_query -WHERE id = 1 AND id = 4; -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 - ) average_query -WHERE id = 1 AND id = 4; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- update with NULL value -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 AND id = 4 - ) average_query -WHERE id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- multi-shard updates with recursively planned subqueries -BEGIN; -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table) average_query; -ROLLBACK; -BEGIN; -UPDATE summary_table SET average_value = average_value + 1 WHERE id = - (SELECT id FROM raw_table WHERE value > 100 LIMIT 1); -ROLLBACK; --- test complex queries -UPDATE summary_table -SET - uniques = metrics.expensive_uniques, - count = metrics.total_count -FROM - (SELECT - id, - count(DISTINCT (CASE WHEN value > 100 then value end)) AS expensive_uniques, - count(value) AS total_count - FROM raw_table - WHERE id = 1 - GROUP BY id) metrics -WHERE - summary_table.id = metrics.id AND - summary_table.id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | | 4 | 2 - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- test joins -UPDATE summary_table SET count = count + 1 FROM raw_table - WHERE raw_table.id = summary_table.id AND summary_table.id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | | 5 | 2 - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- test with prepared statements -PREPARE prepared_update_with_subquery(int, int) AS - UPDATE summary_table SET count = count + $1 FROM raw_table - WHERE raw_table.id = summary_table.id AND summary_table.id = $2; --- execute 6 times to trigger prepared statement usage -EXECUTE prepared_update_with_subquery(10, 1); -EXECUTE prepared_update_with_subquery(10, 1); -EXECUTE prepared_update_with_subquery(10, 1); -EXECUTE prepared_update_with_subquery(10, 1); -EXECUTE prepared_update_with_subquery(10, 1); -EXECUTE prepared_update_with_subquery(10, 1); -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | | 65 | 2 - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- test with reference tables -CREATE TABLE reference_raw_table (id bigint, value bigint); -CREATE TABLE reference_summary_table ( - id bigint, - min_value numeric, - average_value numeric, - count int, - uniques int); -SELECT create_reference_table('reference_raw_table'); - create_reference_table ------------------------- - -(1 row) - -SELECT create_reference_table('reference_summary_table'); - create_reference_table ------------------------- - -(1 row) - -INSERT INTO reference_raw_table VALUES (1, 100); -INSERT INTO reference_raw_table VALUES (1, 200); -INSERT INTO reference_raw_table VALUES (1, 200); -INSERT INTO reference_raw_table VALUES (1,300), (2, 400), (2,500) RETURNING *; - id | value -----+------- - 1 | 300 - 2 | 400 - 2 | 500 -(3 rows) - -INSERT INTO reference_summary_table VALUES (1); -INSERT INTO reference_summary_table VALUES (2); -SELECT * FROM reference_summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+---------------+-------+--------- - 1 | | | | - 2 | | | | -(2 rows) - -UPDATE reference_summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM reference_raw_table WHERE id = 1 - ) average_query -WHERE id = 1; -UPDATE reference_summary_table SET average_value = average_query.average_value FROM ( - SELECT average_value FROM summary_table WHERE id = 1 FOR UPDATE - ) average_query -WHERE id = 1; -ERROR: cannot perform select on a distributed table and modify a reference table -UPDATE reference_summary_table SET (min_value, average_value) = - (SELECT min(value), avg(value) FROM reference_raw_table WHERE id = 2) -WHERE id = 2; -SELECT * FROM reference_summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | | -(2 rows) - --- no need partition colum equalities on reference tables -UPDATE reference_summary_table SET (count) = - (SELECT id AS inner_id FROM reference_raw_table WHERE value = 500) -WHERE min_value = 400; -SELECT * FROM reference_summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | | 200.0000000000000000 | | - 2 | 400 | 450.0000000000000000 | 2 | -(2 rows) - --- can read from a reference table and update a distributed table -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM reference_raw_table WHERE id = 1 - ) average_query -WHERE id = 1; --- cannot read from a distributed table and update a reference table -UPDATE reference_summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 - ) average_query -WHERE id = 1; -ERROR: cannot perform select on a distributed table and modify a reference table -UPDATE reference_summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 1 AND id = 2 - ) average_query -WHERE id = 1; -ERROR: cannot perform select on a distributed table and modify a reference table --- test connection API via using COPY --- COPY on SELECT part -BEGIN; -\COPY raw_table FROM STDIN WITH CSV -INSERT INTO summary_table VALUES (3); -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 3 - ) average_query -WHERE id = 3; -COMMIT; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | 65 | 2 - 2 | 400 | 450.0000000000000000 | | - 3 | | 150.0000000000000000 | | -(3 rows) - --- COPY on UPDATE part -BEGIN; -INSERT INTO raw_table VALUES (4, 100); -INSERT INTO raw_table VALUES (4, 200); -\COPY summary_table FROM STDIN WITH CSV -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 4 - ) average_query -WHERE id = 4; -COMMIT; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | 65 | 2 - 2 | 400 | 450.0000000000000000 | | - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | -(4 rows) - --- COPY on both part -BEGIN; -\COPY raw_table FROM STDIN WITH CSV -\COPY summary_table FROM STDIN WITH CSV -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM raw_table WHERE id = 5 - ) average_query -WHERE id = 5; -COMMIT; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | 65 | 2 - 2 | 400 | 450.0000000000000000 | | - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | -(5 rows) - --- COPY on reference tables -BEGIN; -\COPY reference_raw_table FROM STDIN WITH CSV -\COPY summary_table FROM STDIN WITH CSV -UPDATE summary_table SET average_value = average_query.average FROM ( - SELECT avg(value) AS average FROM reference_raw_table WHERE id = 6 - ) average_query -WHERE id = 6; -COMMIT; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 1 | 100 | 200.0000000000000000 | 65 | 2 - 2 | 400 | 450.0000000000000000 | | - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | - 6 | | 150.0000000000000000 | | -(6 rows) - --- test DELETE queries -SELECT * FROM raw_table ORDER BY id, value; - id | value -----+------- - 1 | 100 - 1 | 200 - 1 | 200 - 1 | 300 - 2 | 400 - 2 | 500 - 3 | 100 - 3 | 200 - 4 | 100 - 4 | 200 - 5 | 100 - 5 | 200 -(12 rows) - -DELETE FROM summary_table - WHERE min_value IN (SELECT value FROM raw_table WHERE id = 1) AND id = 1; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 2 | 400 | 450.0000000000000000 | | - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | - 6 | | 150.0000000000000000 | | -(5 rows) - --- test with different syntax -DELETE FROM summary_table USING raw_table - WHERE summary_table.id = raw_table.id AND raw_table.id = 2; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | - 6 | | 150.0000000000000000 | | -(4 rows) - --- cannot read from a distributed table and delete from a reference table -DELETE FROM reference_summary_table USING raw_table - WHERE reference_summary_table.id = raw_table.id AND raw_table.id = 3; -ERROR: cannot perform select on a distributed table and modify a reference table -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | - 6 | | 150.0000000000000000 | | -(4 rows) - --- test connection API via using COPY with DELETEs -BEGIN; -\COPY summary_table FROM STDIN WITH CSV -DELETE FROM summary_table USING raw_table - WHERE summary_table.id = raw_table.id AND raw_table.id = 1; -DELETE FROM summary_table USING reference_raw_table - WHERE summary_table.id = reference_raw_table.id AND reference_raw_table.id = 2; -COMMIT; -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+----------------------+-------+--------- - 3 | | 150.0000000000000000 | | - 4 | | 150.0000000000000000 | | - 5 | | 150.0000000000000000 | | - 6 | | 150.0000000000000000 | | -(4 rows) - --- test DELETEs with prepared statements -PREPARE prepared_delete_with_join(int) AS - DELETE FROM summary_table USING raw_table - WHERE summary_table.id = raw_table.id AND raw_table.id = $1; -INSERT INTO raw_table VALUES (6, 100); --- execute 6 times to trigger prepared statement usage -EXECUTE prepared_delete_with_join(1); -EXECUTE prepared_delete_with_join(2); -EXECUTE prepared_delete_with_join(3); -EXECUTE prepared_delete_with_join(4); -EXECUTE prepared_delete_with_join(5); -EXECUTE prepared_delete_with_join(6); -SELECT * FROM summary_table ORDER BY id; - id | min_value | average_value | count | uniques -----+-----------+---------------+-------+--------- -(0 rows) - --- we don't support subqueries in VALUES clause -INSERT INTO summary_table (id) VALUES ((SELECT id FROM summary_table)); -ERROR: subqueries are not supported within INSERT queries -HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. -INSERT INTO summary_table (id) VALUES (5), ((SELECT id FROM summary_table)); -ERROR: subqueries are not supported within INSERT queries -HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. --- similar queries with reference tables -INSERT INTO reference_summary_table (id) VALUES ((SELECT id FROM summary_table)); -ERROR: subqueries are not supported within INSERT queries -HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. -INSERT INTO summary_table (id) VALUES ((SELECT id FROM reference_summary_table)); -ERROR: subqueries are not supported within INSERT queries -HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. -DROP TABLE raw_table; -DROP TABLE summary_table; -DROP TABLE reference_raw_table; -DROP TABLE reference_summary_table; diff --git a/src/test/regress/expected/multi_modifying_xacts.out b/src/test/regress/expected/multi_modifying_xacts.out index 9495941c7..cb6f1d756 100644 --- a/src/test/regress/expected/multi_modifying_xacts.out +++ b/src/test/regress/expected/multi_modifying_xacts.out @@ -433,7 +433,6 @@ SELECT lab_id FROM researchers WHERE lab_id = 2 AND id = 0; (0 rows) ALTER TABLE researchers ADD COLUMN motto text; -ERROR: cannot perform a parallel DDL command because multiple placements have been accessed over the same connection ROLLBACK; -- can perform sequential DDL once a connection is used for multiple shards BEGIN; @@ -528,14 +527,13 @@ FOR EACH ROW EXECUTE PROCEDURE reject_bad(); BEGIN; INSERT INTO objects VALUES (1, 'apple'); INSERT INTO objects VALUES (2, 'BAD'); -WARNING: illegal value +ERROR: illegal value COMMIT; -- so the data should noy be persisted SELECT * FROM objects WHERE id = 2; id | name ----+------ - 2 | BAD -(1 row) +(0 rows) SELECT * FROM labs WHERE id = 7; id | name @@ -553,7 +551,7 @@ AND sp.shardstate = 3 AND s.logicalrelid = 'objects'::regclass; count ------- - 1 + 0 (1 row) DELETE FROM objects; @@ -577,9 +575,11 @@ FOR EACH ROW EXECUTE PROCEDURE reject_bad(); BEGIN; INSERT INTO objects VALUES (1, 'apple'); INSERT INTO objects VALUES (2, 'BAD'); -INSERT INTO labs VALUES (8, 'Aperture Science'); -INSERT INTO labs VALUES (2, 'BAD'); ERROR: illegal value +INSERT INTO labs VALUES (8, 'Aperture Science'); +ERROR: current transaction is aborted, commands ignored until end of transaction block +INSERT INTO labs VALUES (2, 'BAD'); +ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- data should NOT be persisted SELECT * FROM objects WHERE id = 1; @@ -602,7 +602,7 @@ AND (s.logicalrelid = 'objects'::regclass OR s.logicalrelid = 'labs'::regclass); count ------- - 2 + 3 (1 row) -- what if the failures happen at COMMIT time? @@ -619,6 +619,8 @@ INSERT INTO objects VALUES (1, 'apple'); INSERT INTO objects VALUES (2, 'BAD'); INSERT INTO labs VALUES (9, 'Umbrella Corporation'); COMMIT; +WARNING: illegal value +WARNING: failed to commit transaction on localhost:57638 -- data should be persisted SELECT * FROM objects WHERE id = 2; id | name @@ -1308,8 +1310,7 @@ ALTER USER test_user RENAME TO test_user_new; \c - test_user - :master_port -- fails on all shard placements INSERT INTO numbers_hash_failure_test VALUES (2,2); -WARNING: connection error: localhost:57638 -ERROR: could not modify any active placements +ERROR: connection error: localhost:57638 -- connect back to the master with the proper user to continue the tests \c - :default_user - :master_port SET citus.next_shard_id TO 1200020; @@ -1436,7 +1437,6 @@ SELECT id FROM users WHERE id = 6; (1 row) ALTER TABLE items ADD COLUMN last_update timestamptz; -ERROR: cannot perform a parallel DDL command because multiple placements have been accessed over the same connection ROLLBACK; -- can perform sequential DDL after a co-located table has been read over 1 connection BEGIN; diff --git a/src/test/regress/expected/multi_modifying_xacts_9.out b/src/test/regress/expected/multi_modifying_xacts_9.out deleted file mode 100644 index cb6f1d756..000000000 --- a/src/test/regress/expected/multi_modifying_xacts_9.out +++ /dev/null @@ -1,1584 +0,0 @@ -SET citus.next_shard_id TO 1200000; -SET citus.next_placement_id TO 1200000; --- =================================================================== --- test end-to-end modification functionality --- =================================================================== -CREATE TABLE researchers ( - id bigint NOT NULL, - lab_id int NOT NULL, - name text NOT NULL -); -CREATE TABLE labs ( - id bigint NOT NULL, - name text NOT NULL -); -SELECT master_create_distributed_table('researchers', 'lab_id', 'hash'); - master_create_distributed_table ---------------------------------- - -(1 row) - -SELECT master_create_worker_shards('researchers', 2, 2); - master_create_worker_shards ------------------------------ - -(1 row) - -SELECT master_create_distributed_table('labs', 'id', 'hash'); - master_create_distributed_table ---------------------------------- - -(1 row) - -SELECT master_create_worker_shards('labs', 1, 1); - master_create_worker_shards ------------------------------ - -(1 row) - --- might be confusing to have two people in the same lab with the same name -CREATE UNIQUE INDEX avoid_name_confusion_idx ON researchers (lab_id, name); --- add some data -INSERT INTO researchers VALUES (1, 1, 'Donald Knuth'); -INSERT INTO researchers VALUES (2, 1, 'Niklaus Wirth'); -INSERT INTO researchers VALUES (3, 2, 'Tony Hoare'); -INSERT INTO researchers VALUES (4, 2, 'Kenneth Iverson'); --- replace a researcher, reusing their id in a multi-row INSERT -BEGIN; -DELETE FROM researchers WHERE lab_id = 1 AND id = 2; -INSERT INTO researchers VALUES (2, 1, 'John Backus'), (12, 1, 'Frances E. Allen'); -COMMIT; -SELECT name FROM researchers WHERE lab_id = 1 AND id % 10 = 2; - name ------------------- - John Backus - Frances E. Allen -(2 rows) - --- and the other way around -BEGIN; -INSERT INTO researchers VALUES (14, 2, 'Alan Kay'), (15, 2, 'Barbara Liskov'); -DELETE FROM researchers WHERE id = 14 AND lab_id = 2; -ROLLBACK; --- should have rolled everything back -SELECT * FROM researchers WHERE id = 15 AND lab_id = 2; - id | lab_id | name -----+--------+------ -(0 rows) - --- abort a modification -BEGIN; -DELETE FROM researchers WHERE lab_id = 1 AND id = 1; -ABORT; -SELECT name FROM researchers WHERE lab_id = 1 AND id = 1; - name --------------- - Donald Knuth -(1 row) - --- trigger a unique constraint violation -BEGIN; -\set VERBOSITY TERSE -UPDATE researchers SET name = 'John Backus' WHERE id = 1 AND lab_id = 1; -ERROR: duplicate key value violates unique constraint "avoid_name_confusion_idx_1200000" -\set VERBOSITY DEFAULT -ABORT; --- creating savepoints should work... -BEGIN; -INSERT INTO researchers VALUES (5, 3, 'Dennis Ritchie'); -SAVEPOINT hire_thompson; -INSERT INTO researchers VALUES (6, 3, 'Ken Thompson'); -COMMIT; -SELECT name FROM researchers WHERE lab_id = 3 AND id = 6; - name --------------- - Ken Thompson -(1 row) - --- even if created by PL/pgSQL... -\set VERBOSITY terse -BEGIN; -DO $$ -BEGIN - INSERT INTO researchers VALUES (10, 10, 'Edsger Dijkstra'); -EXCEPTION - WHEN not_null_violation THEN - RAISE NOTICE 'caught not_null_violation'; -END $$; -COMMIT; --- rollback should also work -BEGIN; -INSERT INTO researchers VALUES (7, 4, 'Jim Gray'); -SAVEPOINT hire_engelbart; -INSERT INTO researchers VALUES (8, 4, 'Douglas Engelbart'); -ROLLBACK TO hire_engelbart; -COMMIT; -SELECT name FROM researchers WHERE lab_id = 4; - name ----------- - Jim Gray -(1 row) - -BEGIN; -DO $$ -BEGIN - INSERT INTO researchers VALUES (11, 11, 'Whitfield Diffie'); - INSERT INTO researchers VALUES (NULL, 10, 'Edsger Dijkstra'); -EXCEPTION - WHEN not_null_violation THEN - RAISE NOTICE 'caught not_null_violation'; -END $$; -NOTICE: caught not_null_violation -COMMIT; -\set VERBOSITY default --- should be valid to edit labs after researchers... -BEGIN; -INSERT INTO researchers VALUES (8, 5, 'Douglas Engelbart'); -INSERT INTO labs VALUES (5, 'Los Alamos'); -COMMIT; -SELECT * FROM researchers, labs WHERE labs.id = researchers.lab_id AND researchers.lab_id = 5; - id | lab_id | name | id | name -----+--------+-------------------+----+------------ - 8 | 5 | Douglas Engelbart | 5 | Los Alamos -(1 row) - --- and the other way around is also allowed -BEGIN; -INSERT INTO labs VALUES (6, 'Bell Labs'); -INSERT INTO researchers VALUES (9, 6, 'Leslie Lamport'); -COMMIT; --- we should be able to expand the transaction participants -BEGIN; -INSERT INTO labs VALUES (6, 'Bell Labs'); -INSERT INTO researchers VALUES (9, 6, 'Leslie Lamport'); -ERROR: duplicate key value violates unique constraint "avoid_name_confusion_idx_1200001" -DETAIL: Key (lab_id, name)=(6, Leslie Lamport) already exists. -CONTEXT: while executing command on localhost:57638 -ABORT; --- SELECTs may occur after a modification: First check that selecting --- from the modified node works. -BEGIN; -INSERT INTO labs VALUES (6, 'Bell Labs'); -SELECT count(*) FROM researchers WHERE lab_id = 6; - count -------- - 1 -(1 row) - -ABORT; --- then check that SELECT going to new node still is fine -BEGIN; -UPDATE pg_dist_shard_placement AS sp SET shardstate = 3 -FROM pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.nodename = 'localhost' -AND sp.nodeport = :worker_1_port -AND s.logicalrelid = 'researchers'::regclass; -INSERT INTO labs VALUES (6, 'Bell Labs'); -SELECT count(*) FROM researchers WHERE lab_id = 6; - count -------- - 1 -(1 row) - -ABORT; --- we can mix DDL and INSERT -BEGIN; -INSERT INTO labs VALUES (6, 'Bell Labs'); -ALTER TABLE labs ADD COLUMN motto text; -ABORT; --- whether it occurs first or second -BEGIN; -ALTER TABLE labs ADD COLUMN motto text; -INSERT INTO labs VALUES (6, 'Bell Labs'); -ABORT; --- this should work find with sequential DDL as well -BEGIN; -SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; -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; - Column | Type | Modifiers ---------+--------+----------- - id | bigint | not null - name | text | not null -(2 rows) - -SELECT * FROM labs WHERE id = 6; - id | name -----+----------- - 6 | Bell Labs -(1 row) - --- COPY can happen after single row INSERT -BEGIN; -INSERT INTO labs VALUES (6, 'Bell Labs'); -\copy labs from stdin delimiter ',' -COMMIT; --- COPY can be performed if multiple shards were modified over the same connection -BEGIN; -INSERT INTO researchers VALUES (2, 1, 'Knuth Donald'); -INSERT INTO researchers VALUES (10, 6, 'Lamport Leslie'); -\copy researchers from stdin delimiter ',' -ROLLBACK; --- COPY can be performed after a multi-row INSERT that uses one connection -BEGIN; -INSERT INTO researchers VALUES (2, 1, 'Knuth Donald'), (10, 6, 'Lamport Leslie'); -\copy researchers from stdin delimiter ',' -ROLLBACK; --- after a COPY you can modify multiple shards, since they'll use different connections -BEGIN; -\copy researchers from stdin delimiter ',' -INSERT INTO researchers VALUES (2, 1, 'Knuth Donald'); -INSERT INTO researchers VALUES (10, 6, 'Lamport Leslie'); -ROLLBACK; --- after a COPY you can perform a multi-row INSERT -BEGIN; -\copy researchers from stdin delimiter ',' -INSERT INTO researchers VALUES (2, 1, 'Knuth Donald'), (10, 6, 'Lamport Leslie'); -ROLLBACK; --- COPY can happen before single row INSERT -BEGIN; -\copy labs from stdin delimiter ',' -SELECT name FROM labs WHERE id = 10; - name ----------------- - Weyland-Yutani - Weyland-Yutani -(2 rows) - -INSERT INTO labs VALUES (6, 'Bell Labs'); -COMMIT; --- two consecutive COPYs in a transaction are allowed -BEGIN; -\copy labs from stdin delimiter ',' -\copy labs from stdin delimiter ',' -COMMIT; -SELECT name FROM labs WHERE id = 11 OR id = 12 ORDER BY id; - name ----------------- - Planet Express - fsociety -(2 rows) - --- 1pc failure test -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - --- copy with unique index violation -BEGIN; -\copy researchers FROM STDIN delimiter ',' -\copy researchers FROM STDIN delimiter ',' -ERROR: duplicate key value violates unique constraint "avoid_name_confusion_idx_1200001" -DETAIL: Key (lab_id, name)=(6, 'Bjarne Stroustrup') already exists. -COMMIT; --- verify rollback -SELECT * FROM researchers WHERE lab_id = 6; - id | lab_id | name -----+--------+---------------- - 9 | 6 | Leslie Lamport -(1 row) - -SELECT count(*) FROM pg_dist_transaction; - count -------- - 0 -(1 row) - --- 2pc failure and success tests -SET citus.multi_shard_commit_protocol TO '2pc'; -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - --- copy with unique index violation -BEGIN; -\copy researchers FROM STDIN delimiter ',' -\copy researchers FROM STDIN delimiter ',' -ERROR: duplicate key value violates unique constraint "avoid_name_confusion_idx_1200001" -DETAIL: Key (lab_id, name)=(6, 'Bjarne Stroustrup') already exists. -COMMIT; --- verify rollback -SELECT * FROM researchers WHERE lab_id = 6; - id | lab_id | name -----+--------+---------------- - 9 | 6 | Leslie Lamport -(1 row) - -SELECT count(*) FROM pg_dist_transaction; - count -------- - 0 -(1 row) - -BEGIN; -\copy researchers FROM STDIN delimiter ',' -\copy researchers FROM STDIN delimiter ',' -COMMIT; --- verify success -SELECT * FROM researchers WHERE lab_id = 6; - id | lab_id | name -----+--------+---------------------- - 9 | 6 | Leslie Lamport - 17 | 6 | 'Bjarne Stroustrup' - 18 | 6 | 'Dennis Ritchie' -(3 rows) - --- verify 2pc -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - -RESET citus.multi_shard_commit_protocol; --- create a check function -SELECT * from run_command_on_workers('CREATE FUNCTION reject_large_id() RETURNS trigger AS $rli$ - BEGIN - IF (NEW.id > 30) THEN - RAISE ''illegal value''; - END IF; - - RETURN NEW; - END; -$rli$ LANGUAGE plpgsql;') -ORDER BY nodeport; - nodename | nodeport | success | result ------------+----------+---------+----------------- - localhost | 57637 | t | CREATE FUNCTION - localhost | 57638 | t | CREATE FUNCTION -(2 rows) - --- 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()') -ORDER BY nodeport, shardid; - nodename | nodeport | shardid | success | result ------------+----------+---------+---------+---------------- - localhost | 57637 | 1200000 | t | CREATE TRIGGER - localhost | 57637 | 1200001 | t | CREATE TRIGGER - localhost | 57638 | 1200000 | t | CREATE TRIGGER - localhost | 57638 | 1200001 | t | CREATE TRIGGER -(4 rows) - --- hide postgresql version dependend messages for next test only -\set VERBOSITY terse --- deferred check should abort the transaction -BEGIN; -SET LOCAL citus.multi_shard_commit_protocol TO '1pc'; -DELETE FROM researchers WHERE lab_id = 6; -\copy researchers FROM STDIN delimiter ',' -\copy researchers FROM STDIN delimiter ',' -COMMIT; -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57638 -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57637 -WARNING: could not commit transaction for shard 1200001 on any active node -ERROR: could not commit transaction on any active node -\unset VERBOSITY --- verify everyhing including delete is rolled back -SELECT * FROM researchers WHERE lab_id = 6; - id | lab_id | name -----+--------+---------------------- - 9 | 6 | Leslie Lamport - 17 | 6 | 'Bjarne Stroustrup' - 18 | 6 | 'Dennis Ritchie' -(3 rows) - --- cleanup triggers and the function -SELECT * from run_command_on_placements('researchers', 'drop trigger reject_large_researcher_id on %s') -ORDER BY nodeport, shardid; - nodename | nodeport | shardid | success | result ------------+----------+---------+---------+-------------- - localhost | 57637 | 1200000 | t | DROP TRIGGER - localhost | 57637 | 1200001 | t | DROP TRIGGER - localhost | 57638 | 1200000 | t | DROP TRIGGER - localhost | 57638 | 1200001 | t | DROP TRIGGER -(4 rows) - -SELECT * FROM run_command_on_workers('drop function reject_large_id()') -ORDER BY nodeport; - nodename | nodeport | success | result ------------+----------+---------+--------------- - localhost | 57637 | t | DROP FUNCTION - localhost | 57638 | t | DROP FUNCTION -(2 rows) - --- ALTER and copy are compatible -BEGIN; -ALTER TABLE labs ADD COLUMN motto text; -\copy labs from stdin delimiter ',' -ROLLBACK; -BEGIN; -\copy labs from stdin delimiter ',' -ALTER TABLE labs ADD COLUMN motto text; -ABORT; --- can perform parallel DDL even a connection is used for multiple shards -BEGIN; -SELECT lab_id FROM researchers WHERE lab_id = 1 AND id = 0; - lab_id --------- -(0 rows) - -SELECT lab_id FROM researchers WHERE lab_id = 2 AND id = 0; - lab_id --------- -(0 rows) - -ALTER TABLE researchers ADD COLUMN motto text; -ROLLBACK; --- can perform sequential DDL once a connection is used for multiple shards -BEGIN; -SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; -SELECT lab_id FROM researchers WHERE lab_id = 1 AND id = 0; - lab_id --------- -(0 rows) - -SELECT lab_id FROM researchers WHERE lab_id = 2 AND id = 0; - lab_id --------- -(0 rows) - -ALTER TABLE researchers ADD COLUMN motto text; -ROLLBACK; --- multi-shard operations can co-exist with DDL in a transactional way -BEGIN; -ALTER TABLE labs ADD COLUMN motto text; -DELETE FROM labs; -ALTER TABLE labs ADD COLUMN score float; -ROLLBACK; --- should have rolled everything back -SELECT * FROM labs WHERE id = 12; - id | name -----+---------- - 12 | fsociety -(1 row) - --- now, for some special failures... -CREATE TABLE objects ( - id bigint PRIMARY KEY, - name text NOT NULL -); -SELECT master_create_distributed_table('objects', 'id', 'hash'); - master_create_distributed_table ---------------------------------- - -(1 row) - -SELECT master_create_worker_shards('objects', 1, 2); - master_create_worker_shards ------------------------------ - -(1 row) - --- test primary key violations -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO objects VALUES (1, 'orange'); -ERROR: duplicate key value violates unique constraint "objects_pkey_1200003" -DETAIL: Key (id)=(1) already exists. -CONTEXT: while executing command on localhost:57637 -COMMIT; --- data shouldn't have persisted... -SELECT * FROM objects WHERE id = 1; - id | name -----+------ -(0 rows) - --- and placements should still be healthy... -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.shardstate = 1 -AND s.logicalrelid = 'objects'::regclass; - count -------- - 2 -(1 row) - --- create trigger on one worker to reject certain values -\c - - - :worker_2_port -CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ - BEGIN - IF (NEW.name = 'BAD') THEN - RAISE 'illegal value'; - END IF; - - RETURN NEW; - END; -$rb$ LANGUAGE plpgsql; -CREATE CONSTRAINT TRIGGER reject_bad -AFTER INSERT ON objects_1200003 -DEFERRABLE INITIALLY IMMEDIATE -FOR EACH ROW EXECUTE PROCEDURE reject_bad(); -\c - - - :master_port --- test partial failure; worker_1 succeeds, 2 fails --- in this case, we expect the transaction to abort -\set VERBOSITY terse -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO objects VALUES (2, 'BAD'); -ERROR: illegal value -COMMIT; --- so the data should noy be persisted -SELECT * FROM objects WHERE id = 2; - id | name -----+------ -(0 rows) - -SELECT * FROM labs WHERE id = 7; - id | name -----+------ -(0 rows) - --- and none of placements should be inactive -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.nodename = 'localhost' -AND sp.nodeport = :worker_2_port -AND sp.shardstate = 3 -AND s.logicalrelid = 'objects'::regclass; - count -------- - 0 -(1 row) - -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 -CREATE FUNCTION reject_bad() RETURNS trigger AS $rb$ - BEGIN - IF (NEW.name = 'BAD') THEN - RAISE 'illegal value'; - END IF; - - RETURN NEW; - END; -$rb$ LANGUAGE plpgsql; -CREATE CONSTRAINT TRIGGER reject_bad -AFTER INSERT ON labs_1200002 -DEFERRABLE INITIALLY IMMEDIATE -FOR EACH ROW EXECUTE PROCEDURE reject_bad(); -\c - - - :master_port -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO objects VALUES (2, 'BAD'); -ERROR: illegal value -INSERT INTO labs VALUES (8, 'Aperture Science'); -ERROR: current transaction is aborted, commands ignored until end of transaction block -INSERT INTO labs VALUES (2, 'BAD'); -ERROR: current transaction is aborted, commands ignored until end of transaction block -COMMIT; --- data should NOT be persisted -SELECT * FROM objects WHERE id = 1; - id | name -----+------ -(0 rows) - -SELECT * FROM labs WHERE id = 8; - id | name -----+------ -(0 rows) - --- all placements should remain healthy -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.shardstate = 1 -AND (s.logicalrelid = 'objects'::regclass OR - s.logicalrelid = 'labs'::regclass); - count -------- - 3 -(1 row) - --- what if the failures happen at COMMIT time? -\c - - - :worker_2_port -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 --- should be the same story as before, just at COMMIT time -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO objects VALUES (2, 'BAD'); -INSERT INTO labs VALUES (9, 'Umbrella Corporation'); -COMMIT; -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57638 --- data should be persisted -SELECT * FROM objects WHERE id = 2; - id | name -----+------ - 2 | BAD -(1 row) - --- but one placement should be bad -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.nodename = 'localhost' -AND sp.nodeport = :worker_2_port -AND sp.shardstate = 3 -AND s.logicalrelid = 'objects'::regclass; - count -------- - 1 -(1 row) - -DELETE FROM objects; --- mark shards as healthy again; delete all data -UPDATE pg_dist_shard_placement AS sp SET shardstate = 1 -FROM pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND s.logicalrelid = 'objects'::regclass; --- what if all nodes have failures at COMMIT time? -\c - - - :worker_1_port -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 -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO objects VALUES (2, 'BAD'); -INSERT INTO labs VALUES (8, 'Aperture Science'); -INSERT INTO labs VALUES (9, 'BAD'); -COMMIT; -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57637 -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57638 -WARNING: could not commit transaction for shard 1200002 on any active node -WARNING: could not commit transaction for shard 1200003 on any active node -ERROR: could not commit transaction on any active node --- data should NOT be persisted -SELECT * FROM objects WHERE id = 1; - id | name -----+------ -(0 rows) - -SELECT * FROM labs WHERE id = 8; - id | name -----+------ -(0 rows) - --- all placements should remain healthy -SELECT count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND sp.shardstate = 1 -AND (s.logicalrelid = 'objects'::regclass OR - s.logicalrelid = 'labs'::regclass); - count -------- - 3 -(1 row) - --- what if one shard (objects) succeeds but another (labs) completely fails? -\c - - - :worker_2_port -DROP TRIGGER reject_bad ON objects_1200003; -\c - - - :master_port -SET citus.next_shard_id TO 1200004; -BEGIN; -INSERT INTO objects VALUES (1, 'apple'); -INSERT INTO labs VALUES (8, 'Aperture Science'); -INSERT INTO labs VALUES (9, 'BAD'); -COMMIT; -WARNING: illegal value -WARNING: failed to commit transaction on localhost:57637 -WARNING: could not commit transaction for shard 1200002 on any active node -\set VERBOSITY default --- data to objects should be persisted, but labs should not... -SELECT * FROM objects WHERE id = 1; - id | name -----+------- - 1 | apple -(1 row) - -SELECT * FROM labs WHERE id = 8; - id | name -----+------ -(0 rows) - --- labs should be healthy, but one object placement shouldn't be -SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND (s.logicalrelid = 'objects'::regclass OR - s.logicalrelid = 'labs'::regclass) -GROUP BY s.logicalrelid, sp.shardstate -ORDER BY s.logicalrelid, sp.shardstate; - logicalrelid | shardstate | count ---------------+------------+------- - labs | 1 | 1 - objects | 1 | 1 - objects | 3 | 1 -(3 rows) - --- some append-partitioned tests for good measure -CREATE TABLE append_researchers ( LIKE researchers ); -SELECT master_create_distributed_table('append_researchers', 'id', 'append'); - master_create_distributed_table ---------------------------------- - -(1 row) - -SET citus.shard_replication_factor TO 1; -SELECT master_create_empty_shard('append_researchers') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 0, shardmaxvalue = 500000 -WHERE shardid = :new_shard_id; -SELECT master_create_empty_shard('append_researchers') AS new_shard_id -\gset -UPDATE pg_dist_shard SET shardminvalue = 500000, shardmaxvalue = 1000000 -WHERE shardid = :new_shard_id; -SET citus.shard_replication_factor TO DEFAULT; --- try single-shard INSERT -BEGIN; -INSERT INTO append_researchers VALUES (0, 0, 'John Backus'); -COMMIT; -SELECT * FROM append_researchers WHERE id = 0; - id | lab_id | name -----+--------+------------- - 0 | 0 | John Backus -(1 row) - --- try rollback -BEGIN; -DELETE FROM append_researchers WHERE id = 0; -ROLLBACK; -SELECT * FROM append_researchers WHERE id = 0; - id | lab_id | name -----+--------+------------- - 0 | 0 | John Backus -(1 row) - --- try hitting shard on other node -BEGIN; -INSERT INTO append_researchers VALUES (1, 1, 'John McCarthy'); -INSERT INTO append_researchers VALUES (500000, 500000, 'Tony Hoare'); -ERROR: cannot run INSERT command which targets multiple shards -HINT: Make sure the value for partition column "id" falls into a single shard. -ROLLBACK; -SELECT * FROM append_researchers; - id | lab_id | name -----+--------+------------- - 0 | 0 | John Backus -(1 row) - --- we use 2PC for reference tables by default --- let's add some tests for them -CREATE TABLE reference_modifying_xacts (key int, value int); -SELECT create_reference_table('reference_modifying_xacts'); - create_reference_table ------------------------- - -(1 row) - --- very basic test, ensure that INSERTs work -INSERT INTO reference_modifying_xacts VALUES (1, 1); -SELECT * FROM reference_modifying_xacts; - key | value ------+------- - 1 | 1 -(1 row) - --- now ensure that it works in a transaction as well -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (2, 2); -SELECT * FROM reference_modifying_xacts; - key | value ------+------- - 1 | 1 - 2 | 2 -(2 rows) - -COMMIT; --- we should be able to see the insert outside of the transaction as well -SELECT * FROM reference_modifying_xacts; - key | value ------+------- - 1 | 1 - 2 | 2 -(2 rows) - --- rollback should also work -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (3, 3); -SELECT * FROM reference_modifying_xacts; - key | value ------+------- - 1 | 1 - 2 | 2 - 3 | 3 -(3 rows) - -ROLLBACK; --- see that we've not inserted -SELECT * FROM reference_modifying_xacts; - key | value ------+------- - 1 | 1 - 2 | 2 -(2 rows) - --- lets fail on of the workers at before the commit time -\c - - - :worker_1_port -CREATE FUNCTION reject_bad_reference() RETURNS trigger AS $rb$ - BEGIN - IF (NEW.key = 999) THEN - RAISE 'illegal value'; - END IF; - - RETURN NEW; - END; -$rb$ LANGUAGE plpgsql; -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 VERBOSITY terse --- try without wrapping inside a transaction -INSERT INTO reference_modifying_xacts VALUES (999, 3); -ERROR: illegal value --- same test within a transaction -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (999, 3); -ERROR: illegal value -COMMIT; --- lets fail one of the workers at COMMIT time -\c - - - :worker_1_port -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 VERBOSITY terse --- try without wrapping inside a transaction -INSERT INTO reference_modifying_xacts VALUES (999, 3); -ERROR: illegal value --- same test within a transaction -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (999, 3); -COMMIT; -ERROR: illegal value --- all placements should be healthy -SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND s.logicalrelid = 'reference_modifying_xacts'::regclass -GROUP BY s.logicalrelid, sp.shardstate -ORDER BY s.logicalrelid, sp.shardstate; - logicalrelid | shardstate | count ----------------------------+------------+------- - reference_modifying_xacts | 1 | 2 -(1 row) - --- for the time-being drop the constraint -\c - - - :worker_1_port -DROP TRIGGER reject_bad_reference ON reference_modifying_xacts_1200006; -\c - - - :master_port --- now create a hash distributed table and run tests --- including both the reference table and the hash --- distributed table --- To prevent colocating a hash table with append table -DELETE FROM pg_dist_colocation WHERE colocationid = 100001; -SET citus.next_shard_id TO 1200007; -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 1; -CREATE TABLE hash_modifying_xacts (key int, value int); -SELECT create_distributed_table('hash_modifying_xacts', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- let's try to expand the xact participants -BEGIN; -INSERT INTO hash_modifying_xacts VALUES (1, 1); -INSERT INTO reference_modifying_xacts VALUES (10, 10); -COMMIT; --- it is allowed when turning off deadlock prevention -BEGIN; -INSERT INTO hash_modifying_xacts VALUES (1, 1); -INSERT INTO reference_modifying_xacts VALUES (10, 10); -ABORT; -BEGIN; -INSERT INTO hash_modifying_xacts VALUES (1, 1); -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 -CREATE FUNCTION reject_bad_hash() RETURNS trigger AS $rb$ - BEGIN - IF (NEW.key = 997) THEN - RAISE 'illegal value'; - END IF; - - RETURN NEW; - END; -$rb$ LANGUAGE plpgsql; -CREATE CONSTRAINT TRIGGER reject_bad_hash -AFTER INSERT ON hash_modifying_xacts_1200007 -DEFERRABLE INITIALLY IMMEDIATE -FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); -\c - - - :master_port -\set VERBOSITY terse --- the transaction as a whole should fail -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (55, 10); -INSERT INTO hash_modifying_xacts VALUES (997, 1); -ERROR: illegal value -COMMIT; --- ensure that the value didn't go into the reference table -SELECT * FROM reference_modifying_xacts WHERE key = 55; - key | value ------+------- -(0 rows) - --- now lets fail on of the workers for the hash distributed table table --- when there is a reference table involved -\c - - - :worker_1_port -DROP TRIGGER reject_bad_hash ON hash_modifying_xacts_1200007; --- the trigger is on execution time -CREATE CONSTRAINT TRIGGER reject_bad_hash -AFTER INSERT ON hash_modifying_xacts_1200007 -DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE reject_bad_hash(); -\c - - - :master_port -\set VERBOSITY terse --- the transaction as a whole should fail -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (12, 12); -INSERT INTO hash_modifying_xacts VALUES (997, 1); -COMMIT; -ERROR: illegal value --- ensure that the values didn't go into the reference table -SELECT * FROM reference_modifying_xacts WHERE key = 12; - key | value ------+------- -(0 rows) - --- all placements should be healthy -SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR - s.logicalrelid = 'hash_modifying_xacts'::regclass) -GROUP BY s.logicalrelid, sp.shardstate -ORDER BY s.logicalrelid, sp.shardstate; - logicalrelid | shardstate | count ----------------------------+------------+------- - reference_modifying_xacts | 1 | 2 - hash_modifying_xacts | 1 | 4 -(2 rows) - --- now, fail the insert on reference table --- and ensure that hash distributed table's --- change is rollbacked as well -\c - - - :worker_1_port -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 VERBOSITY terse -BEGIN; --- to expand participant to include all worker nodes -INSERT INTO reference_modifying_xacts VALUES (66, 3); -INSERT INTO hash_modifying_xacts VALUES (80, 1); -INSERT INTO reference_modifying_xacts VALUES (999, 3); -ERROR: illegal value -COMMIT; -SELECT * FROM hash_modifying_xacts WHERE key = 80; - key | value ------+------- -(0 rows) - -SELECT * FROM reference_modifying_xacts WHERE key = 66; - key | value ------+------- -(0 rows) - -SELECT * FROM reference_modifying_xacts WHERE key = 999; - key | value ------+------- -(0 rows) - --- all placements should be healthy -SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR - s.logicalrelid = 'hash_modifying_xacts'::regclass) -GROUP BY s.logicalrelid, sp.shardstate -ORDER BY s.logicalrelid, sp.shardstate; - logicalrelid | shardstate | count ----------------------------+------------+------- - reference_modifying_xacts | 1 | 2 - hash_modifying_xacts | 1 | 4 -(2 rows) - --- now show that all modifications to reference --- tables are done in 2PC -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -INSERT INTO reference_modifying_xacts VALUES (70, 70); -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - --- reset the transactions table -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -BEGIN; -INSERT INTO reference_modifying_xacts VALUES (71, 71); -COMMIT; -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - --- create a hash distributed tablw which spans all nodes -SET citus.shard_count = 4; -SET citus.shard_replication_factor = 2; -CREATE TABLE hash_modifying_xacts_second (key int, value int); -SELECT create_distributed_table('hash_modifying_xacts_second', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- reset the transactions table -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -BEGIN; -INSERT INTO hash_modifying_xacts_second VALUES (72, 1); -INSERT INTO reference_modifying_xacts VALUES (72, 3); -COMMIT; -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - --- reset the transactions table -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -DELETE FROM reference_modifying_xacts; -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - --- reset the transactions table -SELECT recover_prepared_transactions(); - recover_prepared_transactions -------------------------------- - 0 -(1 row) - -UPDATE reference_modifying_xacts SET key = 10; -SELECT count(*) FROM pg_dist_transaction; - count -------- - 2 -(1 row) - --- now to one more type of failure testing --- in which we'll make the remote host unavailable --- first create the new user on all nodes -CREATE USER test_user; -NOTICE: not propagating CREATE ROLE/USER commands to worker nodes -\c - - - :worker_1_port -CREATE USER test_user; -NOTICE: not propagating CREATE ROLE/USER commands to worker nodes -\c - - - :worker_2_port -CREATE USER test_user; -NOTICE: not propagating CREATE ROLE/USER commands to worker nodes --- now connect back to the master with the new user -\c - test_user - :master_port -SET citus.next_shard_id TO 1200015; -CREATE TABLE reference_failure_test (key int, value int); -SELECT create_reference_table('reference_failure_test'); - create_reference_table ------------------------- - -(1 row) - --- create a hash distributed table -SET citus.shard_count TO 4; -CREATE TABLE numbers_hash_failure_test(key int, value int); -SELECT create_distributed_table('numbers_hash_failure_test', 'key'); - create_distributed_table --------------------------- - -(1 row) - --- ensure that the shard is created for this user -\c - test_user - :worker_1_port -\dt reference_failure_test_1200015 - List of relations - Schema | Name | Type | Owner ---------+--------------------------------+-------+----------- - public | 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 -ALTER USER test_user RENAME TO test_user_new; --- connect back to master and query the reference table - \c - test_user - :master_port --- should fail since the worker doesn't have test_user anymore -INSERT INTO reference_failure_test VALUES (1, '1'); -ERROR: connection error: localhost:57637 --- the same as the above, but wrapped within a transaction -BEGIN; -INSERT INTO reference_failure_test VALUES (1, '1'); -ERROR: connection error: localhost:57637 -COMMIT; -BEGIN; -COPY reference_failure_test FROM STDIN WITH (FORMAT 'csv'); -ERROR: connection error: localhost:57637 -COMMIT; --- show that no data go through the table and shard states are good -SET client_min_messages to 'ERROR'; -SELECT * FROM reference_failure_test; - key | value ------+------- -(0 rows) - -RESET client_min_messages; --- all placements should be healthy -SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) -FROM pg_dist_shard_placement AS sp, - pg_dist_shard AS s -WHERE sp.shardid = s.shardid -AND s.logicalrelid = 'reference_failure_test'::regclass -GROUP BY s.logicalrelid, sp.shardstate -ORDER BY s.logicalrelid, sp.shardstate; - logicalrelid | shardstate | count -------------------------+------------+------- - reference_failure_test | 1 | 2 -(1 row) - -BEGIN; -COPY numbers_hash_failure_test FROM STDIN WITH (FORMAT 'csv'); -WARNING: connection error: localhost:57637 -WARNING: connection error: localhost:57637 --- some placements are invalid before abort -SELECT shardid, shardstate, nodename, nodeport -FROM pg_dist_shard_placement JOIN pg_dist_shard USING (shardid) -WHERE logicalrelid = 'numbers_hash_failure_test'::regclass -ORDER BY shardid, nodeport; - shardid | shardstate | nodename | nodeport ----------+------------+-----------+---------- - 1200016 | 3 | localhost | 57637 - 1200016 | 1 | localhost | 57638 - 1200017 | 1 | localhost | 57637 - 1200017 | 1 | localhost | 57638 - 1200018 | 1 | localhost | 57637 - 1200018 | 1 | localhost | 57638 - 1200019 | 3 | localhost | 57637 - 1200019 | 1 | localhost | 57638 -(8 rows) - -ABORT; --- verify nothing is inserted -SELECT count(*) FROM numbers_hash_failure_test; -WARNING: connection error: localhost:57637 -WARNING: connection error: localhost:57637 - count -------- - 0 -(1 row) - --- all placements to be market valid -SELECT shardid, shardstate, nodename, nodeport -FROM pg_dist_shard_placement JOIN pg_dist_shard USING (shardid) -WHERE logicalrelid = 'numbers_hash_failure_test'::regclass -ORDER BY shardid, nodeport; - shardid | shardstate | nodename | nodeport ----------+------------+-----------+---------- - 1200016 | 1 | localhost | 57637 - 1200016 | 1 | localhost | 57638 - 1200017 | 1 | localhost | 57637 - 1200017 | 1 | localhost | 57638 - 1200018 | 1 | localhost | 57637 - 1200018 | 1 | localhost | 57638 - 1200019 | 1 | localhost | 57637 - 1200019 | 1 | localhost | 57638 -(8 rows) - -BEGIN; -COPY numbers_hash_failure_test FROM STDIN WITH (FORMAT 'csv'); -WARNING: connection error: localhost:57637 -WARNING: connection error: localhost:57637 --- check shard states before commit -SELECT shardid, shardstate, nodename, nodeport -FROM pg_dist_shard_placement JOIN pg_dist_shard USING (shardid) -WHERE logicalrelid = 'numbers_hash_failure_test'::regclass -ORDER BY shardid, nodeport; - shardid | shardstate | nodename | nodeport ----------+------------+-----------+---------- - 1200016 | 3 | localhost | 57637 - 1200016 | 1 | localhost | 57638 - 1200017 | 1 | localhost | 57637 - 1200017 | 1 | localhost | 57638 - 1200018 | 1 | localhost | 57637 - 1200018 | 1 | localhost | 57638 - 1200019 | 3 | localhost | 57637 - 1200019 | 1 | localhost | 57638 -(8 rows) - -COMMIT; --- expect some placements to be market invalid after commit -SELECT shardid, shardstate, nodename, nodeport -FROM pg_dist_shard_placement JOIN pg_dist_shard USING (shardid) -WHERE logicalrelid = 'numbers_hash_failure_test'::regclass -ORDER BY shardid, nodeport; - shardid | shardstate | nodename | nodeport ----------+------------+-----------+---------- - 1200016 | 3 | localhost | 57637 - 1200016 | 1 | localhost | 57638 - 1200017 | 1 | localhost | 57637 - 1200017 | 1 | localhost | 57638 - 1200018 | 1 | localhost | 57637 - 1200018 | 1 | localhost | 57638 - 1200019 | 3 | localhost | 57637 - 1200019 | 1 | localhost | 57638 -(8 rows) - --- verify data is inserted -SELECT count(*) FROM numbers_hash_failure_test; -WARNING: connection error: localhost:57637 -WARNING: connection error: localhost:57637 - count -------- - 2 -(1 row) - --- break the other node as well -\c - :default_user - :worker_2_port -ALTER USER test_user RENAME TO test_user_new; -\c - test_user - :master_port --- fails on all shard placements -INSERT INTO numbers_hash_failure_test VALUES (2,2); -ERROR: connection error: localhost:57638 --- connect back to the master with the proper user to continue the tests -\c - :default_user - :master_port -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 -SELECT * FROM run_command_on_workers('ALTER USER test_user_new RENAME TO test_user'); - nodename | nodeport | success | result ------------+----------+---------+------------ - localhost | 57637 | t | ALTER ROLE - localhost | 57638 | t | ALTER ROLE -(2 rows) - -DROP TABLE reference_modifying_xacts, hash_modifying_xacts, hash_modifying_xacts_second, - reference_failure_test, numbers_hash_failure_test; -SELECT * FROM run_command_on_workers('DROP USER test_user'); - nodename | nodeport | success | result ------------+----------+---------+----------- - localhost | 57637 | t | DROP ROLE - localhost | 57638 | t | DROP ROLE -(2 rows) - -DROP USER test_user; --- set up foreign keys to test transactions with co-located and reference tables -BEGIN; -SET LOCAL citus.shard_replication_factor TO 1; -SET LOCAL citus.shard_count TO 4; -CREATE TABLE usergroups ( - gid int PRIMARY KEY, - name text -); -SELECT create_reference_table('usergroups'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE itemgroups ( - gid int PRIMARY KEY, - name text -); -SELECT create_reference_table('itemgroups'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE users ( - id int PRIMARY KEY, - name text, - user_group int -); -SELECT create_distributed_table('users', 'id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE items ( - user_id int REFERENCES users (id) ON DELETE CASCADE, - item_name text, - item_group int -); -SELECT create_distributed_table('items', 'user_id'); - create_distributed_table --------------------------- - -(1 row) - --- Table to find values that live in different shards on the same node -SELECT id, shard_name('users', shardid), nodename, nodeport -FROM - pg_dist_shard_placement -JOIN - ( SELECT id, get_shard_id_for_distribution_column('users', id) shardid FROM generate_series(1,10) id ) ids -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 -(10 rows) - -END; --- the INSERTs into items should see the users -BEGIN; -\COPY users FROM STDIN WITH CSV -INSERT INTO items VALUES (1, 'item-1'); -INSERT INTO items VALUES (6, 'item-6'); -END; -SELECT user_id FROM items ORDER BY user_id; - user_id ---------- - 1 - 6 -(2 rows) - --- should be able to open multiple connections per node after INSERTing over one connection -BEGIN; -INSERT INTO users VALUES (2, 'burak'); -INSERT INTO users VALUES (3, 'burak'); -\COPY items FROM STDIN WITH CSV -ROLLBACK; --- perform parallel DDL after a co-located table has been read over 1 connection -BEGIN; -SELECT id FROM users WHERE id = 1; - id ----- - 1 -(1 row) - -SELECT id FROM users WHERE id = 6; - id ----- - 6 -(1 row) - -ALTER TABLE items ADD COLUMN last_update timestamptz; -ROLLBACK; --- can perform sequential DDL after a co-located table has been read over 1 connection -BEGIN; -SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; -SELECT id FROM users WHERE id = 1; - id ----- - 1 -(1 row) - -SELECT id FROM users WHERE id = 6; - id ----- - 6 -(1 row) - -ALTER TABLE items ADD COLUMN last_update timestamptz; -ROLLBACK; --- and the other way around is also fine -BEGIN; -ALTER TABLE items ADD COLUMN last_update timestamptz; -SELECT id FROM users JOIN items ON (id = user_id) WHERE id = 1; - id ----- - 1 -(1 row) - -SELECT id FROM users JOIN items ON (id = user_id) WHERE id = 6; - id ----- - 6 -(1 row) - -END; -BEGIN; --- establish multiple connections to a node -\COPY users FROM STDIN WITH CSV --- now read from the reference table over each connection -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 2; - user_id ---------- -(0 rows) - -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 3; - user_id ---------- -(0 rows) - --- perform a DDL command on the reference table errors --- because the current implementation of COPY always opens one connection --- per placement SELECTs have to use those connections for correctness -ALTER TABLE itemgroups ADD COLUMN last_update timestamptz; -ERROR: cannot perform DDL on placement 1200036, which has been read over multiple connections -END; -BEGIN; --- establish multiple connections to a node -\COPY users FROM STDIN WITH CSV --- read from the reference table over each connection -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 2; - user_id ---------- -(0 rows) - -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 3; - user_id ---------- -(0 rows) - --- perform a DDL command on a co-located reference table -ALTER TABLE usergroups ADD COLUMN last_update timestamptz; -ERROR: cannot perform DDL on placement 1200034 since a co-located placement has been read over multiple connections -END; -BEGIN; --- make a modification over connection 1 -INSERT INTO usergroups VALUES (0,'istanbul'); --- copy over connections 1 and 2 -\COPY users FROM STDIN WITH CSV --- cannot read modifications made over different connections -SELECT id FROM users JOIN usergroups ON (gid = user_group) WHERE id = 3; -ERROR: cannot perform query with placements that were modified over multiple connections -END; --- make sure we can see cascading deletes -BEGIN; -DELETE FROM users; -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 1; - user_id ---------- -(0 rows) - -SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 6; - user_id ---------- -(0 rows) - -END; --- test visibility after COPY -INSERT INTO usergroups VALUES (2,'group'); -BEGIN; --- opens two separate connections to node -\COPY users FROM STDIN WITH CSV --- Uses first connection, which wrote the row with id = 2 -SELECT * FROM users JOIN usergroups ON (user_group = gid) WHERE id = 2; - id | name | user_group | gid | name -----+-------+------------+-----+------- - 2 | onder | 2 | 2 | group -(1 row) - --- Should use second connection, which wrote the row with id = 4 -SELECT * FROM users JOIN usergroups ON (user_group = gid) WHERE id = 4; - id | name | user_group | gid | name -----+-------+------------+-----+------- - 4 | murat | 2 | 2 | group -(1 row) - -END; --- make sure functions that throw an error roll back propertly -CREATE FUNCTION insert_abort() -RETURNS bool -AS $BODY$ -BEGIN - INSERT INTO labs VALUES (1001, 'Abort Labs'); - UPDATE labs SET name = 'Rollback Labs' WHERE id = 1001; - RAISE 'do not insert'; -END; -$BODY$ LANGUAGE plpgsql; -SELECT insert_abort(); -ERROR: do not insert -SELECT name FROM labs WHERE id = 1001; - name ------- -(0 rows) - --- if function_opens_transaction-block is disabled the insert commits immediately -SET citus.function_opens_transaction_block TO off; -SELECT insert_abort(); -ERROR: do not insert -SELECT name FROM labs WHERE id = 1001; - name ---------------- - Rollback Labs -(1 row) - -RESET citus.function_opens_transaction_block; -DROP FUNCTION insert_abort(); -DROP TABLE items, users, itemgroups, usergroups, researchers, labs; diff --git a/src/test/regress/expected/multi_partition_pruning.out b/src/test/regress/expected/multi_partition_pruning.out index 210a9c4e6..824485ae3 100644 --- a/src/test/regress/expected/multi_partition_pruning.out +++ b/src/test/regress/expected/multi_partition_pruning.out @@ -153,7 +153,7 @@ SELECT count(*) FROM varchar_partitioned_table WHERE varchar_column = 'BA2'; QUERY PLAN ------------------------------------------------- Aggregate - -> Custom Scan (Citus Real-Time) + -> Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task @@ -166,7 +166,7 @@ SELECT count(*) FROM array_partitioned_table QUERY PLAN ------------------------------------------------- Aggregate - -> Custom Scan (Citus Real-Time) + -> Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task @@ -179,7 +179,7 @@ SELECT count(*) FROM composite_partitioned_table QUERY PLAN ------------------------------------------------- Aggregate - -> Custom Scan (Citus Real-Time) + -> Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task diff --git a/src/test/regress/expected/multi_partitioning.out b/src/test/regress/expected/multi_partitioning.out index bb5f6f192..8f5c63d46 100644 --- a/src/test/regress/expected/multi_partitioning.out +++ b/src/test/regress/expected/multi_partitioning.out @@ -412,7 +412,7 @@ SELECT * FROM partitioning_test WHERE id = 9 OR id = 10 ORDER BY 1; -- create default partition CREATE TABLE partitioning_test_default PARTITION OF partitioning_test DEFAULT; \d+ partitioning_test - Table "public.partitioning_test" + Partitioned table "public.partitioning_test" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | @@ -1475,21 +1475,13 @@ WHERE pid = pg_backend_pid() ORDER BY 1, 2, 3; - logicalrelid | locktype | mode --------------------------+----------+-------------------------- - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock + logicalrelid | locktype | mode +-------------------------+----------+----------- partitioning_locks_2009 | advisory | ShareLock partitioning_locks_2009 | advisory | ShareLock partitioning_locks_2009 | advisory | ShareLock partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock -(12 rows) +(4 rows) COMMIT; -- test shard resource locks with INSERT/SELECT @@ -1583,7 +1575,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Custom Scan (Citus Real-Time) + Custom Scan (Citus Adaptive) Task Count: 4 Tasks Shown: One of 4 -> Task @@ -1623,7 +1615,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - Custom Scan (Citus Real-Time) + Custom Scan (Citus Adaptive) Task Count: 4 Tasks Shown: One of 4 -> Task @@ -1653,7 +1645,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); QUERY PLAN --------------------------------------------------------------------------------------------------------- - Custom Scan (Citus Real-Time) + Custom Scan (Citus Adaptive) Task Count: 4 Tasks Shown: One of 4 -> Task diff --git a/src/test/regress/expected/multi_partitioning_1.out b/src/test/regress/expected/multi_partitioning_1.out deleted file mode 100644 index 8f5c63d46..000000000 --- a/src/test/regress/expected/multi_partitioning_1.out +++ /dev/null @@ -1,1935 +0,0 @@ --- --- Distributed Partitioned Table Tests --- -SET citus.next_shard_id TO 1660000; -SET citus.shard_count TO 4; -SET citus.shard_replication_factor TO 1; --- --- Distributed Partitioned Table Creation Tests --- --- 1-) Distributing partitioned table --- create partitioned table -CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); -CREATE TABLE partitioning_hash_test(id int, subid int) PARTITION BY HASH(subid); --- create its partitions -CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); -CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); -CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); -CREATE TABLE partitioning_hash_test_1 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); --- load some data and distribute tables -INSERT INTO partitioning_test VALUES (1, '2009-06-06'); -INSERT INTO partitioning_test VALUES (2, '2010-07-07'); -INSERT INTO partitioning_test_2009 VALUES (3, '2009-09-09'); -INSERT INTO partitioning_test_2010 VALUES (4, '2010-03-03'); -INSERT INTO partitioning_hash_test VALUES (1, 2); -INSERT INTO partitioning_hash_test VALUES (2, 13); -INSERT INTO partitioning_hash_test VALUES (3, 7); -INSERT INTO partitioning_hash_test VALUES (4, 4); --- distribute partitioned table -SELECT create_distributed_table('partitioning_test', 'id'); -NOTICE: Copying data from local table... -NOTICE: Copying data from local table... - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('partitioning_hash_test', 'id'); -NOTICE: Copying data from local table... -NOTICE: Copying data from local table... - create_distributed_table --------------------------- - -(1 row) - --- see the data is loaded to shards -SELECT * FROM partitioning_test ORDER BY 1; - id | time -----+------------ - 1 | 06-06-2009 - 2 | 07-07-2010 - 3 | 09-09-2009 - 4 | 03-03-2010 -(4 rows) - -SELECT * FROM partitioning_hash_test ORDER BY 1; - id | subid -----+------- - 1 | 2 - 2 | 13 - 3 | 7 - 4 | 4 -(4 rows) - --- see partitioned table and its partitions are distributed -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') -ORDER BY 1; - logicalrelid ------------------------- - partitioning_test - partitioning_test_2009 - partitioning_test_2010 -(3 rows) - -SELECT - logicalrelid, count(*) -FROM pg_dist_shard - WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count -------------------------+------- - partitioning_test | 4 - partitioning_test_2009 | 4 - partitioning_test_2010 | 4 -(3 rows) - -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_hash_test', 'partitioning_hash_test_0', 'partitioning_hash_test_1') -ORDER BY 1; - logicalrelid --------------------------- - partitioning_hash_test - partitioning_hash_test_0 - partitioning_hash_test_1 -(3 rows) - -SELECT - logicalrelid, count(*) -FROM pg_dist_shard - WHERE logicalrelid IN ('partitioning_hash_test', 'partitioning_hash_test_0', 'partitioning_hash_test_1') -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count ---------------------------+------- - partitioning_hash_test | 4 - partitioning_hash_test_0 | 4 - partitioning_hash_test_1 | 4 -(3 rows) - --- 2-) Creating partition of a distributed table -CREATE TABLE partitioning_test_2011 PARTITION OF partitioning_test FOR VALUES FROM ('2011-01-01') TO ('2012-01-01'); --- new partition is automatically distributed as well -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_test', 'partitioning_test_2011') -ORDER BY 1; - logicalrelid ------------------------- - partitioning_test - partitioning_test_2011 -(2 rows) - -SELECT - logicalrelid, count(*) -FROM pg_dist_shard - WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count -------------------------+------- - partitioning_test | 4 - partitioning_test_2011 | 4 -(2 rows) - --- 3-) Attaching non distributed table to a distributed table -CREATE TABLE partitioning_test_2012(id int, time date); --- load some data -INSERT INTO partitioning_test_2012 VALUES (5, '2012-06-06'); -INSERT INTO partitioning_test_2012 VALUES (6, '2012-07-07'); -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2012 FOR VALUES FROM ('2012-01-01') TO ('2013-01-01'); -NOTICE: Copying data from local table... --- attached partition is distributed as well -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_test', 'partitioning_test_2012') -ORDER BY 1; - logicalrelid ------------------------- - partitioning_test - partitioning_test_2012 -(2 rows) - -SELECT - logicalrelid, count(*) -FROM pg_dist_shard - WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count -------------------------+------- - partitioning_test | 4 - partitioning_test_2012 | 4 -(2 rows) - --- try to insert a new data to hash partitioned table --- no partition is defined for value 5 -INSERT INTO partitioning_hash_test VALUES (8, 5); -ERROR: no partition of relation "partitioning_hash_test_1660012" found for row -DETAIL: Partition key of the failing row contains (subid) = (5). -CONTEXT: while executing command on localhost:57637 -INSERT INTO partitioning_hash_test VALUES (9, 12); -ERROR: no partition of relation "partitioning_hash_test_1660015" found for row -DETAIL: Partition key of the failing row contains (subid) = (12). -CONTEXT: while executing command on localhost:57638 -CREATE TABLE partitioning_hash_test_2 (id int, subid int); -INSERT INTO partitioning_hash_test_2 VALUES (8, 5); -ALTER TABLE partitioning_hash_test ATTACH PARTITION partitioning_hash_test_2 FOR VALUES WITH (MODULUS 3, REMAINDER 2); -NOTICE: Copying data from local table... -INSERT INTO partitioning_hash_test VALUES (9, 12); --- see the data is loaded to shards -SELECT * FROM partitioning_test ORDER BY 1; - id | time -----+------------ - 1 | 06-06-2009 - 2 | 07-07-2010 - 3 | 09-09-2009 - 4 | 03-03-2010 - 5 | 06-06-2012 - 6 | 07-07-2012 -(6 rows) - -SELECT * FROM partitioning_hash_test ORDER BY 1; - id | subid -----+------- - 1 | 2 - 2 | 13 - 3 | 7 - 4 | 4 - 8 | 5 - 9 | 12 -(6 rows) - --- 4-) Attaching distributed table to distributed table -CREATE TABLE partitioning_test_2013(id int, time date); -SELECT create_distributed_table('partitioning_test_2013', 'id'); - create_distributed_table --------------------------- - -(1 row) - --- load some data -INSERT INTO partitioning_test_2013 VALUES (7, '2013-06-06'); -INSERT INTO partitioning_test_2013 VALUES (8, '2013-07-07'); -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2013 FOR VALUES FROM ('2013-01-01') TO ('2014-01-01'); --- see the data is loaded to shards -SELECT * FROM partitioning_test ORDER BY 1; - id | time -----+------------ - 1 | 06-06-2009 - 2 | 07-07-2010 - 3 | 09-09-2009 - 4 | 03-03-2010 - 5 | 06-06-2012 - 6 | 07-07-2012 - 7 | 06-06-2013 - 8 | 07-07-2013 -(8 rows) - --- 5-) Failure cases while creating distributed partitioned tables --- cannot distribute a partition if its parent is not distributed -CREATE TABLE partitioning_test_failure(id int, time date) PARTITION BY RANGE (time); -CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); -SELECT create_distributed_table('partitioning_test_failure_2009', 'id'); -ERROR: cannot distribute relation "partitioning_test_failure_2009" which is partition of "partitioning_test_failure" -DETAIL: Citus does not support distributing partitions if their parent is not distributed table. -HINT: Distribute the partitioned table "partitioning_test_failure" instead. --- only hash distributed tables can have partitions -SELECT create_distributed_table('partitioning_test_failure', 'id', 'append'); -ERROR: distributing partitioned tables in only supported for hash-distributed tables -SELECT create_distributed_table('partitioning_test_failure', 'id', 'range'); -ERROR: distributing partitioned tables in only supported for hash-distributed tables -SELECT create_reference_table('partitioning_test_failure'); -ERROR: distributing partitioned tables in only supported for hash-distributed tables -SET citus.shard_replication_factor TO 1; --- non-distributed tables cannot have distributed partitions; -DROP TABLE partitioning_test_failure_2009; -CREATE TABLE partitioning_test_failure_2009(id int, time date); -SELECT create_distributed_table('partitioning_test_failure_2009', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ALTER TABLE partitioning_test_failure ATTACH PARTITION partitioning_test_failure_2009 FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); -ERROR: non-distributed tables cannot have distributed partitions -HINT: Distribute the partitioned table "partitioning_test_failure_2009" instead --- multi-level partitioning is not allowed -DROP TABLE partitioning_test_failure_2009; -CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01') PARTITION BY RANGE (time); -SELECT create_distributed_table('partitioning_test_failure', 'id'); -ERROR: distributing multi-level partitioned tables is not supported -DETAIL: Relation "partitioning_test_failure_2009" is partitioned table itself and it is also partition of relation "partitioning_test_failure". --- multi-level partitioning is not allowed in different order -DROP TABLE partitioning_test_failure_2009; -SELECT create_distributed_table('partitioning_test_failure', 'id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01') PARTITION BY RANGE (time); -ERROR: distributing multi-level partitioned tables is not supported -DETAIL: Relation "partitioning_test_failure_2009" is partitioned table itself and it is also partition of relation "partitioning_test_failure". --- --- DMLs in distributed partitioned tables --- --- test COPY --- COPY data to partitioned table -COPY partitioning_test FROM STDIN WITH CSV; --- COPY data to partition directly -COPY partitioning_test_2009 FROM STDIN WITH CSV; --- see the data is loaded to shards -SELECT * FROM partitioning_test WHERE id >= 9 ORDER BY 1; - id | time -----+------------ - 9 | 01-01-2009 - 10 | 01-01-2010 - 11 | 01-01-2011 - 12 | 01-01-2012 - 13 | 01-02-2009 - 14 | 01-03-2009 -(6 rows) - --- test INSERT --- INSERT INTO the partitioned table -INSERT INTO partitioning_test VALUES(15, '2009-02-01'); -INSERT INTO partitioning_test VALUES(16, '2010-02-01'); -INSERT INTO partitioning_test VALUES(17, '2011-02-01'); -INSERT INTO partitioning_test VALUES(18, '2012-02-01'); --- INSERT INTO the partitions directly table -INSERT INTO partitioning_test VALUES(19, '2009-02-02'); -INSERT INTO partitioning_test VALUES(20, '2010-02-02'); --- see the data is loaded to shards -SELECT * FROM partitioning_test WHERE id >= 15 ORDER BY 1; - id | time -----+------------ - 15 | 02-01-2009 - 16 | 02-01-2010 - 17 | 02-01-2011 - 18 | 02-01-2012 - 19 | 02-02-2009 - 20 | 02-02-2010 -(6 rows) - --- test INSERT/SELECT --- INSERT/SELECT from partition to partitioned table -INSERT INTO partitioning_test SELECT * FROM partitioning_test_2011; --- INSERT/SELECT from partitioned table to partition -INSERT INTO partitioning_test_2012 SELECT * FROM partitioning_test WHERE time >= '2012-01-01' AND time < '2013-01-01'; --- see the data is loaded to shards (rows in the given range should be duplicated) -SELECT * FROM partitioning_test WHERE time >= '2011-01-01' AND time < '2013-01-01' ORDER BY 1; - id | time -----+------------ - 5 | 06-06-2012 - 5 | 06-06-2012 - 6 | 07-07-2012 - 6 | 07-07-2012 - 11 | 01-01-2011 - 11 | 01-01-2011 - 12 | 01-01-2012 - 12 | 01-01-2012 - 17 | 02-01-2011 - 17 | 02-01-2011 - 18 | 02-01-2012 - 18 | 02-01-2012 -(12 rows) - --- test UPDATE --- UPDATE partitioned table -UPDATE partitioning_test SET time = '2013-07-07' WHERE id = 7; --- UPDATE partition directly -UPDATE partitioning_test_2013 SET time = '2013-08-08' WHERE id = 8; --- see the data is updated -SELECT * FROM partitioning_test WHERE id = 7 OR id = 8 ORDER BY 1; - id | time -----+------------ - 7 | 07-07-2013 - 8 | 08-08-2013 -(2 rows) - --- UPDATE that tries to move a row to a non-existing partition (this should fail) -UPDATE partitioning_test SET time = '2020-07-07' WHERE id = 7; -ERROR: no partition of relation "partitioning_test_1660001" found for row -DETAIL: Partition key of the failing row contains ("time") = (2020-07-07). -CONTEXT: while executing command on localhost:57638 --- UPDATE with subqueries on partitioned table -UPDATE - partitioning_test -SET - time = time + INTERVAL '1 day' -WHERE - id IN (SELECT id FROM partitioning_test WHERE id = 1); --- UPDATE with subqueries on partition -UPDATE - partitioning_test_2009 -SET - time = time + INTERVAL '1 month' -WHERE - id IN (SELECT id FROM partitioning_test WHERE id = 2); --- see the data is updated -SELECT * FROM partitioning_test WHERE id = 1 OR id = 2 ORDER BY 1; - id | time -----+------------ - 1 | 06-07-2009 - 2 | 07-07-2010 -(2 rows) - --- test DELETE --- DELETE from partitioned table -DELETE FROM partitioning_test WHERE id = 9; --- DELETE from partition directly -DELETE FROM partitioning_test_2010 WHERE id = 10; --- see the data is deleted -SELECT * FROM partitioning_test WHERE id = 9 OR id = 10 ORDER BY 1; - id | time -----+------ -(0 rows) - --- create default partition -CREATE TABLE partitioning_test_default PARTITION OF partitioning_test DEFAULT; -\d+ partitioning_test - Partitioned table "public.partitioning_test" - Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ---------+---------+-----------+----------+---------+---------+--------------+------------- - id | integer | | | | plain | | - time | date | | | | plain | | -Partition key: RANGE ("time") -Partitions: partitioning_test_2009 FOR VALUES FROM ('01-01-2009') TO ('01-01-2010'), - partitioning_test_2010 FOR VALUES FROM ('01-01-2010') TO ('01-01-2011'), - partitioning_test_2011 FOR VALUES FROM ('01-01-2011') TO ('01-01-2012'), - partitioning_test_2012 FOR VALUES FROM ('01-01-2012') TO ('01-01-2013'), - partitioning_test_2013 FOR VALUES FROM ('01-01-2013') TO ('01-01-2014'), - partitioning_test_default DEFAULT - -INSERT INTO partitioning_test VALUES(21, '2014-02-02'); -INSERT INTO partitioning_test VALUES(22, '2015-04-02'); --- see they are inserted into default partition -SELECT * FROM partitioning_test WHERE id > 20 ORDER BY 1, 2; - id | time -----+------------ - 21 | 02-02-2014 - 22 | 04-02-2015 -(2 rows) - -SELECT * FROM partitioning_test_default ORDER BY 1, 2; - id | time -----+------------ - 21 | 02-02-2014 - 22 | 04-02-2015 -(2 rows) - --- create a new partition (will fail) -CREATE TABLE partitioning_test_2014 PARTITION OF partitioning_test FOR VALUES FROM ('2014-01-01') TO ('2015-01-01'); -ERROR: updated partition constraint for default partition would be violated by some row -CONTEXT: while executing command on localhost:57637 -BEGIN; -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_default; -CREATE TABLE partitioning_test_2014 PARTITION OF partitioning_test FOR VALUES FROM ('2014-01-01') TO ('2015-01-01'); -INSERT INTO partitioning_test SELECT * FROM partitioning_test_default WHERE time >= '2014-01-01' AND time < '2015-01-01'; -DELETE FROM partitioning_test_default WHERE time >= '2014-01-01' AND time < '2015-01-01'; -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_default DEFAULT; -END; --- see data is in the table, but some moved out from default partition -SELECT * FROM partitioning_test WHERE id > 20 ORDER BY 1, 2; - id | time -----+------------ - 21 | 02-02-2014 - 22 | 04-02-2015 -(2 rows) - -SELECT * FROM partitioning_test_default ORDER BY 1, 2; - id | time -----+------------ - 22 | 04-02-2015 -(1 row) - --- multi-shard UPDATE on partitioned table -UPDATE partitioning_test SET time = time + INTERVAL '1 day'; --- see rows are UPDATED -SELECT * FROM partitioning_test ORDER BY 1; - id | time -----+------------ - 1 | 06-08-2009 - 2 | 07-08-2010 - 3 | 09-10-2009 - 4 | 03-04-2010 - 5 | 06-07-2012 - 5 | 06-07-2012 - 6 | 07-08-2012 - 6 | 07-08-2012 - 7 | 07-08-2013 - 8 | 08-09-2013 - 11 | 01-02-2011 - 11 | 01-02-2011 - 12 | 01-02-2012 - 12 | 01-02-2012 - 13 | 01-03-2009 - 14 | 01-04-2009 - 15 | 02-02-2009 - 16 | 02-02-2010 - 17 | 02-02-2011 - 17 | 02-02-2011 - 18 | 02-02-2012 - 18 | 02-02-2012 - 19 | 02-03-2009 - 20 | 02-03-2010 - 21 | 02-03-2014 - 22 | 04-03-2015 -(26 rows) - --- multi-shard UPDATE on partition directly -UPDATE partitioning_test_2009 SET time = time + INTERVAL '1 day'; --- see rows are UPDATED -SELECT * FROM partitioning_test_2009 ORDER BY 1; - id | time -----+------------ - 1 | 06-09-2009 - 3 | 09-11-2009 - 13 | 01-04-2009 - 14 | 01-05-2009 - 15 | 02-03-2009 - 19 | 02-04-2009 -(6 rows) - --- test multi-shard UPDATE which fails in workers (updated value is outside of partition bounds) -UPDATE partitioning_test_2009 SET time = time + INTERVAL '6 month'; -ERROR: new row for relation "partitioning_test_2009_1660005" violates partition constraint -DETAIL: Failing row contains (3, 2010-03-11). -CONTEXT: while executing command on localhost:57638 --- --- DDL in distributed partitioned tables --- --- test CREATE INDEX --- CREATE INDEX on partitioned table - this will error out --- on earlier versions of postgres earlier than 11. -CREATE INDEX partitioning_index ON partitioning_test(id); --- CREATE INDEX on partition -CREATE INDEX partitioning_2009_index ON partitioning_test_2009(id); --- CREATE INDEX CONCURRENTLY on partition -CREATE INDEX CONCURRENTLY partitioned_2010_index ON partitioning_test_2010(id); --- see index is created -SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'partitioning_test_%' ORDER BY indexname; - tablename | indexname ----------------------------+---------------------------------- - partitioning_test_2010 | partitioned_2010_index - partitioning_test_2009 | partitioning_2009_index - partitioning_test_2009 | partitioning_test_2009_id_idx - partitioning_test_2010 | partitioning_test_2010_id_idx - partitioning_test_2011 | partitioning_test_2011_id_idx - partitioning_test_2012 | partitioning_test_2012_id_idx - partitioning_test_2013 | partitioning_test_2013_id_idx - partitioning_test_2014 | partitioning_test_2014_id_idx - partitioning_test_default | partitioning_test_default_id_idx -(9 rows) - --- test drop --- indexes created on parent table can only be dropped on parent table --- ie using the same index name --- following will fail -DROP INDEX partitioning_test_2009_id_idx; -ERROR: cannot drop index partitioning_test_2009_id_idx because index partitioning_index requires it -HINT: You can drop index partitioning_index instead. --- but dropping index on parent table will succeed -DROP INDEX partitioning_index; --- this index was already created on partition table -DROP INDEX partitioning_2009_index; --- test drop index on non-distributed, partitioned table -CREATE TABLE non_distributed_partitioned_table(a int, b int) PARTITION BY RANGE (a); -CREATE TABLE non_distributed_partitioned_table_1 PARTITION OF non_distributed_partitioned_table -FOR VALUES FROM (0) TO (10); -CREATE INDEX non_distributed_partitioned_table_index ON non_distributed_partitioned_table(a); --- see index is created -SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'non_distributed_partitioned_table_%' ORDER BY indexname; - tablename | indexname --------------------------------------+------------------------------------------- - non_distributed_partitioned_table_1 | non_distributed_partitioned_table_1_a_idx -(1 row) - --- drop the index and see it is dropped -DROP INDEX non_distributed_partitioned_table_index; -SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'non_distributed%' ORDER BY indexname; - tablename | indexname ------------+----------- -(0 rows) - --- test add COLUMN --- add COLUMN to partitioned table -ALTER TABLE partitioning_test ADD new_column int; --- add COLUMN to partition - this will error out -ALTER TABLE partitioning_test_2010 ADD new_column_2 int; -ERROR: cannot add column to a partition --- see additional column is created -SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; - name | type -------------+--------- - id | integer - new_column | integer - time | date -(3 rows) - -SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test_2010'::regclass ORDER BY 1; - name | type -------------+--------- - id | integer - new_column | integer - time | date -(3 rows) - --- test add PRIMARY KEY --- add PRIMARY KEY to partitioned table - this will error out -ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_primary PRIMARY KEY (id); -ERROR: insufficient columns in PRIMARY KEY constraint definition -DETAIL: PRIMARY KEY constraint on table "partitioning_test" lacks column "time" which is part of the partition key. --- ADD PRIMARY KEY to partition -ALTER TABLE partitioning_test_2009 ADD CONSTRAINT partitioning_2009_primary PRIMARY KEY (id); --- see PRIMARY KEY is created -SELECT - table_name, - constraint_name, - constraint_type -FROM - information_schema.table_constraints -WHERE - table_name = 'partitioning_test_2009' AND - constraint_name = 'partitioning_2009_primary'; - table_name | constraint_name | constraint_type -------------------------+---------------------------+----------------- - partitioning_test_2009 | partitioning_2009_primary | PRIMARY KEY -(1 row) - --- however, you can add primary key if it contains both distribution and partition key -ALTER TABLE partitioning_hash_test ADD CONSTRAINT partitioning_hash_primary PRIMARY KEY (id, subid); --- see PRIMARY KEY is created -SELECT - table_name, - constraint_name, - constraint_type -FROM - information_schema.table_constraints -WHERE - table_name LIKE 'partitioning_hash_test%' AND - constraint_type = 'PRIMARY KEY' -ORDER BY 1; - table_name | constraint_name | constraint_type ---------------------------+-------------------------------+----------------- - partitioning_hash_test | partitioning_hash_primary | PRIMARY KEY - partitioning_hash_test_0 | partitioning_hash_test_0_pkey | PRIMARY KEY - partitioning_hash_test_1 | partitioning_hash_test_1_pkey | PRIMARY KEY - partitioning_hash_test_2 | partitioning_hash_test_2_pkey | PRIMARY KEY -(4 rows) - --- test ADD FOREIGN CONSTRAINT --- add FOREIGN CONSTRAINT to partitioned table -- this will error out (it is a self reference) -ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_foreign FOREIGN KEY (id) REFERENCES partitioning_test_2009 (id); -ERROR: cannot ALTER TABLE "partitioning_test_2009" because it is being used by active queries in this session --- add FOREIGN CONSTRAINT to partition -INSERT INTO partitioning_test_2009 VALUES (5, '2009-06-06'); -INSERT INTO partitioning_test_2009 VALUES (6, '2009-07-07'); -INSERT INTO partitioning_test_2009 VALUES(12, '2009-02-01'); -INSERT INTO partitioning_test_2009 VALUES(18, '2009-02-01'); -ALTER TABLE partitioning_test_2012 ADD CONSTRAINT partitioning_2012_foreign FOREIGN KEY (id) REFERENCES partitioning_test_2009 (id) ON DELETE CASCADE; --- see FOREIGN KEY is created -SELECT "Constraint" FROM table_fkeys WHERE relid = 'partitioning_test_2012'::regclass ORDER BY 1; - Constraint ---------------------------- - partitioning_2012_foreign -(1 row) - --- test ON DELETE CASCADE works -DELETE FROM partitioning_test_2009 WHERE id = 5; --- see that element is deleted from both partitions -SELECT * FROM partitioning_test_2009 WHERE id = 5 ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - -SELECT * FROM partitioning_test_2012 WHERE id = 5 ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- test DETACH partition -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2009; --- see DETACHed partitions content is not accessible from partitioning_test; -SELECT * FROM partitioning_test WHERE time >= '2009-01-01' AND time < '2010-01-01' ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- delete from default partition -DELETE FROM partitioning_test WHERE time >= '2015-01-01'; -SELECT * FROM partitioning_test_default; - id | time | new_column -----+------+------------ -(0 rows) - --- create a reference table for foreign key test -CREATE TABLE partitioning_test_reference(id int PRIMARY KEY, subid int); -INSERT INTO partitioning_test_reference SELECT a, a FROM generate_series(1, 50) a; -SELECT create_reference_table('partitioning_test_reference'); -NOTICE: Copying data from local table... - create_reference_table ------------------------- - -(1 row) - -ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_reference_fkey FOREIGN KEY (id) REFERENCES partitioning_test_reference(id) ON DELETE CASCADE; -CREATE TABLE partitioning_test_foreign_key(id int PRIMARY KEY, value int); -SELECT create_distributed_table('partitioning_test_foreign_key', 'id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO partitioning_test_foreign_key SELECT * FROM partitioning_test_reference; -ALTER TABLE partitioning_hash_test ADD CONSTRAINT partitioning_reference_fk_test FOREIGN KEY (id) REFERENCES partitioning_test_foreign_key(id) ON DELETE CASCADE; --- check foreign keys on partitions -SELECT - table_name, constraint_name, constraint_type FROm information_schema.table_constraints -WHERE - table_name LIKE 'partitioning_hash_test%' AND - constraint_type = 'FOREIGN KEY' -ORDER BY - 1,2; - table_name | constraint_name | constraint_type ---------------------------+--------------------------------+----------------- - partitioning_hash_test | partitioning_reference_fk_test | FOREIGN KEY - partitioning_hash_test_0 | partitioning_reference_fk_test | FOREIGN KEY - partitioning_hash_test_1 | partitioning_reference_fk_test | FOREIGN KEY - partitioning_hash_test_2 | partitioning_reference_fk_test | FOREIGN KEY -(4 rows) - --- check foreign keys on partition shards --- there is some text ordering issue regarding table name --- forcing integer sort by extracting shardid -CREATE TYPE foreign_key_details AS (table_name text, constraint_name text, constraint_type text); -SELECT right(table_name, 7)::int as shardid, * FROM ( - SELECT (json_populate_record(NULL::foreign_key_details, - json_array_elements_text(result::json)::json )).* - FROM run_command_on_workers($$ - SELECT - COALESCE(json_agg(row_to_json(q)), '[]'::json) - FROM ( - SELECT - table_name, constraint_name, constraint_type - FROM information_schema.table_constraints - WHERE - table_name LIKE 'partitioning_hash_test%' AND - constraint_type = 'FOREIGN KEY' - ORDER BY 1, 2, 3 - ) q - $$) ) w -ORDER BY 1, 2, 3, 4; - shardid | table_name | constraint_name | constraint_type ----------+----------------------------------+----------------------------------------+----------------- - 1660012 | partitioning_hash_test_1660012 | partitioning_reference_fk_test_1660012 | FOREIGN KEY - 1660013 | partitioning_hash_test_1660013 | partitioning_reference_fk_test_1660013 | FOREIGN KEY - 1660014 | partitioning_hash_test_1660014 | partitioning_reference_fk_test_1660014 | FOREIGN KEY - 1660015 | partitioning_hash_test_1660015 | partitioning_reference_fk_test_1660015 | FOREIGN KEY - 1660016 | partitioning_hash_test_0_1660016 | partitioning_reference_fk_test_1660012 | FOREIGN KEY - 1660017 | partitioning_hash_test_0_1660017 | partitioning_reference_fk_test_1660013 | FOREIGN KEY - 1660018 | partitioning_hash_test_0_1660018 | partitioning_reference_fk_test_1660014 | FOREIGN KEY - 1660019 | partitioning_hash_test_0_1660019 | partitioning_reference_fk_test_1660015 | FOREIGN KEY - 1660020 | partitioning_hash_test_1_1660020 | partitioning_reference_fk_test_1660012 | FOREIGN KEY - 1660021 | partitioning_hash_test_1_1660021 | partitioning_reference_fk_test_1660013 | FOREIGN KEY - 1660022 | partitioning_hash_test_1_1660022 | partitioning_reference_fk_test_1660014 | FOREIGN KEY - 1660023 | partitioning_hash_test_1_1660023 | partitioning_reference_fk_test_1660015 | FOREIGN KEY - 1660032 | partitioning_hash_test_2_1660032 | partitioning_reference_fk_test_1660012 | FOREIGN KEY - 1660033 | partitioning_hash_test_2_1660033 | partitioning_reference_fk_test_1660013 | FOREIGN KEY - 1660034 | partitioning_hash_test_2_1660034 | partitioning_reference_fk_test_1660014 | FOREIGN KEY - 1660035 | partitioning_hash_test_2_1660035 | partitioning_reference_fk_test_1660015 | FOREIGN KEY -(16 rows) - -DROP TYPE foreign_key_details; --- set replication factor back to 1 since it gots reset --- after connection re-establishment -SET citus.shard_replication_factor TO 1; -SELECT * FROM partitioning_test WHERE id = 11 or id = 12; - id | time | new_column -----+------------+------------ - 11 | 01-02-2011 | - 11 | 01-02-2011 | - 12 | 01-02-2012 | - 12 | 01-02-2012 | -(4 rows) - -DELETE FROM partitioning_test_reference WHERE id = 11 or id = 12; -SELECT * FROM partitioning_hash_test ORDER BY 1, 2; - id | subid -----+------- - 1 | 2 - 2 | 13 - 3 | 7 - 4 | 4 - 8 | 5 - 9 | 12 -(6 rows) - -DELETE FROM partitioning_test_foreign_key WHERE id = 2 OR id = 9; --- see data is deleted from referencing table -SELECT * FROM partitioning_test WHERE id = 11 or id = 12; - id | time | new_column -----+------+------------ -(0 rows) - -SELECT * FROM partitioning_hash_test ORDER BY 1, 2; - id | subid -----+------- - 1 | 2 - 3 | 7 - 4 | 4 - 8 | 5 -(4 rows) - --- --- Transaction tests --- --- DDL in transaction -BEGIN; -ALTER TABLE partitioning_test ADD newer_column int; --- see additional column is created -SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; - name | type ---------------+--------- - id | integer - new_column | integer - newer_column | integer - time | date -(4 rows) - -ROLLBACK; --- see rollback is successful -SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; - name | type -------------+--------- - id | integer - new_column | integer - time | date -(3 rows) - --- COPY in transaction -BEGIN; -COPY partitioning_test FROM STDIN WITH CSV; --- see the data is loaded to shards -SELECT * FROM partitioning_test WHERE id = 22 ORDER BY 1; - id | time | new_column -----+------------+------------ - 22 | 01-01-2010 | 22 -(1 row) - -SELECT * FROM partitioning_test WHERE id = 23 ORDER BY 1; - id | time | new_column -----+------------+------------ - 23 | 01-01-2011 | 23 -(1 row) - -SELECT * FROM partitioning_test WHERE id = 24 ORDER BY 1; - id | time | new_column -----+------------+------------ - 24 | 01-01-2013 | 24 -(1 row) - -ROLLBACK; --- see rollback is successful -SELECT * FROM partitioning_test WHERE id >= 22 ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- DML in transaction -BEGIN; --- INSERT in transaction -INSERT INTO partitioning_test VALUES(25, '2010-02-02'); --- see the data is loaded to shards -SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; - id | time | new_column -----+------------+------------ - 25 | 02-02-2010 | -(1 row) - --- INSERT/SELECT in transaction -INSERT INTO partitioning_test SELECT * FROM partitioning_test WHERE id = 25; --- see the data is loaded to shards -SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; - id | time | new_column -----+------------+------------ - 25 | 02-02-2010 | - 25 | 02-02-2010 | -(2 rows) - --- UPDATE in transaction -UPDATE partitioning_test SET time = '2010-10-10' WHERE id = 25; --- see the data is updated -SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; - id | time | new_column -----+------------+------------ - 25 | 10-10-2010 | - 25 | 10-10-2010 | -(2 rows) - --- perform operations on partition and partioned tables together -INSERT INTO partitioning_test VALUES(26, '2010-02-02', 26); -INSERT INTO partitioning_test_2010 VALUES(26, '2010-02-02', 26); -COPY partitioning_test FROM STDIN WITH CSV; -COPY partitioning_test_2010 FROM STDIN WITH CSV; --- see the data is loaded to shards (we should see 4 rows with same content) -SELECT * FROM partitioning_test WHERE id = 26 ORDER BY 1; - id | time | new_column -----+------------+------------ - 26 | 02-02-2010 | 26 - 26 | 02-02-2010 | 26 - 26 | 02-02-2010 | 26 - 26 | 02-02-2010 | 26 -(4 rows) - -ROLLBACK; --- see rollback is successful -SELECT * FROM partitioning_test WHERE id = 26 ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- DETACH and DROP in a transaction -BEGIN; -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2011; -DROP TABLE partitioning_test_2011; -COMMIT; --- see DROPed partitions content is not accessible -SELECT * FROM partitioning_test WHERE time >= '2011-01-01' AND time < '2012-01-01' ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- --- Misc tests --- --- test TRUNCATE --- test TRUNCATE partition -TRUNCATE partitioning_test_2012; --- see partition is TRUNCATEd -SELECT * FROM partitioning_test_2012 ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- test TRUNCATE partitioned table -TRUNCATE partitioning_test; --- see partitioned table is TRUNCATEd -SELECT * FROM partitioning_test ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- test DROP --- test DROP partition -INSERT INTO partitioning_test_2010 VALUES(27, '2010-02-01'); -DROP TABLE partitioning_test_2010; --- see DROPped partitions content is not accessible from partitioning_test; -SELECT * FROM partitioning_test WHERE time >= '2010-01-01' AND time < '2011-01-01' ORDER BY 1; - id | time | new_column -----+------+------------ -(0 rows) - --- test DROP partitioned table -DROP TABLE partitioning_test; -DROP TABLE partitioning_test_reference; --- dropping the parent should CASCADE to the children as well -SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'partitioning_test%' ORDER BY 1; - table_name -------------------------------- - partitioning_test_2009 - partitioning_test_failure - partitioning_test_foreign_key -(3 rows) - --- test distributing partitioned table colocated with non-partitioned table -CREATE TABLE partitioned_users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint) PARTITION BY RANGE (time); -CREATE TABLE partitioned_events_table (user_id int, time timestamp, event_type int, value_2 int, value_3 float, value_4 bigint) PARTITION BY RANGE (time); -SELECT create_distributed_table('partitioned_users_table', 'user_id', colocate_with => 'users_table'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('partitioned_events_table', 'user_id', colocate_with => 'events_table'); - create_distributed_table --------------------------- - -(1 row) - --- INSERT/SELECT from regular table to partitioned table -CREATE TABLE partitioned_users_table_2009 PARTITION OF partitioned_users_table FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); -CREATE TABLE partitioned_events_table_2009 PARTITION OF partitioned_events_table FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); -INSERT INTO partitioned_events_table SELECT * FROM events_table; -INSERT INTO partitioned_users_table_2009 SELECT * FROM users_table; --- --- Complex JOINs, subqueries, UNIONs etc... --- --- subquery with UNIONs on partitioned table -SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType -FROM - (SELECT *, random() - FROM - (SELECT - "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" - FROM - (SELECT - "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events - FROM( - (SELECT - "events"."user_id", "events"."time", 0 AS event - FROM - partitioned_events_table as "events" - WHERE - event_type IN (1, 2) ) - UNION - (SELECT - "events"."user_id", "events"."time", 1 AS event - FROM - partitioned_events_table as "events" - WHERE - event_type IN (3, 4) ) - UNION - (SELECT - "events"."user_id", "events"."time", 2 AS event - FROM - partitioned_events_table as "events" - WHERE - event_type IN (5, 6) ) - UNION - (SELECT - "events"."user_id", "events"."time", 3 AS event - FROM - partitioned_events_table as "events" - WHERE - event_type IN (1, 6))) t1 - GROUP BY "t1"."user_id") AS t) "q" -) AS final_query -GROUP BY types -ORDER BY types; - types | sumofeventtype --------+---------------- - 0 | 43 - 1 | 44 - 2 | 8 - 3 | 25 -(4 rows) - --- UNION and JOIN on both partitioned and regular tables -SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType -FROM - (SELECT - *, random() - FROM - (SELECT - "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" - FROM - (SELECT - "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events - FROM ( - (SELECT - * - FROM - (SELECT - "events"."time", 0 AS event, "events"."user_id" - FROM - partitioned_events_table as "events" - WHERE - event_type IN (1, 2)) events_subquery_1) - UNION - (SELECT * - FROM - ( - SELECT * FROM - ( - SELECT - max("events"."time"), - 0 AS event, - "events"."user_id" - FROM - events_table as "events", users_table as "users" - WHERE - events.user_id = users.user_id AND - event_type IN (1, 2) - GROUP BY "events"."user_id" - ) as events_subquery_5 - ) events_subquery_2) - UNION - (SELECT * - FROM - (SELECT - "events"."time", 2 AS event, "events"."user_id" - FROM - partitioned_events_table as "events" - WHERE - event_type IN (3, 4)) events_subquery_3) - UNION - (SELECT * - FROM - (SELECT - "events"."time", 3 AS event, "events"."user_id" - FROM - events_table as "events" - WHERE - event_type IN (5, 6)) events_subquery_4) - ) t1 - GROUP BY "t1"."user_id") AS t) "q" -INNER JOIN - (SELECT - "users"."user_id" - FROM - partitioned_users_table as "users" - WHERE - value_1 > 2 and value_1 < 5) AS t - ON (t.user_id = q.user_id)) as final_query -GROUP BY - types -ORDER BY - types; - types | sumofeventtype --------+---------------- - 0 | 367 - 2 | 360 - 3 | 57 -(3 rows) - --- test LIST partitioning -CREATE TABLE list_partitioned_events_table (user_id int, time date, event_type int, value_2 int, value_3 float, value_4 bigint) PARTITION BY LIST (time); -CREATE TABLE list_partitioned_events_table_2014_01_01_05 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-11-21', '2017-11-22', '2017-11-23', '2017-11-24', '2017-11-25'); -CREATE TABLE list_partitioned_events_table_2014_01_06_10 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-11-26', '2017-11-27', '2017-11-28', '2017-11-29', '2017-11-30'); -CREATE TABLE list_partitioned_events_table_2014_01_11_15 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-12-01', '2017-12-02', '2017-12-03', '2017-12-04', '2017-12-05'); --- test distributing partitioned table colocated with another partitioned table -SELECT create_distributed_table('list_partitioned_events_table', 'user_id', colocate_with => 'partitioned_events_table'); - create_distributed_table --------------------------- - -(1 row) - --- INSERT/SELECT from partitioned table to partitioned table -INSERT INTO - list_partitioned_events_table -SELECT - user_id, - date_trunc('day', time) as time, - event_type, - value_2, - value_3, - value_4 -FROM - events_table -WHERE - time >= '2017-11-21' AND - time <= '2017-12-01'; --- LEFT JOINs used with INNER JOINs on range partitioned table, list partitioned table and non-partitioned table -SELECT -count(*) AS cnt, "generated_group_field" - FROM - (SELECT - "eventQuery"."user_id", random(), generated_group_field - FROM - (SELECT - "multi_group_wrapper_1".*, generated_group_field, random() - FROM - (SELECT * - FROM - (SELECT - "list_partitioned_events_table"."time", "list_partitioned_events_table"."user_id" as event_user_id - FROM - list_partitioned_events_table as "list_partitioned_events_table" - WHERE - user_id > 2) "temp_data_queries" - INNER JOIN - (SELECT - "users"."user_id" - FROM - partitioned_users_table as "users" - WHERE - user_id > 2 and value_2 = 1) "user_filters_1" - ON ("temp_data_queries".event_user_id = "user_filters_1".user_id)) AS "multi_group_wrapper_1" - LEFT JOIN - (SELECT - "users"."user_id" AS "user_id", value_2 AS "generated_group_field" - FROM - partitioned_users_table as "users") "left_group_by_1" - ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" - GROUP BY - "generated_group_field" - ORDER BY - cnt DESC, generated_group_field ASC - LIMIT 10; - cnt | generated_group_field -------+----------------------- - 1851 | 1 - 1077 | 4 - 963 | 2 - 955 | 3 - 768 | 5 - 639 | 0 -(6 rows) - --- --- Additional partitioning features --- --- test multi column partitioning -CREATE TABLE multi_column_partitioning(c1 int, c2 int) PARTITION BY RANGE (c1, c2); -CREATE TABLE multi_column_partitioning_0_0_10_0 PARTITION OF multi_column_partitioning FOR VALUES FROM (0, 0) TO (10, 0); -SELECT create_distributed_table('multi_column_partitioning', 'c1'); - create_distributed_table --------------------------- - -(1 row) - --- test INSERT to multi-column partitioned table -INSERT INTO multi_column_partitioning VALUES(1, 1); -INSERT INTO multi_column_partitioning_0_0_10_0 VALUES(5, -5); --- test INSERT to multi-column partitioned table where no suitable partition exists -INSERT INTO multi_column_partitioning VALUES(10, 1); -ERROR: no partition of relation "multi_column_partitioning_1660101" found for row -DETAIL: Partition key of the failing row contains (c1, c2) = (10, 1). -CONTEXT: while executing command on localhost:57637 --- test with MINVALUE/MAXVALUE -CREATE TABLE multi_column_partitioning_10_max_20_min PARTITION OF multi_column_partitioning FOR VALUES FROM (10, MAXVALUE) TO (20, MINVALUE); --- test INSERT to partition with MINVALUE/MAXVALUE bounds -INSERT INTO multi_column_partitioning VALUES(11, -11); -INSERT INTO multi_column_partitioning_10_max_20_min VALUES(19, -19); --- test INSERT to multi-column partitioned table where no suitable partition exists -INSERT INTO multi_column_partitioning VALUES(20, -20); -ERROR: no partition of relation "multi_column_partitioning_1660101" found for row -DETAIL: Partition key of the failing row contains (c1, c2) = (20, -20). -CONTEXT: while executing command on localhost:57637 --- see data is loaded to multi-column partitioned table -SELECT * FROM multi_column_partitioning ORDER BY 1, 2; - c1 | c2 -----+----- - 1 | 1 - 5 | -5 - 11 | -11 - 19 | -19 -(4 rows) - --- --- Tests for locks on partitioned tables --- -CREATE TABLE partitioning_locks(id int, ref_id int, time date) PARTITION BY RANGE (time); --- create its partitions -CREATE TABLE partitioning_locks_2009 PARTITION OF partitioning_locks FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); -CREATE TABLE partitioning_locks_2010 PARTITION OF partitioning_locks FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); --- distribute partitioned table -SELECT create_distributed_table('partitioning_locks', 'id'); - create_distributed_table --------------------------- - -(1 row) - --- test locks on router SELECT -BEGIN; -SELECT * FROM partitioning_locks WHERE id = 1 ORDER BY 1, 2; - id | ref_id | time -----+--------+------ -(0 rows) - -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+----------------- - partitioning_locks | relation | AccessShareLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2010 | relation | AccessShareLock -(3 rows) - -COMMIT; --- test locks on real-time SELECT -BEGIN; -SELECT * FROM partitioning_locks ORDER BY 1, 2; - id | ref_id | time -----+--------+------ -(0 rows) - -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+----------------- - partitioning_locks | relation | AccessShareLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2010 | relation | AccessShareLock -(3 rows) - -COMMIT; --- test locks on task-tracker SELECT -SET citus.task_executor_type TO 'task-tracker'; -BEGIN; -SELECT * FROM partitioning_locks AS pl1 JOIN partitioning_locks AS pl2 ON pl1.id = pl2.ref_id ORDER BY 1, 2; - id | ref_id | time | id | ref_id | time -----+--------+------+----+--------+------ -(0 rows) - -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+----------------- - partitioning_locks | relation | AccessShareLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2010 | relation | AccessShareLock -(3 rows) - -COMMIT; -RESET citus.task_executor_type; --- test locks on INSERT -BEGIN; -INSERT INTO partitioning_locks VALUES(1, 1, '2009-01-01'); -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | RowExclusiveLock -(6 rows) - -COMMIT; --- test locks on UPDATE -BEGIN; -UPDATE partitioning_locks SET time = '2009-02-01' WHERE id = 1; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | RowExclusiveLock -(6 rows) - -COMMIT; --- test locks on DELETE -BEGIN; -DELETE FROM partitioning_locks WHERE id = 1; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | RowExclusiveLock -(6 rows) - -COMMIT; --- test locks on INSERT/SELECT -CREATE TABLE partitioning_locks_for_select(id int, ref_id int, time date); -SELECT create_distributed_table('partitioning_locks_for_select', 'id'); - create_distributed_table --------------------------- - -(1 row) - -BEGIN; -INSERT INTO partitioning_locks SELECT * FROM partitioning_locks_for_select; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | RowExclusiveLock - partitioning_locks_for_select | relation | AccessShareLock -(7 rows) - -COMMIT; --- test locks on coordinator INSERT/SELECT -BEGIN; -INSERT INTO partitioning_locks SELECT * FROM partitioning_locks_for_select LIMIT 5; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | RowExclusiveLock - partitioning_locks_for_select | relation | AccessShareLock -(5 rows) - -COMMIT; --- test locks on multi-shard UPDATE -BEGIN; -UPDATE partitioning_locks SET time = '2009-03-01'; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+------------------ - partitioning_locks | relation | AccessShareLock - partitioning_locks | relation | RowExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | RowExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | RowExclusiveLock -(6 rows) - -COMMIT; --- test locks on DDL -BEGIN; -ALTER TABLE partitioning_locks ADD COLUMN new_column int; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+--------------------- - partitioning_locks | relation | AccessExclusiveLock - partitioning_locks | relation | AccessShareLock - partitioning_locks_2009 | relation | AccessExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2010 | relation | AccessExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock -(6 rows) - -COMMIT; --- test locks on TRUNCATE -BEGIN; -TRUNCATE partitioning_locks; -SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; - relation | locktype | mode --------------------------+----------+--------------------- - partitioning_locks | relation | AccessExclusiveLock - partitioning_locks | relation | AccessShareLock - partitioning_locks_2009 | relation | AccessExclusiveLock - partitioning_locks_2009 | relation | AccessShareLock - partitioning_locks_2009 | relation | ShareLock - partitioning_locks_2010 | relation | AccessExclusiveLock - partitioning_locks_2010 | relation | AccessShareLock - partitioning_locks_2010 | relation | ShareLock -(8 rows) - -COMMIT; --- test shard resource locks with multi-shard UPDATE -BEGIN; -UPDATE partitioning_locks_2009 SET time = '2009-03-01'; --- see the locks on parent table -SELECT - logicalrelid, - locktype, - mode -FROM - pg_locks AS l JOIN pg_dist_shard AS s -ON - l.objid = s.shardid -WHERE - logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND - pid = pg_backend_pid() -ORDER BY - 1, 2, 3; - logicalrelid | locktype | mode --------------------------+----------+-------------------------- - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock -(12 rows) - -COMMIT; --- test shard resource locks with TRUNCATE -BEGIN; -TRUNCATE partitioning_locks_2009; --- see the locks on parent table -SELECT - logicalrelid, - locktype, - mode -FROM - pg_locks AS l JOIN pg_dist_shard AS s -ON - l.objid = s.shardid -WHERE - logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND - pid = pg_backend_pid() -ORDER BY - 1, 2, 3; - logicalrelid | locktype | mode --------------------------+----------+----------- - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock -(4 rows) - -COMMIT; --- test shard resource locks with INSERT/SELECT -BEGIN; -INSERT INTO partitioning_locks_2009 SELECT * FROM partitioning_locks WHERE time >= '2009-01-01' AND time < '2010-01-01'; --- see the locks on parent table -SELECT - logicalrelid, - locktype, - mode -FROM - pg_locks AS l JOIN pg_dist_shard AS s -ON - l.objid = s.shardid -WHERE - logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND - pid = pg_backend_pid() -ORDER BY - 1, 2, 3; - logicalrelid | locktype | mode --------------------------+----------+-------------------------- - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock - partitioning_locks_2009 | advisory | ShareUpdateExclusiveLock -(12 rows) - -COMMIT; --- test partition-wise join -CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); -CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); -CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); -CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); -SELECT create_distributed_table('partitioning_hash_join_test', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------- - t - t -(2 rows) - -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=57637 dbname=regression - -> Gather - Workers Planned: 2 - -> Parallel Hash Join - Hash Cond: ((partitioning_hash_join_test.id = partitioning_hash_test_1.id) AND (partitioning_hash_join_test.subid = partitioning_hash_test_1.subid)) - -> Parallel Append - -> Parallel Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test - -> Parallel Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_1 - -> Parallel Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_2 - -> Parallel Hash - -> Parallel Append - -> Parallel Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_1 - -> Parallel Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test - -> Parallel Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_2 -(18 rows) - --- set partition-wise join on -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------- - t - t -(2 rows) - -SET enable_partitionwise_join TO on; -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=57637 dbname=regression - -> Append - -> Hash Join - Hash Cond: ((partitioning_hash_join_test.id = partitioning_hash_test.id) AND (partitioning_hash_join_test.subid = partitioning_hash_test.subid)) - -> Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test - -> Hash - -> Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test - -> Hash Join - Hash Cond: ((partitioning_hash_test_1.id = partitioning_hash_join_test_1.id) AND (partitioning_hash_test_1.subid = partitioning_hash_join_test_1.subid)) - -> Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_1 - -> Hash - -> Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_1 - -> Hash Join - Hash Cond: ((partitioning_hash_join_test_2.id = partitioning_hash_test_2.id) AND (partitioning_hash_join_test_2.subid = partitioning_hash_test_2.subid)) - -> Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_2 - -> Hash - -> Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_2 -(21 rows) - --- note that partition-wise joins only work when partition key is in the join --- following join does not have that, therefore join will not be pushed down to --- partitions -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); - QUERY PLAN ---------------------------------------------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=57637 dbname=regression - -> Hash Join - Hash Cond: (partitioning_hash_join_test.id = partitioning_hash_test.id) - -> Append - -> Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test - -> Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_1 - -> Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_2 - -> Hash - -> Append - -> Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test - -> Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_1 - -> Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_2 -(16 rows) - --- reset partition-wise join -SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); - success ---------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------- - t - t -(2 rows) - -RESET enable_partitionwise_join; -DROP TABLE -IF EXISTS - partitioning_test_2009, - partitioned_events_table, - partitioned_users_table, - list_partitioned_events_table, - multi_column_partitioning, - partitioning_locks, - partitioning_locks_for_select; --- make sure we can create a partitioned table with streaming replication -SET citus.replication_model TO 'streaming'; -CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); -CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); -SELECT create_distributed_table('partitioning_test', 'id'); - create_distributed_table --------------------------- - -(1 row) - -DROP TABLE partitioning_test; --- make sure we can attach partitions to a distributed table in a schema -CREATE SCHEMA partitioning_schema; -CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); -SELECT create_distributed_table('partitioning_schema."schema-test"', 'id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE partitioning_schema."schema-test_2009"(id int, time date); -ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITION partitioning_schema."schema-test_2009" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); --- attached partition is distributed as well -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -ORDER BY 1; - logicalrelid ----------------------------------------- - partitioning_schema."schema-test" - partitioning_schema."schema-test_2009" -(2 rows) - -SELECT - logicalrelid, count(*) -FROM - pg_dist_shard -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count -----------------------------------------+------- - partitioning_schema."schema-test" | 4 - partitioning_schema."schema-test_2009" | 4 -(2 rows) - -DROP TABLE partitioning_schema."schema-test"; --- make sure we can create partition of a distributed table in a schema -CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); -SELECT create_distributed_table('partitioning_schema."schema-test"', 'id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF partitioning_schema."schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); --- newly created partition is distributed as well -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -ORDER BY 1; - logicalrelid ----------------------------------------- - partitioning_schema."schema-test" - partitioning_schema."schema-test_2009" -(2 rows) - -SELECT - logicalrelid, count(*) -FROM - pg_dist_shard -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count -----------------------------------------+------- - partitioning_schema."schema-test" | 4 - partitioning_schema."schema-test_2009" | 4 -(2 rows) - -DROP TABLE partitioning_schema."schema-test"; --- make sure creating partitioned tables works while search_path is set -CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); -SET search_path = partitioning_schema; -SELECT create_distributed_table('"schema-test"', 'id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF "schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); --- newly created partition is distributed as well -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -ORDER BY 1; - logicalrelid --------------------- - "schema-test" - "schema-test_2009" -(2 rows) - -SELECT - logicalrelid, count(*) -FROM - pg_dist_shard -WHERE - logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) -GROUP BY - logicalrelid -ORDER BY - 1,2; - logicalrelid | count ---------------------+------- - "schema-test" | 4 - "schema-test_2009" | 4 -(2 rows) - --- test we don't deadlock when attaching and detaching partitions from partitioned --- tables with foreign keys -CREATE TABLE reference_table(id int PRIMARY KEY); -SELECT create_reference_table('reference_table'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE reference_table_2(id int PRIMARY KEY); -SELECT create_reference_table('reference_table_2'); - create_reference_table ------------------------- - -(1 row) - -CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); -CREATE TABLE partitioning_test_2008 PARTITION OF partitioning_test FOR VALUES FROM ('2008-01-01') TO ('2009-01-01'); -CREATE TABLE partitioning_test_2009 (LIKE partitioning_test); -CREATE TABLE partitioning_test_2010 (LIKE partitioning_test); -CREATE TABLE partitioning_test_2011 (LIKE partitioning_test); --- distributing partitioning_test will also distribute partitioning_test_2008 -SELECT create_distributed_table('partitioning_test', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('partitioning_test_2009', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('partitioning_test_2010', 'id'); - create_distributed_table --------------------------- - -(1 row) - -SELECT create_distributed_table('partitioning_test_2011', 'id'); - create_distributed_table --------------------------- - -(1 row) - -ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_reference_fkey - FOREIGN KEY (id) REFERENCES reference_table(id) ON DELETE CASCADE; -ALTER TABLE partitioning_test_2009 ADD CONSTRAINT partitioning_reference_fkey_2009 - FOREIGN KEY (id) REFERENCES reference_table(id) ON DELETE CASCADE; -INSERT INTO partitioning_test_2010 VALUES (1, '2010-02-01'); --- This should fail because of foreign key constraint violation -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2010 - FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); -ERROR: insert or update on table "partitioning_test_2010_1660191" violates foreign key constraint "partitioning_reference_fkey_1660179" -DETAIL: Key (id)=(1) is not present in table "reference_table_1660177". -CONTEXT: while executing command on localhost:57637 --- Truncate, so attaching again won't fail -TRUNCATE partitioning_test_2010; --- Attach a table which already has the same constraint -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2009 - FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); --- Attach a table which doesn't have the constraint -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2010 - FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); --- Attach a table which has a different constraint -ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2011 - FOR VALUES FROM ('2011-01-01') TO ('2012-01-01'); -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2008; -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2009; -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2010; -ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2011; -DROP TABLE partitioning_test, partitioning_test_2008, partitioning_test_2009, - partitioning_test_2010, partitioning_test_2011, - reference_table, reference_table_2; -DROP SCHEMA partitioning_schema CASCADE; -NOTICE: drop cascades to table "schema-test" -RESET SEARCH_PATH; -DROP TABLE IF EXISTS - partitioning_hash_test, - partitioning_hash_join_test, - partitioning_test_failure, - non_distributed_partitioned_table, - partitioning_test_foreign_key; diff --git a/src/test/regress/expected/multi_subquery_window_functions.out b/src/test/regress/expected/multi_subquery_window_functions.out index 7c247a68b..b239f06f2 100644 --- a/src/test/regress/expected/multi_subquery_window_functions.out +++ b/src/test/regress/expected/multi_subquery_window_functions.out @@ -716,7 +716,7 @@ EXPLAIN (COSTS FALSE, VERBOSE TRUE) -> Sort Output: remote_scan.user_id, remote_scan.sum Sort Key: remote_scan.sum DESC, remote_scan.user_id DESC - -> Custom Scan (Citus Real-Time) + -> Custom Scan (Citus Adaptive) Output: remote_scan.user_id, remote_scan.sum Task Count: 4 Tasks Shown: One of 4 diff --git a/src/test/regress/expected/with_transactions.out b/src/test/regress/expected/with_transactions.out index a1a601665..9387b558c 100644 --- a/src/test/regress/expected/with_transactions.out +++ b/src/test/regress/expected/with_transactions.out @@ -1,6 +1,7 @@ CREATE SCHEMA with_transactions; SET search_path TO with_transactions, public; SET citus.shard_count TO 4; +SET citus.shard_replication_factor TO 1; -- https://github.com/citusdata/citus/issues/3061 SET citus.next_placement_id TO 800000; CREATE TABLE with_transactions.raw_table (tenant_id int, income float, created_at timestamptz); SELECT create_distributed_table('raw_table', 'tenant_id'); @@ -82,18 +83,17 @@ WITH ids_inserted AS UPDATE raw_table SET created_at = '2001-02-10 20:00:00' WHERE tenant_id IN (SELECT tenant_id FROM ids_inserted); DEBUG: generating subplan 12_1 for CTE ids_inserted: INSERT INTO with_transactions.raw_table (tenant_id, income, created_at) VALUES (11,1000,now()), (12,1000,now()), (13,1000,now()) RETURNING raw_table.tenant_id DEBUG: Plan 12 query after replacing subqueries and CTEs: UPDATE with_transactions.raw_table SET created_at = 'Sat Feb 10 20:00:00 2001 PST'::timestamp with time zone WHERE (tenant_id OPERATOR(pg_catalog.=) ANY (SELECT ids_inserted.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('12_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) ids_inserted)) -ERROR: cannot establish a new connection for placement 800007, since DML has been executed on a connection that is in use -- make sure that everything committed SELECT count(*) FROM raw_table; count ------- - 102 + 105 (1 row) SELECT count(*) FROM raw_table WHERE created_at = '2001-02-10 20:00:00'; count ------- - 1 + 4 (1 row) SELECT count(*) FROM second_raw_table; diff --git a/src/test/regress/expected/with_transactions_9.out b/src/test/regress/expected/with_transactions_9.out deleted file mode 100644 index 9387b558c..000000000 --- a/src/test/regress/expected/with_transactions_9.out +++ /dev/null @@ -1,126 +0,0 @@ -CREATE SCHEMA with_transactions; -SET search_path TO with_transactions, public; -SET citus.shard_count TO 4; -SET citus.shard_replication_factor TO 1; -- https://github.com/citusdata/citus/issues/3061 -SET citus.next_placement_id TO 800000; -CREATE TABLE with_transactions.raw_table (tenant_id int, income float, created_at timestamptz); -SELECT create_distributed_table('raw_table', 'tenant_id'); - create_distributed_table --------------------------- - -(1 row) - -CREATE TABLE with_transactions.second_raw_table (tenant_id int, income float, created_at timestamptz); -SELECT create_distributed_table('second_raw_table', 'tenant_id'); - create_distributed_table --------------------------- - -(1 row) - -INSERT INTO - raw_table (tenant_id, income, created_at) -SELECT - i % 10, i * 10.0, timestamp '2014-01-10 20:00:00' + i * interval '1 day' -FROM - generate_series (0, 100) i; -INSERT INTO second_raw_table SELECT * FROM raw_table; -SET client_min_messages TO DEBUG1; --- run a transaction which DELETE -BEGIN; - WITH ids_to_delete AS - ( - SELECT tenant_id FROM raw_table WHERE income < 250 - ), - deleted_ids AS - ( - DELETE FROM raw_table WHERE created_at < '2014-02-10 20:00:00' AND tenant_id IN (SELECT * from ids_to_delete) RETURNING tenant_id - ) - UPDATE raw_table SET income = income * 2 WHERE tenant_id IN (SELECT tenant_id FROM deleted_ids); -DEBUG: generating subplan 3_1 for CTE ids_to_delete: SELECT tenant_id FROM with_transactions.raw_table WHERE (income OPERATOR(pg_catalog.<) (250)::double precision) -DEBUG: generating subplan 3_2 for CTE deleted_ids: DELETE FROM with_transactions.raw_table WHERE ((created_at OPERATOR(pg_catalog.<) 'Mon Feb 10 20:00:00 2014 PST'::timestamp with time zone) AND (tenant_id OPERATOR(pg_catalog.=) ANY (SELECT ids_to_delete.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('3_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) ids_to_delete))) RETURNING tenant_id -DEBUG: Plan 3 query after replacing subqueries and CTEs: UPDATE with_transactions.raw_table SET income = (income OPERATOR(pg_catalog.*) (2)::double precision) WHERE (tenant_id OPERATOR(pg_catalog.=) ANY (SELECT deleted_ids.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('3_2'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) deleted_ids)) -ROLLBACK; --- see that both UPDATE and DELETE commands are rollbacked -SELECT count(*) FROM raw_table; - count -------- - 101 -(1 row) - -SELECT max(income) FROM raw_table; - max ------- - 1000 -(1 row) - --- multi-statement multi shard modifying statements should work -BEGIN; - SELECT count (*) FROM second_raw_table; - count -------- - 101 -(1 row) - - WITH distinct_count AS ( - SELECT count(DISTINCT created_at) FROM raw_table - ), - ids_inserted AS - ( - INSERT INTO raw_table VALUES (11, 1000, now()) RETURNING tenant_id - ) - UPDATE raw_table SET created_at = '2001-02-10 20:00:00' - WHERE tenant_id IN (SELECT tenant_id FROM ids_inserted) AND tenant_id < (SELECT count FROM distinct_count); -DEBUG: generating subplan 9_1 for CTE distinct_count: SELECT count(DISTINCT created_at) AS count FROM with_transactions.raw_table -DEBUG: generating subplan 9_2 for CTE ids_inserted: INSERT INTO with_transactions.raw_table (tenant_id, income, created_at) VALUES (11, 1000, now()) RETURNING tenant_id -DEBUG: Plan 9 query after replacing subqueries and CTEs: UPDATE with_transactions.raw_table SET created_at = 'Sat Feb 10 20:00:00 2001 PST'::timestamp with time zone WHERE ((tenant_id OPERATOR(pg_catalog.=) ANY (SELECT ids_inserted.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('9_2'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) ids_inserted)) AND (tenant_id OPERATOR(pg_catalog.<) (SELECT distinct_count.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('9_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) distinct_count))) - TRUNCATE second_raw_table; -COMMIT; --- sequential insert followed by parallel update works just fine -WITH ids_inserted AS -( - INSERT INTO raw_table VALUES (11, 1000, now()), (12, 1000, now()), (13, 1000, now()) RETURNING tenant_id -) -UPDATE raw_table SET created_at = '2001-02-10 20:00:00' WHERE tenant_id IN (SELECT tenant_id FROM ids_inserted); -DEBUG: generating subplan 12_1 for CTE ids_inserted: INSERT INTO with_transactions.raw_table (tenant_id, income, created_at) VALUES (11,1000,now()), (12,1000,now()), (13,1000,now()) RETURNING raw_table.tenant_id -DEBUG: Plan 12 query after replacing subqueries and CTEs: UPDATE with_transactions.raw_table SET created_at = 'Sat Feb 10 20:00:00 2001 PST'::timestamp with time zone WHERE (tenant_id OPERATOR(pg_catalog.=) ANY (SELECT ids_inserted.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('12_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) ids_inserted)) --- make sure that everything committed -SELECT count(*) FROM raw_table; - count -------- - 105 -(1 row) - -SELECT count(*) FROM raw_table WHERE created_at = '2001-02-10 20:00:00'; - count -------- - 4 -(1 row) - -SELECT count(*) FROM second_raw_table; - count -------- - 0 -(1 row) - --- sequential insert followed by a sequential real-time query should be fine -BEGIN; -SET LOCAL citus.multi_shard_modify_mode TO 'sequential'; -WITH ids_inserted AS -( - INSERT INTO raw_table (tenant_id) VALUES (11), (12), (13), (14) RETURNING tenant_id -) -SELECT income FROM second_raw_table WHERE tenant_id IN (SELECT * FROM ids_inserted) ORDER BY 1 DESC LIMIT 3; -DEBUG: generating subplan 17_1 for CTE ids_inserted: INSERT INTO with_transactions.raw_table (tenant_id) VALUES (11), (12), (13), (14) RETURNING raw_table.tenant_id -DEBUG: Plan 17 query after replacing subqueries and CTEs: SELECT income FROM with_transactions.second_raw_table WHERE (tenant_id OPERATOR(pg_catalog.=) ANY (SELECT ids_inserted.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('17_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) ids_inserted)) ORDER BY income DESC LIMIT 3 -DEBUG: push down of limit count: 3 - income --------- -(0 rows) - -ROLLBACK; -RESET client_min_messages; -RESET citus.shard_count; -DROP SCHEMA with_transactions CASCADE; -NOTICE: drop cascades to 2 other objects -DETAIL: drop cascades to table raw_table -drop cascades to table second_raw_table diff --git a/src/test/regress/sql/local_shard_execution.sql b/src/test/regress/sql/local_shard_execution.sql index 1aea11abc..e6f7d11ee 100644 --- a/src/test/regress/sql/local_shard_execution.sql +++ b/src/test/regress/sql/local_shard_execution.sql @@ -541,66 +541,6 @@ BEGIN; ROLLBACK; --- mix with other executors should fail - --- router modify execution should error -BEGIN; - DELETE FROM distributed_table WHERE key = 500; - - SET LOCAL citus.task_executor_type = 'real-time'; - - DELETE FROM distributed_table; -ROLLBACK; - --- local execution should not be executed locally --- becase a multi-shard router query has already been executed -BEGIN; - - SET LOCAL citus.task_executor_type = 'real-time'; - - DELETE FROM distributed_table; - - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; - --- router select execution -BEGIN; - DELETE FROM distributed_table WHERE key = 500; - - SET LOCAL citus.task_executor_type = 'real-time'; - - SELECT count(*) FROM distributed_table WHERE key = 500; -ROLLBACK; - --- local execution should not be executed locally --- becase a single-shard router query has already been executed -BEGIN; - SET LOCAL citus.task_executor_type = 'real-time'; - - SELECT count(*) FROM distributed_table WHERE key = 500; - - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; - --- real-time select execution -BEGIN; - DELETE FROM distributed_table WHERE key = 500; - - SET LOCAL citus.task_executor_type = 'real-time'; - - SELECT count(*) FROM distributed_table; -ROLLBACK; - --- local execution should not be executed locally --- becase a real-time query has already been executed -BEGIN; - SET LOCAL citus.task_executor_type = 'real-time'; - - SELECT count(*) FROM distributed_table; - - DELETE FROM distributed_table WHERE key = 500; -ROLLBACK; - -- task-tracker select execution BEGIN; DELETE FROM distributed_table WHERE key = 500;