Fix optimization for 'WHERE column in (empty set)' case.

This commit is contained in:
Nikolai Kochetov 2019-12-03 15:27:44 +03:00
parent 81b5b17828
commit efe1616fda
2 changed files with 13 additions and 15 deletions

View File

@ -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();

View File

@ -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);
};