Read prefix before blocks while executing subquery.

This commit is contained in:
Vitaly Baranov 2019-07-11 16:51:54 +03:00
parent f635d2bd9b
commit 001e4daf25
4 changed files with 22 additions and 1 deletions

View File

@ -279,12 +279,14 @@ void ExpressionAnalyzer::tryMakeSetForIndexFromSubquery(const ASTPtr & subquery_
SetPtr set = std::make_shared<Set>(settings.size_limits_for_set, true);
set->setHeader(res.in->getHeader());
res.in->readPrefix();
while (Block block = res.in->read())
{
/// If the limits have been exceeded, give up and let the default subquery processing actions take place.
if (!set->insertFromBlock(block))
return;
}
res.in->readSuffix();
prepared_sets[set_key] = std::move(set);
}

View File

@ -249,7 +249,7 @@ private:
void assertAggregation() const;
/**
* Create Set from a subuquery or a table expression in the query. The created set is suitable for using the index.
* Create Set from a subquery or a table expression in the query. The created set is suitable for using the index.
* The set will not be created if its size hits the limit.
*/
void tryMakeSetForIndexFromSubquery(const ASTPtr & subquery_or_table_name);

View File

@ -0,0 +1,10 @@
0
1
2
3
4
5
6
7
8
9

View File

@ -0,0 +1,9 @@
DROP TABLE IF EXISTS tableFile_00968;
DROP TABLE IF EXISTS tableMergeTree_00968;
CREATE TABLE tableFile_00968(number UInt64) ENGINE = File('TSV');
CREATE TABLE tableMergeTree_00968(id UInt64) ENGINE = MergeTree() PARTITION BY id ORDER BY id;
INSERT INTO tableFile_00968 SELECT number FROM system.numbers LIMIT 10;
INSERT INTO tableMergeTree_00968 SELECT number FROM system.numbers LIMIT 100;
SELECT id FROM tableMergeTree_00968 WHERE id IN (SELECT number FROM tableFile_00968) ORDER BY id;