citusdata / citusdata/citus

Local-dist join `prefer-distributed` errors out

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

Description

The following query errors out with `prefer-distributed`:

```sql
SELECT
count(*)
FROM
distributed
JOIN LATERAL
(SELECT
*
FROM
local
JOIN
distributed d2
ON(true)
WHERE local.id = distributed.id AND d2.id = local.id) as foo
ON (true);
ERROR: direct joins between distributed and local tables are not supported
```

schema:

```sql

CREATE TABLE distributed (key int, id bigserial PRIMARY KEY,
name text,
created_at timestamptz DEFAULT now(), b int);
CREATE TABLE reference (a int, id bigserial PRIMARY KEY,
title text, b int);

CREATE TABLE local (key int, id bigserial PRIMARY KEY, key2 int,
title text, key3 int);

-- drop columns so that we test the correctness in different scenarios.
ALTER TABLE local DROP column key;
ALTER TABLE local DROP column key2;
ALTER TABLE local DROP column key3;

ALTER TABLE distributed DROP column key;
ALTER TABLE reference DROP column b;

-- these above restrictions brought us to the following schema
SELECT create_reference_table('reference');
SELECT create_distributed_table('distributed', 'id');
SELECT citus_add_local_table_to_metadata('local');

ALTER TABLE distributed DROP column b;
ALTER TABLE reference DROP column a;
```

`prefer-distributed` should choose local tables as a fallback mechanism in case there is going to be an error and the same query works fine with `auto` mode.

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.