ClickHouse / ClickHouse/ClickHouse

Wrong result when combining WHERE and ARRAY JOIN

Open
#69,510 3 comments 0 reactions 0 assignees View on GitHub
comp-query-analyzer external unexpected behaviour
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

With clickhouse 23.8 and 24.8.

Let select an array and transposte it.

We get this result

```sql
SELECT rowNumberInAllBlocks() AS bid
FROM
(
SELECT
['a', 'b', 'c'] AS array,
'x' AS scalar
)
ARRAY JOIN array AS element

Query id: 3805dcc5-49ac-4ca9-9c59-0e41c25c1e94

┌─bid─┐
1. │ 0 │
2. │ 0 │
3. │ 0 │
└─────┘
```

Then let add a filter that would select some line from the previous result.

```sql
SELECT rowNumberInAllBlocks() AS bid
FROM
(
SELECT
['a', 'b', 'c'] AS array,
'x' AS scalar
)
ARRAY JOIN array AS element
WHERE scalar IN ('x', 'y', 'z')

Query id: 50d79bb3-d03d-46b8-b563-7745f34bc011

┌─bid─┐
1. │ 0 │
2. │ 0 │
3. │ 0 │
└─────┘
```

it return the expected result, but when filtering on a transposed element of the array :

```sql
SELECT rowNumberInAllBlocks() AS bid
FROM
(
SELECT
['a', 'b', 'c'] AS array,
'x' AS scalar
)
ARRAY JOIN array AS element
WHERE element IN ('a', 'b', 'c')

Query id: 3805dcc5-49ac-4ca9-9c59-0e41c25c1e94

┌─bid─┐
1. │ 0 │
2. │ 1 │
3. │ 2 │
└─────┘
```

But as you can see where we would expect the same result than the first query because the filter is actually filering nothing it return un expected result, because the usage of the array in the filter modify when the function is called.

I try with `allow_experimental_analyser` 1 and 0 it give the same result.

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.