citusdata / citusdata/citus

Intermediate results that should be locally written may be written via remote copy

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

Description

Subplan execution is capable of writing results locally to a file. However, in some cases, it still uses remote COPY over directly writing into the file. I have not measure the overhead, but may not be negligible (e.g., writing directly to the file should be more performant)

In single node Citus experience, all the intermediate results fall under this bucket.

```SQL
-- unnecessary COPY over network
SELECT 1 FROM master_add_node('localhost', 5432, groupid => 0);
SELECT 1 FROM master_set_node_property('localhost', 5432, 'shouldhaveshards', true);

CREATE TABLE test(x int PRIMARY KEY, y int);
SELECT create_distributed_table('test','x');

set client_min_messages TO DEBUG1;

SET citus.log_intermediate_results TO TRUE;

-- Case 1: as expected, the subplan is written to local file
postgres=# WITH cte_1 AS (SELECT * FROM test ORDER BY 1 DESC LIMIT 5)
SELECT count(*) FROM cte_1;
DEBUG: CTE cte_1 is going to be inlined via distributed planning
DEBUG: push down of limit count: 5
DEBUG: generating subplan 8_1 for subquery SELECT x, y FROM public.test ORDER BY x DESC LIMIT 5
DEBUG: Plan 8 query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('8_1'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) cte_1
DEBUG: Subplan 8_1 will be written to local file
count
-------
0
(1 row)

-- Case 2: contrary to the expectations, the subplan is NOT written to local file
WITH cte_1 AS (SELECT * FROM test ORDER BY 1 DESC LIMIT 5)
SELECT count(*) FROM test JOIN cte_1 USING (x);
DEBUG: CTE cte_1 is going to be inlined via distributed planning
DEBUG: push down of limit count: 5
DEBUG: generating subplan 8_1 for subquery SELECT x, y FROM public.test ORDER BY x DESC LIMIT 5
DEBUG: Plan 8 query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (public.test JOIN (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('8_1'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) cte_1 USING (x))
DEBUG: Subplan 8_1 will be sent to localhost:5432
count
-------
0
(1 row)
```

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.