SELECT EXISTS is extremely inefficient
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
This is meant to be an O(1) operation in Postgres, but it is an O(N) operation in Citus:
```sql
explain select exists (select 1 from test);
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY PLAN │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) │
│ -> Distributed Subplan 3_1 │
│ -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=4) │
│ Task Count: 40 │
│ Tasks Shown: One of 40 │
│ -> Task │
│ Node: host=localhost port=1301 dbname=postgres │
│ -> Seq Scan on test_102008 test (cost=0.00..30.40 rows=2040 width=4) │
│ Task Count: 1 │
│ Tasks Shown: All │
│ -> Task │
│ Node: host=localhost port=1300 dbname=postgres │
│ -> Result (cost=0.01..0.02 rows=1 width=1) │
│ InitPlan 1 (returns $0) │
│ -> Function Scan on read_intermediate_result intermediate_result (cost=0.00..10.00 rows=1000 width=0) │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(15 rows)
```
Contributor guide
Assessment
This issue has not been assessed yet.