mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Fix optimization for 'WHERE column in (empty set)' case.
This commit is contained in:
parent
81b5b17828
commit
efe1616fda
@ -64,14 +64,24 @@ FilterTransform::FilterTransform(
|
||||
|
||||
IProcessor::Status FilterTransform::prepare()
|
||||
{
|
||||
if (constant_filter_description.always_false)
|
||||
if (constant_filter_description.always_false
|
||||
/// Optimization for `WHERE column in (empty set)`.
|
||||
/// The result will not change after set was created, so we can skip this check.
|
||||
/// It is implemented in prepare() stop pipeline before reading from input port.
|
||||
|| (!are_prepared_sets_initialized && expression->checkColumnIsAlwaysFalse(filter_column_name)))
|
||||
{
|
||||
input.close();
|
||||
output.finish();
|
||||
return Status::Finished;
|
||||
}
|
||||
|
||||
return ISimpleTransform::prepare();
|
||||
auto status = ISimpleTransform::prepare();
|
||||
|
||||
/// Until prepared sets are initialized, output port will be unneeded, and prepare will return PortFull.
|
||||
if (status != IProcessor::Status::PortFull)
|
||||
are_prepared_sets_initialized = true;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -83,18 +93,6 @@ void FilterTransform::removeFilterIfNeed(Chunk & chunk)
|
||||
|
||||
void FilterTransform::transform(Chunk & chunk)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
initialized = true;
|
||||
|
||||
if (expression->checkColumnIsAlwaysFalse(filter_column_name))
|
||||
{
|
||||
stopReading();
|
||||
chunk = Chunk(getOutputPort().getHeader().getColumns(), 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
size_t num_rows_before_filtration = chunk.getNumRows();
|
||||
auto columns = chunk.detachColumns();
|
||||
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
/// Header after expression, but before removing filter column.
|
||||
Block transformed_header;
|
||||
|
||||
bool initialized = false;
|
||||
bool are_prepared_sets_initialized = false;
|
||||
|
||||
void removeFilterIfNeed(Chunk & chunk);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user