citusdata / citusdata/citus

NeedsDistributedPlanning might fail to properly handle unused ctes

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

Description

```SQL
CREATE TABLE dist (a int);
SELECT create_distributed_table('dist', 'a');

CREATE TABLE local (user_id int, time timestamp with time zone);
INSERT INTO local VALUES (1, '2018-04-13 00:01:00+00');

-- the plan is weird
EXPLAIN
WITH cte_unused AS (SELECT * FROM dist)
INSERT INTO local SELECT * FROM local;
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY PLAN │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Insert on local (cost=0.00..0.00 rows=0 width=0) │
│ -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=12) │
│ -> Distributed Subplan 16_1 │
│ -> Seq Scan on local (cost=0.00..30.40 rows=2040 width=12) │
│ Task Count: 1 │
│ Tasks Shown: All │
│ -> Task │
│ Node: host=localhost port=5432 dbname=postgres │
│ -> Function Scan on read_intermediate_result intermediate_result (cost=0.00..10.00 rows=1000 width=12) │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(9 rows)
```

NeedsDistributedPlanning() decides it needs distributed planning, which shouldn't

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.