Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALIAS column can't be used as right table key in JOIN #24395

Closed
UnamedRus opened this issue May 21, 2021 · 0 comments · Fixed by #62185
Closed

ALIAS column can't be used as right table key in JOIN #24395

UnamedRus opened this issue May 21, 2021 · 0 comments · Fixed by #62185
Labels
bug Confirmed user-visible misbehaviour in official release comp-joins JOINs st-hold We've paused the work on issue for some reason

Comments

@UnamedRus
Copy link
Contributor

You have to provide the following information whenever possible.

Does it reproduce on recent release?
Yes

How to reproduce
Clickhouse 21.6

CREATE TABLE xxxx_yyy (key UInt32, key_b ALIAS key) ENGINE=MergeTree() ORDER BY key;
INSERT INTO xxxx_yyy SELECT number FROM numbers(10);


SELECT *
FROM xxxx_yyy AS a
INNER JOIN xxxx_yyy AS b ON a.key_b = b.key

Query id: f56b09d9-2d8a-46a8-bfae-3da08f38d704

┌─key─┬─b.key─┐
│   0 │     0 │
│   1 │     1 │
│   2 │     2 │
│   3 │     3 │
│   4 │     4 │
│   5 │     5 │
│   6 │     6 │
│   7 │     7 │
│   8 │     8 │
│   9 │     9 │
└─────┴───────┘


SELECT *
FROM xxxx_yyy AS a
INNER JOIN xxxx_yyy AS b ON a.key = b.key_b

Query id: 540ad3a6-e857-4b7e-baa5-08d55de57bd2


0 rows in set. Elapsed: 0.003 sec.

Received exception from server (version 21.6.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'b.key_b' while processing query: 'SELECT key, b.key FROM xxxx_yyy AS a ALL INNER JOIN xxxx_yyy AS b ON key = b.key_b', required columns: 'key' 'b.key' 'b.key_b', maybe you meant: ['key'], joined columns: 'b.key'.


SELECT *
FROM xxxx_yyy AS a
INNER JOIN
(
    SELECT
        *,
        key_b
    FROM xxxx_yyy
) AS b ON a.key = b.key_b

Query id: 5f2a065d-549d-4cde-8cc5-9a409861c699

┌─key─┬─b.key─┬─b.key_b─┐
│   0 │     0 │       0 │
│   1 │     1 │       1 │
│   2 │     2 │       2 │
│   3 │     3 │       3 │
│   4 │     4 │       4 │
│   5 │     5 │       5 │
│   6 │     6 │       6 │
│   7 │     7 │       7 │
│   8 │     8 │       8 │
│   9 │     9 │       9 │
└─────┴───────┴─────────┘

10 rows in set. Elapsed: 0.003 sec.
@UnamedRus UnamedRus added the bug Confirmed user-visible misbehaviour in official release label May 21, 2021
@vdimir vdimir added the comp-joins JOINs label May 24, 2021
@alexey-milovidov alexey-milovidov added the st-hold We've paused the work on issue for some reason label Jul 3, 2021
fm4v added a commit that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release comp-joins JOINs st-hold We've paused the work on issue for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants