Repository navigation
Closed
Labels
bugConfirmed user-visible misbehaviour in official releasecomp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...
Description
Is there a way to make filtering by right table materialized columns on join?
How to reproduce
Latest lts version
ClickHouse client version 20.3.15.133 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.3.15 revision 54433.
Queries for reproduce
CREATE TABLE test1 (time DateTime, foo String, dimension_1 String, dt Date MATERIALIZED toDate(time)) ENGINE = MergeTree() PARTITION BY toYYYYMM(dt) ORDER BY (dt, foo);
CREATE TABLE test2 (time DateTime, bar String, dimension_2 String, dt Date MATERIALIZED toDate(time)) ENGINE = MergeTree() PARTITION BY toYYYYMM(dt) ORDER BY (dt, bar);
INSERT INTO test1 VALUES ('2020-01-01 12:00:00', 'fact1', 'test1_val1'), ('2020-01-01 13:00:00', 'fact2', 'test1_val2');
INSERT INTO test2 VALUES ('2020-01-01 12:00:00', 'fact1', 'test2_val2'), ('2019-01-01 12:00:00', 'fact3', 'test2_val2');
Following works
SELECT *
FROM test1
FULL OUTER JOIN test2 ON test1.foo = test2.bar
┌────────────────time─┬─foo───┬─dimension_1─┬──────────test2.time─┬─bar───┬─dimension_2─┐
│ 2020-01-01 12:00:00 │ fact1 │ test1_val1 │ 2020-01-01 12:00:00 │ fact1 │ test2_val2 │
│ 2020-01-01 13:00:00 │ fact2 │ test1_val2 │ 0000-00-00 00:00:00 │ │ │
└─────────────────────┴───────┴─────────────┴─────────────────────┴───────┴─────────────┘
┌────────────────time─┬─foo─┬─dimension_1─┬──────────test2.time─┬─bar───┬─dimension_2─┐
│ 0000-00-00 00:00:00 │ │ │ 2019-01-01 12:00:00 │ fact3 │ test2_val2 │
└─────────────────────┴─────┴─────────────┴─────────────────────┴───────┴─────────────┘
But when I try to filter on test2.dt server throws an exception
SELECT *
FROM test1
FULL OUTER JOIN test2 ON test1.foo = test2.bar
WHERE test2.dt >= '2020-01-01'
Received exception from server (version 20.3.15):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'test2.dt' while processing query: 'SELECT time, foo, dimension_1, test2.time, bar, dimension_2 FROM test1 ALL FULL OUTER JOIN (SELECT * FROM test2) AS test2 ON foo = bar WHERE test2.dt >= '2020-01-01'', required columns: 'time' 'foo' 'test2.dt' 'test2.time' 'dimension_1' 'bar' 'dimension_2', source columns: 'dt' 'dimension_1' 'foo' 'time', joined columns: 'test2.time' 'bar' 'dimension_2'.
0 rows in set. Elapsed: 0.003 sec.
I understand that joins works other way than in traditional SQL and I have option to move where clause and do separate select like following.
SELECT *
FROM test1
FULL OUTER JOIN
(
SELECT *
FROM test2
WHERE dt >= '2020-01-01'
) AS test2 ON test1.foo = test2.bar
┌────────────────time─┬─foo───┬─dimension_1─┬──────────test2.time─┬─bar───┬─dimension_2─┐
│ 2020-01-01 12:00:00 │ fact1 │ test1_val1 │ 2020-01-01 12:00:00 │ fact1 │ test2_val2 │
│ 2020-01-01 13:00:00 │ fact2 │ test1_val2 │ 0000-00-00 00:00:00 │ │ │
└─────────────────────┴───────┴─────────────┴─────────────────────┴───────┴─────────────┘
But what if main query contains some complicated where clause with condition_from_left OR condition_from_right_materialized, then I have no way to reduce right table to store less in memory and need to do something like
SELECT *
FROM test1
FULL OUTER JOIN
(
SELECT *, dt
FROM test2
) AS test2 ON test1.foo = test2.bar
WHERE test2.dt >= '2020-01-01'
which may load bunch of unnecessary data into RAM
Reacted by Anton Protopopov, serg94, Alexander Tokmakov and TahaYK
Metadata
Metadata
Assignees
Labels
bugConfirmed user-visible misbehaviour in official releasecomp-joinsJOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla...
Activity
TheGreatAbyss commentedon Nov 5, 2020
Hello
I've encountered what I think is a related issue to the above. I have two tables
table_aandtable_bthat have materialized columnscolumn_aandcolumn_brespectively. When I try to write a query that joins the tables and uses those columns:I get an error that looks like this:
DB::Exception: Missing columns: 'b.column_b' while processing query: 'SELECT...If I select from table_b and join on table_a I get the same error for column_a
The work around is to do the following:
Thanks
jirislav commentedon Mar 18, 2024
Is this issue actually resolved? Here's an example, when the materialized column is reported to be missing from the table even though it is there:
It results in
DB::Exception: Unknown column: time, there are only columns symbol, price.error.den-crane commentedon Mar 18, 2024
works with experimental_analyzer
https://fiddle.clickhouse.com/f57022e5-a440-4fc1-a834-13d9c1ebcf48