diff --git a/dbms/src/Columns/ColumnAggregateFunction.cpp b/dbms/src/Columns/ColumnAggregateFunction.cpp index 8702a2b241a..941d8988375 100644 --- a/dbms/src/Columns/ColumnAggregateFunction.cpp +++ b/dbms/src/Columns/ColumnAggregateFunction.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -143,7 +144,11 @@ ColumnPtr ColumnAggregateFunction::filter(const Filter & filter, ssize_t result_ auto & res_data = res->getData(); if (result_size_hint) - res_data.reserve(result_size_hint > 0 ? result_size_hint : size); + { + if (result_size_hint < 0) + result_size_hint = countBytesInFilter(filter); + res_data.reserve(result_size_hint); + } for (size_t i = 0; i < size; ++i) if (filter[i]) diff --git a/dbms/src/Columns/ColumnArray.h b/dbms/src/Columns/ColumnArray.h index 6493dbecab5..5b10e02272e 100644 --- a/dbms/src/Columns/ColumnArray.h +++ b/dbms/src/Columns/ColumnArray.h @@ -87,6 +87,7 @@ class ColumnArray final : public COWPtrHelper void insertFrom(const IColumn & src_, size_t n) override; void insertDefault() override; void popBack(size_t n) override; + /// TODO: If result_size_hint < 0, makes reserve() using size of column after being filtered, not source column. ColumnPtr filter(const Filter & filt, ssize_t result_size_hint) const override; ColumnPtr permute(const Permutation & perm, size_t limit) const override; int compareAt(size_t n, size_t m, const IColumn & rhs_, int nan_direction_hint) const override; diff --git a/dbms/src/Columns/ColumnDecimal.cpp b/dbms/src/Columns/ColumnDecimal.cpp index 25f85ddb986..48f263f5399 100644 --- a/dbms/src/Columns/ColumnDecimal.cpp +++ b/dbms/src/Columns/ColumnDecimal.cpp @@ -305,10 +305,12 @@ ColumnPtr ColumnDecimal::filter(const IColumn::Filter & filt, ssize_t result_ auto res = this->create(0, scale); Container & res_data = res->getData(); - if (result_size_hint < 0) - res_data.reserve(countBytesInFilter(filt)); - else if (result_size_hint > 0) + if (result_size_hint) + { + if (result_size_hint < 0) + result_size_hint = countBytesInFilter(filt); res_data.reserve(result_size_hint); + } const UInt8 * filt_pos = filt.data(); const UInt8 * filt_end = filt_pos + size; diff --git a/dbms/src/Columns/ColumnFixedString.cpp b/dbms/src/Columns/ColumnFixedString.cpp index a28177bc0b6..a07d3f37d1d 100644 --- a/dbms/src/Columns/ColumnFixedString.cpp +++ b/dbms/src/Columns/ColumnFixedString.cpp @@ -205,10 +205,12 @@ ColumnPtr ColumnFixedString::filter(const IColumn::Filter & filt, ssize_t result auto res = ColumnFixedString::create(n); - if (result_size_hint < 0) - res->chars.reserve(countBytesInFilter(filt) * n); - else if (result_size_hint > 0) + if (result_size_hint) + { + if (result_size_hint < 0) + result_size_hint = countBytesInFilter(filt); res->chars.reserve(result_size_hint * n); + } const UInt8 * filt_pos = &filt[0]; const UInt8 * filt_end = filt_pos + col_size; diff --git a/dbms/src/Columns/ColumnVector.cpp b/dbms/src/Columns/ColumnVector.cpp index 03fd5cab5c8..90c4710c170 100644 --- a/dbms/src/Columns/ColumnVector.cpp +++ b/dbms/src/Columns/ColumnVector.cpp @@ -213,10 +213,12 @@ ColumnPtr ColumnVector::filter(const IColumn::Filter & filt, ssize_t result_s auto res = this->create(); Container & res_data = res->getData(); - if (result_size_hint < 0) - res_data.reserve(countBytesInFilter(filt)); - else if (result_size_hint > 0) + if (result_size_hint) + { + if (result_size_hint < 0) + result_size_hint = countBytesInFilter(filt); res_data.reserve(result_size_hint); + } const UInt8 * filt_pos = &filt[0]; const UInt8 * filt_end = filt_pos + size;