mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #3090 from yandex/fix_prewhere_with_sampling_2
Fix prewhere with sampling 2
This commit is contained in:
commit
1d28a9c510
@ -2678,7 +2678,7 @@ bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool onl
|
||||
|
||||
Names required_sample_columns;
|
||||
if (sampling_expression)
|
||||
required_sample_columns = ExpressionAnalyzer(sampling_expression, context, nullptr, source_columns).getRequiredSourceColumns();
|
||||
required_sample_columns = ExpressionAnalyzer(sampling_expression, context, storage).getRequiredSourceColumns();
|
||||
|
||||
initChain(chain, source_columns);
|
||||
auto & step = chain.getLastStep();
|
||||
@ -2687,15 +2687,6 @@ bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool onl
|
||||
step.required_output.push_back(prewhere_column_name);
|
||||
step.can_remove_required_output.push_back(true);
|
||||
|
||||
/// Add required columns for sample expression to required output in order not to remove them after
|
||||
/// prewhere execution because sampling is executed after prewhere.
|
||||
/// TODO: add sampling execution to common chain.
|
||||
for (const auto & column : required_sample_columns)
|
||||
{
|
||||
step.required_output.push_back(column);
|
||||
step.can_remove_required_output.push_back(true);
|
||||
}
|
||||
|
||||
{
|
||||
/// Remove unused source_columns from prewhere actions.
|
||||
auto tmp_actions = std::make_shared<ExpressionActions>(source_columns, context);
|
||||
@ -2704,6 +2695,18 @@ bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool onl
|
||||
auto required_columns = tmp_actions->getRequiredColumns();
|
||||
NameSet required_source_columns(required_columns.begin(), required_columns.end());
|
||||
|
||||
/// Add required columns for sample expression to required output in order not to remove them after
|
||||
/// prewhere execution because sampling is executed after prewhere.
|
||||
/// TODO: add sampling execution to common chain.
|
||||
for (const auto & column : required_sample_columns)
|
||||
{
|
||||
if (required_source_columns.count(column))
|
||||
{
|
||||
step.required_output.push_back(column);
|
||||
step.can_remove_required_output.push_back(true);
|
||||
}
|
||||
}
|
||||
|
||||
auto names = step.actions->getSampleBlock().getNames();
|
||||
NameSet name_set(names.begin(), names.end());
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
1
|
||||
0
|
||||
|
@ -4,3 +4,7 @@ insert into test.tab values (1, 2), (1, 4);
|
||||
select a from test.tab sample 1 / 2 prewhere b = 2;
|
||||
drop table if exists test.tab;
|
||||
|
||||
DROP TABLE IF EXISTS test.sample_prewhere;
|
||||
CREATE TABLE test.sample_prewhere (CounterID UInt32, UserID UInt64) ENGINE = MergeTree ORDER BY UserID SAMPLE BY UserID;
|
||||
SELECT count() FROM test.sample_prewhere SAMPLE 1/2 PREWHERE CounterID = 1;
|
||||
DROP TABLE test.sample_prewhere;
|
||||
|
Loading…
Reference in New Issue
Block a user