global in set index.

This commit is contained in:
Amos Bird 2020-11-21 16:25:45 +08:00
parent e76f7c316b
commit 172b7e9ed1
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
5 changed files with 63 additions and 4 deletions

View File

@ -364,7 +364,7 @@ void SelectQueryExpressionAnalyzer::makeSetsForIndex(const ASTPtr & node)
}
const auto * func = node->as<ASTFunction>();
if (func && functionIsInOperator(func->name))
if (func && functionIsInOrGlobalInOperator(func->name))
{
const IAST & args = *func->arguments;
const ASTPtr & left_in_operand = args.children.at(0);

View File

@ -135,9 +135,28 @@ public:
ast = database_and_table_name;
external_tables[external_table_name] = external_storage_holder;
subqueries_for_sets[external_table_name].source = std::make_unique<QueryPlan>();
interpreter->buildQueryPlan(*subqueries_for_sets[external_table_name].source);
subqueries_for_sets[external_table_name].table = external_storage;
if (context.getSettingsRef().use_index_for_in_with_subqueries)
{
auto external_table = external_storage_holder->getTable();
auto table_out = external_table->write({}, external_table->getInMemoryMetadataPtr(), context);
auto stream = interpreter->execute().getInputStream();
table_out->writePrefix();
stream->readPrefix();
while (Block block = stream->read())
{
table_out->write(block);
}
table_out->writeSuffix();
stream->readSuffix();
}
else
{
subqueries_for_sets[external_table_name].source = std::make_unique<QueryPlan>();
interpreter->buildQueryPlan(*subqueries_for_sets[external_table_name].source);
subqueries_for_sets[external_table_name].table = external_storage;
}
/** NOTE If it was written IN tmp_table - the existing temporary (but not external) table,
* then a new temporary table will be created (for example, _data1),

View File

@ -184,6 +184,22 @@ const KeyCondition::AtomMap KeyCondition::atom_map
return true;
}
},
{
"globalIn",
[] (RPNElement & out, const Field &)
{
out.function = RPNElement::FUNCTION_IN_SET;
return true;
}
},
{
"globalNotIn",
[] (RPNElement & out, const Field &)
{
out.function = RPNElement::FUNCTION_NOT_IN_SET;
return true;
}
},
{
"empty",
[] (RPNElement & out, const Field & value)

View File

@ -0,0 +1,8 @@
0 2
1 3
0 2
1 3
0 2
1 3
0 2
1 3

View File

@ -0,0 +1,16 @@
drop table if exists xp;
drop table if exists xp_d;
create table xp(i UInt64, j UInt64) engine MergeTree order by i settings index_granularity = 1;
create table xp_d as xp engine Distributed(test_shard_localhost, currentDatabase(), xp);
insert into xp select number, number + 2 from numbers(10);
set max_rows_to_read = 2;
select * from xp where i in (select * from numbers(2));
select * from xp where i global in (select * from numbers(2));
select * from xp_d where i in (select * from numbers(2));
select * from xp_d where i global in (select * from numbers(2));
drop table if exists xp;
drop table if exists xp_d;