Skip to content

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

Closed

Description

@UnamedRus

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.

Activity

  1. added
    bug
    on May 21, 2021
  2. added
    comp-joins
    on May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcomp-joins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions