Repository navigation
Description
Describe the bug
If setting distributed_product_mode=local, distributed query contains IN condition and
a) fields in subquery are referenced with database name, ClickHouse replaces distributed names with local names only in FROM and JOIN sections, but not in SELECT, WHERE, ORDER BY
b) fields in subquery are referenced with table alias, ClickHouse replaces distributed names and aliases with local names. So aliases are lost.
How to reproduce
ClickHouse version 19.4.0.49 cluster (shards)
HTTP interface
setting distributed_product_mode=local
create table bug_shard1 on cluster mycluster
(id Int32)
engine = MergeTree
order by cityHash64(id);
create table bug_distr1 on cluster mycluster
as bug_shard1
engine Distributed(
mycluster,
`default`,
bug_shard1,
cityHash64(id)
);
create table bug_shard2 on cluster mycluster
(id Int32)
engine = MergeTree
order by cityHash64(id);
create table bug_distr2 on cluster mycluster
as bug_shard2
engine Distributed(
mycluster,
`default`,
bug_shard2,
cityHash64(id)
);
Queries to run that lead to unexpected result
a)
select `default`.bug_distr1.id
from `default`.bug_distr1
where `default`.bug_distr1.id in
(
select `default`.bug_distr1.id
from `default`.bug_distr1
inner join `default`.bug_distr2 on `default`.bug_distr1.id = `default`.bug_distr2.id
where `default`.bug_distr1.id > 0
order by `default`.bug_distr1.id
);
b)
select d0.id
from bug_distr1 d0
where d0.id in
(
select d1.id
from bug_distr1 as d1
inner join bug_distr2 as d2 on d1.id = d2.id
where d1.id > 0
order by d1.id
);
Expected behavior
a) distributed table names has been replaced with local names in all query sections
b) aliases in FROM and JOIN sections has not been removed
Error message and/or stacktrace
a)
SQL Error [47]: ClickHouse exception, code: 47, host: localhost, port: 8125; Code: 47, e.displayText() = DB::Exception: Unknown identifier: default.bug_distr1.id, context: query: 'SELECT default.bug_distr1.id FROM default.bug_shard1 INNER JOIN default.bug_shard2 ON default.bug_distr1.id = default.bug_distr2.id WHERE default.bug_distr1.id > 0 ORDER BY default.bug_distr1.id ASC' required_names: 'default.bug_distr2.id''default.bug_distr1.id' source_tables: 'default.bug_shard1' 'default.bug_shard2' table_aliases: complex_aliases: masked_columns: array_join_columns: source_columns:
b)
SQL Error [47]: ClickHouse exception, code: 47, host: localhost, port: 8125; Code: 47, e.displayText() = DB::Exception: Unknown identifier: d1.id, context: query: 'SELECT d1.id FROM default.bug_shard1 INNER JOIN default.bug_shard2 ON d1.id = d2.id WHERE d1.id > 0 ORDER BY d1.id ASC' required_names: 'd2.id''d1.id' source_tables: 'default.bug_shard1' 'default.bug_shard2' table_aliases: complex_aliases: masked_columns: array_join_columns: source_columns:
Activity
4ertus2 commentedon Apr 11, 2019
Probably related #4879
4ertus2 commentedon Apr 11, 2019
Partial fix #4986
hohaftf commentedon Apr 17, 2019
I checked fix for #4879 on v 19.5.2.6
Both queries from this issue work in global and allow modes, and they did not before.
Both queries fail in local mode.
hohaftf commentedon Oct 10, 2019
UPD.
Clickhouse v 19.15.3.6
Query with aliases works in local mode
Query with db names throws exception
hohaftf commentedon Apr 16, 2020
As I understand this must be fixed in v 20.3.6.40. But case A still does not work.
query
is translated to
The table name in left join field is not converted to default.bug_shard1. The table name in right join field is also confusing. And I got exception
4ertus2 commentedon Apr 16, 2020
It's not backported to 20.3 cause of code conflicts and backport complexity. It should be fixed in 20.4. Could you check it on muster build?
If you have version that passes this test https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/01104_distributed_one_test.sql but does not pass your test, it's a new issue.