mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #31105 from abel-cheng/fix-rewrite-in-local-in
This commit is contained in:
commit
b85710a673
@ -191,13 +191,25 @@ private:
|
|||||||
ASTTableJoin * table_join = node.table_join->as<ASTTableJoin>();
|
ASTTableJoin * table_join = node.table_join->as<ASTTableJoin>();
|
||||||
if (table_join->locality != ASTTableJoin::Locality::Global)
|
if (table_join->locality != ASTTableJoin::Locality::Global)
|
||||||
{
|
{
|
||||||
if (auto & subquery = node.table_expression->as<ASTTableExpression>()->subquery)
|
if (auto * table = node.table_expression->as<ASTTableExpression>())
|
||||||
{
|
{
|
||||||
std::vector<ASTPtr> renamed;
|
if (auto & subquery = table->subquery)
|
||||||
NonGlobalTableVisitor::Data table_data(data.getContext(), data.checker, renamed, nullptr, table_join);
|
{
|
||||||
NonGlobalTableVisitor(table_data).visit(subquery);
|
std::vector<ASTPtr> renamed;
|
||||||
if (!renamed.empty()) //-V547
|
NonGlobalTableVisitor::Data table_data(data.getContext(), data.checker, renamed, nullptr, table_join);
|
||||||
data.renamed_tables.emplace_back(subquery, std::move(renamed));
|
NonGlobalTableVisitor(table_data).visit(subquery);
|
||||||
|
if (!renamed.empty()) //-V547
|
||||||
|
data.renamed_tables.emplace_back(subquery, std::move(renamed));
|
||||||
|
}
|
||||||
|
else if (table->database_and_table_name)
|
||||||
|
{
|
||||||
|
auto tb = node.table_expression;
|
||||||
|
std::vector<ASTPtr> renamed;
|
||||||
|
NonGlobalTableVisitor::Data table_data{data.getContext(), data.checker, renamed, nullptr, table_join};
|
||||||
|
NonGlobalTableVisitor(table_data).visit(tb);
|
||||||
|
if (!renamed.empty()) //-V547
|
||||||
|
data.renamed_tables.emplace_back(tb, std::move(renamed));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ GLOBAL ALL INNER JOIN
|
|||||||
(
|
(
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM t1_distr AS d1
|
FROM t1_distr AS d1
|
||||||
ALL INNER JOIN t2_distr AS d2 ON id = d2.id
|
GLOBAL ALL INNER JOIN t2_distr AS d2 ON id = d2.id
|
||||||
WHERE id > 0
|
WHERE id > 0
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
) AS s0 USING (id)
|
) AS s0 USING (id)
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
SELECT a
|
||||||
|
FROM t1_all AS t1
|
||||||
|
ALL INNER JOIN test_02115.t2_local AS t2 ON a = t2.a
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
SELECT a
|
||||||
|
FROM t1_all AS t1
|
||||||
|
GLOBAL ALL INNER JOIN t2_all AS t2 ON a = t2.a
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
3
|
||||||
|
3
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
3
|
||||||
|
3
|
@ -0,0 +1,33 @@
|
|||||||
|
-- Tags: global, no-parallel
|
||||||
|
CREATE DATABASE IF NOT EXISTS test_02115;
|
||||||
|
USE test_02115;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS t1_local;
|
||||||
|
DROP TABLE IF EXISTS t2_local;
|
||||||
|
DROP TABLE IF EXISTS t1_all;
|
||||||
|
DROP TABLE IF EXISTS t2_all;
|
||||||
|
|
||||||
|
create table t1_local(a Int32) engine=MergeTree() order by a;
|
||||||
|
create table t2_local as t1_local;
|
||||||
|
|
||||||
|
create table t1_all as t1_local engine Distributed(test_cluster_two_shards_localhost, test_02115, t1_local, rand());
|
||||||
|
create table t2_all as t2_local engine Distributed(test_cluster_two_shards_localhost, test_02115, t2_local, rand());
|
||||||
|
|
||||||
|
insert into t1_local values(1), (2), (3);
|
||||||
|
insert into t2_local values(1), (2), (3);
|
||||||
|
|
||||||
|
set distributed_product_mode = 'local';
|
||||||
|
select * from t1_all t1 where t1.a in (select t2.a from t2_all t2);
|
||||||
|
explain syntax select t1.* from t1_all t1 join t2_all t2 on t1.a = t2.a;
|
||||||
|
select t1.* from t1_all t1 join t2_all t2 on t1.a = t2.a;
|
||||||
|
|
||||||
|
set distributed_product_mode = 'global';
|
||||||
|
select * from t1_all t1 where t1.a in (select t2.a from t2_all t2);
|
||||||
|
explain syntax select t1.* from t1_all t1 join t2_all t2 on t1.a = t2.a;
|
||||||
|
select t1.* from t1_all t1 join t2_all t2 on t1.a = t2.a;
|
||||||
|
|
||||||
|
DROP TABLE t1_local;
|
||||||
|
DROP TABLE t2_local;
|
||||||
|
DROP TABLE t1_all;
|
||||||
|
DROP TABLE t2_all;
|
||||||
|
DROP DATABASE test_02115;
|
Loading…
Reference in New Issue
Block a user