Fixed DISTINCT if all columns are constant [#CLICKHOUSE-3505].

This commit is contained in:
Alexey Milovidov 2017-12-24 10:59:26 +03:00
parent 90aa544573
commit 7ee1c81d45
2 changed files with 16 additions and 6 deletions

View File

@ -31,6 +31,9 @@ Block DistinctBlockInputStream::readImpl()
/// a block with some new records will be gotten.
while (1)
{
if (no_more_rows)
return Block();
/// Stop reading if we already reach the limit.
if (limit_hint && data.getTotalRowCount() >= limit_hint)
return Block();
@ -41,7 +44,13 @@ Block DistinctBlockInputStream::readImpl()
const ColumnRawPtrs column_ptrs(getKeyColumns(block));
if (column_ptrs.empty())
{
/// Only constants. We need to return single row.
no_more_rows = true;
for (auto & elem : block)
elem.column = elem.column->cut(0, 1);
return block;
}
if (data.empty())
data.init(SetVariants::chooseMethod(column_ptrs, key_sizes));
@ -54,12 +63,12 @@ Block DistinctBlockInputStream::readImpl()
{
case SetVariants::Type::EMPTY:
break;
#define M(NAME) \
#define M(NAME) \
case SetVariants::Type::NAME: \
buildFilter(*data.NAME, column_ptrs, filter, rows, data); \
break;
APPLY_FOR_SET_VARIANTS(M)
#undef M
APPLY_FOR_SET_VARIANTS(M)
#undef M
}
/// Just go to the next block if there isn't any new record in the current one.
@ -86,9 +95,8 @@ Block DistinctBlockInputStream::readImpl()
}
}
size_t all_columns = block.columns();
for (size_t i = 0; i < all_columns; ++i)
block.safeGetByPosition(i).column = block.safeGetByPosition(i).column->filter(filter, -1);
for (auto & elem : block)
elem.column = elem.column->filter(filter, -1);
return block;
}

View File

@ -46,6 +46,8 @@ private:
Sizes key_sizes;
size_t limit_hint;
bool no_more_rows = false;
/// Restrictions on the maximum size of the output data.
size_t max_rows;
size_t max_bytes;