fix bug with comma join and in

This commit is contained in:
chertus 2020-02-20 16:33:14 +03:00
parent 39f2e6b835
commit 9748f8dcf6
4 changed files with 21 additions and 18 deletions

View File

@ -124,15 +124,12 @@ public:
{
/// leave other comparisons as is
}
else if (functionIsLikeOperator(node.name)) /// LIKE, NOT LIKE
else if (functionIsLikeOperator(node.name) || /// LIKE, NOT LIKE
functionIsInOperator(node.name)) /// IN, NOT IN
{
/// leave as is
}
else if (functionIsInOperator(node.name)) /// IN, NOT IN
{
if (auto ident = node.arguments->children.at(0)->as<ASTIdentifier>())
if (size_t min_table = checkIdentifier(*ident))
asts_to_join_on[min_table].push_back(ast);
/// leave as is. It's not possible to make push down here cause of unknown aliases and not implemented JOIN predicates.
/// select a as b form t1, t2 where t1.x = t2.x and b in(42)
/// select a as b form t1 inner join t2 on t1.x = t2.x and b in(42)
}
else
{
@ -202,16 +199,6 @@ private:
}
return 0;
}
size_t checkIdentifier(const ASTIdentifier & identifier)
{
size_t best_table_pos = 0;
bool match = IdentifierSemantic::chooseTable(identifier, tables, best_table_pos);
if (match && joined_tables[best_table_pos].canAttachOnExpression())
return best_table_pos;
return 0;
}
};
using CheckExpressionMatcher = ConstOneTypeMatcher<CheckExpressionVisitorData, false>;

View File

@ -10,6 +10,8 @@ insert into test1_00863 (id, code) select number, toString(number) FROM numbers(
insert into test3_00863 (id, code) select number, toString(number) FROM numbers(100000);
insert into test2_00863 (id, code, test1_id, test3_id) select number, toString(number), number, number FROM numbers(100000);
SET max_memory_usage = 50000000;
select test2_00863.id
from test1_00863, test2_00863, test3_00863
where test1_00863.code in ('1', '2', '3')

View File

@ -0,0 +1,13 @@
drop table if exists ax;
drop table if exists bx;
create table ax (A Int64, B Int64) Engine = Memory;
create table bx (A Int64) Engine = Memory;
insert into ax values (1, 1), (2, 1);
insert into bx values (2), (4);
select * from bx, ax where ax.A = bx.A and ax.B in (1,2);
drop table ax;
drop table bx;