Merge pull request #31105 from abel-cheng/fix-rewrite-in-local-in

This commit is contained in:
Vladimir C 2021-11-11 10:02:52 +03:00 committed by GitHub
commit b85710a673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 7 deletions

View File

@ -191,7 +191,9 @@ private:
ASTTableJoin * table_join = node.table_join->as<ASTTableJoin>();
if (table_join->locality != ASTTableJoin::Locality::Global)
{
if (auto & subquery = node.table_expression->as<ASTTableExpression>()->subquery)
if (auto * table = node.table_expression->as<ASTTableExpression>())
{
if (auto & subquery = table->subquery)
{
std::vector<ASTPtr> renamed;
NonGlobalTableVisitor::Data table_data(data.getContext(), data.checker, renamed, nullptr, table_join);
@ -199,6 +201,16 @@ private:
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));
}
}
}
}
};

View File

@ -42,7 +42,7 @@ GLOBAL ALL INNER JOIN
(
SELECT id
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
ORDER BY id ASC
) AS s0 USING (id)

View File

@ -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

View File

@ -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;