Merge pull request #27298 from ClickHouse/fix-23515

Fix bug from #23515.
This commit is contained in:
Nikolai Kochetov 2021-08-09 23:25:30 +03:00 committed by GitHub
commit bb4c11cd27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 3 deletions

View File

@ -342,6 +342,13 @@ static void executeAction(const ExpressionActions::Action & action, ExecutionCon
res_column.type = action.node->result_type;
res_column.name = action.node->result_name;
if (action.node->column)
{
/// Do not execute function if it's result is already known.
res_column.column = action.node->column->cloneResized(num_rows);
break;
}
ColumnsWithTypeAndName arguments(action.arguments.size());
for (size_t i = 0; i < arguments.size(); ++i)
{

View File

@ -2,6 +2,7 @@
#include <Columns/FilterDescription.h>
#include <Columns/ColumnsCommon.h>
#include <common/range.h>
#include <Interpreters/castColumn.h>
#include <DataTypes/DataTypeNothing.h>
#ifdef __SSE2__
@ -1043,9 +1044,9 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
/// Filter in WHERE instead
else
{
result.columns[prewhere_column_pos] = result.getFilterHolder()->convertToFullColumnIfConst();
if (getSampleBlock().getByName(prewhere_info->prewhere_column_name).type->isNullable())
result.columns[prewhere_column_pos] = makeNullable(std::move(result.columns[prewhere_column_pos]));
auto type = getSampleBlock().getByName(prewhere_info->prewhere_column_name).type;
ColumnWithTypeAndName col(result.getFilterHolder()->convertToFullColumnIfConst(), std::make_shared<DataTypeUInt8>(), "");
result.columns[prewhere_column_pos] = castColumn(col, type);
result.clearFilter(); // Acting as a flag to not filter in PREWHERE
}
}

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,10 @@
drop table if exists tab;
create table tab (a LowCardinality(String), b LowCardinality(String)) engine = MergeTree partition by a order by tuple() settings min_bytes_for_wide_part = 0, min_rows_for_wide_part = 0;
insert into tab values ('1', 'a'), ('2', 'b');
SELECT a = '1' FROM tab WHERE a = '1' and b='a';
-- Fuzzed
SELECT * FROM tab WHERE (a = '1') AND 0 AND (b = 'a');
drop table if exists tab;