citusdata / citusdata/citus

Nested multi-shard commands might fail

Open
#4,076 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

While working on #4034, we considered cases where a COPY command might nest another call other COPY commands (or any other command basically). I traced back to 9.2, and I can reproduce until there.

It turns out we have some other issues around it:
```SQL
CREATE TABLE colocated_test_table (a int);
SELECT create_distributed_table('colocated_test_table', 'a');
INSERT INTO colocated_test_table SELECT * FROM generate_series(0,100)i;

CREATE OR REPLACE FUNCTION distributed_insert_select(out result bigint)
AS $$ WITH cte_1 AS (INSERT INTO colocated_test_table SELECT * FROM colocated_test_table LIMIT 100 OFFSET 0 RETURNING *) SELECT count(*) FROM cte_1;$$
LANGUAGE SQL;

-- MX needed to allow create_distributed_function succeed
SELECT start_metadata_sync_to_node(nodename, nodeport) FROM pg_dist_node;
SELECT create_distributed_function('distributed_insert_select()');

CREATE TABLE nested_copy_test (key int, value int DEFAULT distributed_insert_select());
SELECT create_distributed_table('nested_copy_test', 'key');

COPY nested_copy_test(key) FROM PROGRAM 'seq 32';
ERROR: connection to the remote node localhost:9701 failed with the following error: another command is already in progress
CONTEXT: SQL function "distributed_insert_select" statement 1
COPY nested_copy_test, line 2: "2"

INSERT INTO nested_copy_test (key) SELECT * FROM generate_series(0,10);
ERROR: connection to the remote node localhost:9701 failed with the following error: another command is already in progress
CONTEXT: SQL function "distributed_insert_select" statement 1

-- single command operations seems to work
INSERT INTO nested_copy_test (key) VALUES (1);
INSERT 0 1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.