dbms: JOIN with empty table: additions [#METR-16476].

This commit is contained in:
Alexey Milovidov 2015-05-27 03:55:54 +03:00
parent 7f38ad390e
commit 5390f492e1
6 changed files with 33 additions and 1 deletions

View File

@ -22,6 +22,7 @@ struct SubqueryForSet
{
/// Источник - получен с помощью InterpreterSelectQuery подзапроса.
BlockInputStreamPtr source;
Block source_sample;
/// Если задано - создать из результата Set.
SetPtr set;

View File

@ -769,6 +769,7 @@ void ExpressionAnalyzer::addExternalStorage(ASTPtr & subquery_or_table_name)
external_tables[external_table_name] = external_storage;
subqueries_for_sets[external_table_name].source = interpreter->execute();
subqueries_for_sets[external_table_name].source_sample = interpreter->getSampleBlock();
subqueries_for_sets[external_table_name].table = external_storage;
/** NOTE Если было написано IN tmp_table - существующая временная (но не внешняя) таблица,
@ -842,6 +843,7 @@ void ExpressionAnalyzer::makeSet(ASTFunction * node, const Block & sample_block)
{
auto interpreter = interpretSubquery(arg, context, subquery_depth);
subquery_for_set.source = new LazyBlockInputStream([interpreter]() mutable { return interpreter->execute(); });
subquery_for_set.source_sample = interpreter->getSampleBlock();
/** Зачем используется LazyBlockInputStream?
*
@ -1591,10 +1593,12 @@ bool ExpressionAnalyzer::appendJoin(ExpressionActionsChain & chain, bool only_ty
{
auto interpreter = interpretSubquery(ast_join.table, context, subquery_depth, required_joined_columns);
subquery_for_set.source = new LazyBlockInputStream([interpreter]() mutable { return interpreter->execute(); });
join->setSampleBlock(interpreter->getSampleBlock());
subquery_for_set.source_sample = interpreter->getSampleBlock();
}
/// TODO Это не нужно выставлять, когда JOIN нужен только на удалённых серверах.
subquery_for_set.join = join;
subquery_for_set.join->setSampleBlock(subquery_for_set.source_sample);
}
addJoinAction(step.actions, false);

View File

@ -0,0 +1,2 @@
2 6 Hello
2 6 Hello

View File

@ -0,0 +1 @@
SELECT toFloat64(dummy + 2) AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.one) GLOBAL ANY LEFT JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 10) USING n LIMIT 10;

View File

@ -0,0 +1,20 @@
0 0 0
1 0.5 0
2 1 0
3 1.5 0
4 2 0
5 2.5 0
6 3 0
7 3.5 0
8 4 0
9 4.5 0
0 0 0
1 0.5 0
2 1 0
3 1.5 0
4 2 0
5 2.5 0
6 3 0
7 3.5 0
8 4 0
9 4.5 0

View File

@ -0,0 +1,4 @@
SELECT number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.numbers) ANY LEFT JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
SELECT dummy + 2 AS number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.one) ANY INNER JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
SELECT number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.numbers) GLOBAL ANY LEFT JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;
SELECT dummy + 2 AS number, number / 2 AS n, j1, j2 FROM remote('127.0.0.{2,3}', system.one) GLOBAL ANY INNER JOIN (SELECT number / 3 AS n, number AS j1, 'Hello' AS j2 FROM system.numbers LIMIT 0) USING n LIMIT 10;