mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Alternative way
This commit is contained in:
parent
2f36c9e965
commit
66248d4814
@ -303,7 +303,7 @@ ColumnPtr ColumnAggregateFunction::filter(const Filter & filter, ssize_t result_
|
||||
auto & res_data = res->data;
|
||||
|
||||
if (result_size_hint)
|
||||
res_data.reserve(result_size_hint > 0 ? result_size_hint : size);
|
||||
res_data.reserve_exact(result_size_hint > 0 ? result_size_hint : size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
if (filter[i])
|
||||
@ -584,7 +584,7 @@ ColumnPtr ColumnAggregateFunction::replicate(const IColumn::Offsets & offsets) c
|
||||
|
||||
auto res = createView();
|
||||
auto & res_data = res->data;
|
||||
res_data.reserve(offsets.back());
|
||||
res_data.reserve_exact(offsets.back());
|
||||
|
||||
IColumn::Offset prev_offset = 0;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
|
@ -423,7 +423,7 @@ struct ColumnArray::ComparatorCollationBase
|
||||
|
||||
void ColumnArray::reserve(size_t n)
|
||||
{
|
||||
getOffsets().reserve(n);
|
||||
getOffsets().reserve_exact(n);
|
||||
getData().reserve(n); /// The average size of arrays is not taken into account here. Or it is considered to be no more than 1.
|
||||
}
|
||||
|
||||
@ -533,7 +533,7 @@ void ColumnArray::insertRangeFrom(const IColumn & src, size_t start, size_t leng
|
||||
|
||||
Offsets & cur_offsets = getOffsets();
|
||||
/// Reserve offsets before to make it more exception safe (in case of MEMORY_LIMIT_EXCEEDED)
|
||||
cur_offsets.reserve(cur_offsets.size() + length);
|
||||
cur_offsets.reserve_exact(cur_offsets.size() + length);
|
||||
|
||||
getData().insertRangeFrom(src_concrete.getData(), nested_offset, nested_length);
|
||||
|
||||
@ -684,9 +684,9 @@ ColumnPtr ColumnArray::filterString(const Filter & filt, ssize_t result_size_hin
|
||||
|
||||
if (result_size_hint < 0) /// Other cases are not considered.
|
||||
{
|
||||
res_chars.reserve(src_chars.size());
|
||||
res_string_offsets.reserve(src_string_offsets.size());
|
||||
res_offsets.reserve(col_size);
|
||||
res_chars.reserve_exact(src_chars.size());
|
||||
res_string_offsets.reserve_exact(src_string_offsets.size());
|
||||
res_offsets.reserve_exact(col_size);
|
||||
}
|
||||
|
||||
Offset prev_src_offset = 0;
|
||||
@ -760,7 +760,7 @@ ColumnPtr ColumnArray::filterGeneric(const Filter & filt, ssize_t result_size_hi
|
||||
|
||||
Offsets & res_offsets = res->getOffsets();
|
||||
if (result_size_hint)
|
||||
res_offsets.reserve(result_size_hint > 0 ? result_size_hint : size);
|
||||
res_offsets.reserve_exact(result_size_hint > 0 ? result_size_hint : size);
|
||||
|
||||
size_t current_offset = 0;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
@ -847,7 +847,7 @@ ColumnPtr ColumnArray::indexImpl(const PaddedPODArray<T> & indexes, size_t limit
|
||||
/// Convert indexes to UInt64 in case of overflow.
|
||||
auto nested_indexes_column = ColumnUInt64::create();
|
||||
PaddedPODArray<UInt64> & nested_indexes = nested_indexes_column->getData();
|
||||
nested_indexes.reserve(getOffsets().back());
|
||||
nested_indexes.reserve_exact(getOffsets().back());
|
||||
|
||||
auto res = ColumnArray::create(data->cloneEmpty());
|
||||
|
||||
@ -1060,8 +1060,8 @@ ColumnPtr ColumnArray::replicateNumber(const Offsets & replicate_offsets) const
|
||||
typename ColVecType::Container & res_data = typeid_cast<ColVecType &>(res_arr.getData()).getData();
|
||||
Offsets & res_offsets = res_arr.getOffsets();
|
||||
|
||||
res_data.reserve(data->size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve(replicate_offsets.back());
|
||||
res_data.reserve_exact(data->size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve_exact(replicate_offsets.back());
|
||||
|
||||
Offset prev_replicate_offset = 0;
|
||||
Offset prev_data_offset = 0;
|
||||
@ -1114,9 +1114,9 @@ ColumnPtr ColumnArray::replicateString(const Offsets & replicate_offsets) const
|
||||
Offsets & res_string_offsets = typeid_cast<ColumnString &>(res_arr.getData()).getOffsets();
|
||||
Offsets & res_offsets = res_arr.getOffsets();
|
||||
|
||||
res_chars.reserve(src_chars.size() / col_size * replicate_offsets.back());
|
||||
res_string_offsets.reserve(src_string_offsets.size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve(replicate_offsets.back());
|
||||
res_chars.reserve_exact(src_chars.size() / col_size * replicate_offsets.back());
|
||||
res_string_offsets.reserve_exact(src_string_offsets.size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve_exact(replicate_offsets.back());
|
||||
|
||||
Offset prev_replicate_offset = 0;
|
||||
|
||||
@ -1183,7 +1183,7 @@ ColumnPtr ColumnArray::replicateConst(const Offsets & replicate_offsets) const
|
||||
|
||||
auto res_column_offsets = ColumnOffsets::create();
|
||||
Offsets & res_offsets = res_column_offsets->getData();
|
||||
res_offsets.reserve(replicate_offsets.back());
|
||||
res_offsets.reserve_exact(replicate_offsets.back());
|
||||
|
||||
Offset prev_replicate_offset = 0;
|
||||
Offset prev_data_offset = 0;
|
||||
|
@ -263,7 +263,7 @@ public:
|
||||
if (!data->isDefaultAt(0))
|
||||
{
|
||||
size_t to = limit && from + limit < size() ? from + limit : size();
|
||||
indices.reserve(indices.size() + to - from);
|
||||
indices.reserve_exact(indices.size() + to - from);
|
||||
for (size_t i = from; i < to; ++i)
|
||||
indices.push_back(i);
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ ColumnPtr ColumnDecimal<T>::filter(const IColumn::Filter & filt, ssize_t result_
|
||||
Container & res_data = res->getData();
|
||||
|
||||
if (result_size_hint)
|
||||
res_data.reserve(result_size_hint > 0 ? result_size_hint : size);
|
||||
res_data.reserve_exact(result_size_hint > 0 ? result_size_hint : size);
|
||||
|
||||
const UInt8 * filt_pos = filt.data();
|
||||
const UInt8 * filt_end = filt_pos + size;
|
||||
@ -445,7 +445,7 @@ ColumnPtr ColumnDecimal<T>::replicate(const IColumn::Offsets & offsets) const
|
||||
return res;
|
||||
|
||||
typename Self::Container & res_data = res->getData();
|
||||
res_data.reserve(offsets.back());
|
||||
res_data.reserve_exact(offsets.back());
|
||||
|
||||
IColumn::Offset prev_offset = 0;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
size_t byteSizeAt(size_t) const override { return sizeof(data[0]); }
|
||||
size_t allocatedBytes() const override { return data.allocated_bytes(); }
|
||||
void protect() override { data.protect(); }
|
||||
void reserve(size_t n) override { data.reserve(n); }
|
||||
void reserve(size_t n) override { data.reserve_exact(n); }
|
||||
void shrinkToFit() override { data.shrink_to_fit(); }
|
||||
|
||||
void insertFrom(const IColumn & src, size_t n) override { data.push_back(static_cast<const Self &>(src).getData()[n]); }
|
||||
|
@ -224,7 +224,7 @@ ColumnPtr ColumnFixedString::filter(const IColumn::Filter & filt, ssize_t result
|
||||
auto res = ColumnFixedString::create(n);
|
||||
|
||||
if (result_size_hint)
|
||||
res->chars.reserve(result_size_hint > 0 ? result_size_hint * n : chars.size());
|
||||
res->chars.reserve_exact(result_size_hint > 0 ? result_size_hint * n : chars.size());
|
||||
|
||||
const UInt8 * filt_pos = filt.data();
|
||||
const UInt8 * filt_end = filt_pos + col_size;
|
||||
|
@ -184,7 +184,7 @@ public:
|
||||
|
||||
void reserve(size_t size) override
|
||||
{
|
||||
chars.reserve(n * size);
|
||||
chars.reserve_exact(n * size);
|
||||
}
|
||||
|
||||
void shrinkToFit() override
|
||||
|
@ -191,7 +191,7 @@ void ColumnSparse::insertRangeFrom(const IColumn & src, size_t start, size_t len
|
||||
|
||||
if (offset_start != offset_end)
|
||||
{
|
||||
offsets_data.reserve(offsets_data.size() + offset_end - offset_start);
|
||||
offsets_data.reserve_exact(offsets_data.size() + offset_end - offset_start);
|
||||
insertManyDefaults(src_offsets[offset_start] - start);
|
||||
offsets_data.push_back(_size);
|
||||
++_size;
|
||||
@ -302,7 +302,7 @@ ColumnPtr ColumnSparse::filter(const Filter & filt, ssize_t) const
|
||||
auto & res_offsets_data = assert_cast<ColumnUInt64 &>(*res_offsets).getData();
|
||||
|
||||
Filter values_filter;
|
||||
values_filter.reserve(values->size());
|
||||
values_filter.reserve_exact(values->size());
|
||||
values_filter.push_back(1);
|
||||
size_t values_result_size_hint = 1;
|
||||
|
||||
@ -632,7 +632,7 @@ ColumnPtr ColumnSparse::replicate(const Offsets & replicate_offsets) const
|
||||
if (!offset_it.isDefault())
|
||||
{
|
||||
size_t replicate_size = replicate_offsets[i] - replicate_offsets[i - 1];
|
||||
res_offsets_data.reserve(res_offsets_data.size() + replicate_size);
|
||||
res_offsets_data.reserve_exact(res_offsets_data.size() + replicate_size);
|
||||
for (size_t row = replicate_offsets[i - 1]; row < replicate_offsets[i]; ++row)
|
||||
{
|
||||
res_offsets_data.push_back(row);
|
||||
|
@ -122,7 +122,7 @@ void ColumnString::insertRangeFrom(const IColumn & src, size_t start, size_t len
|
||||
size_t nested_length = src_concrete.offsets[start + length - 1] - nested_offset;
|
||||
|
||||
/// Reserve offsets before to make it more exception safe (in case of MEMORY_LIMIT_EXCEEDED)
|
||||
offsets.reserve(offsets.size() + length);
|
||||
offsets.reserve_exact(offsets.size() + length);
|
||||
|
||||
size_t old_chars_size = chars.size();
|
||||
chars.resize(old_chars_size + nested_length);
|
||||
@ -453,8 +453,8 @@ ColumnPtr ColumnString::replicate(const Offsets & replicate_offsets) const
|
||||
|
||||
Chars & res_chars = res->chars;
|
||||
Offsets & res_offsets = res->offsets;
|
||||
res_chars.reserve(chars.size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve(replicate_offsets.back());
|
||||
res_chars.reserve_exact(chars.size() / col_size * replicate_offsets.back());
|
||||
res_offsets.reserve_exact(replicate_offsets.back());
|
||||
|
||||
Offset prev_replicate_offset = 0;
|
||||
Offset prev_string_offset = 0;
|
||||
@ -491,7 +491,7 @@ void ColumnString::gather(ColumnGathererStream & gatherer)
|
||||
|
||||
void ColumnString::reserve(size_t n)
|
||||
{
|
||||
offsets.reserve(n);
|
||||
offsets.reserve_exact(n);
|
||||
}
|
||||
|
||||
void ColumnString::shrinkToFit()
|
||||
|
@ -37,9 +37,9 @@ class WriteHelper
|
||||
column.resize(rows);
|
||||
else
|
||||
{
|
||||
column.getOffsets().reserve(rows);
|
||||
column.getOffsets().reserve_exact(rows);
|
||||
/// Using coefficient 2 for initial size is arbitrary.
|
||||
column.getChars().resize(rows * 2);
|
||||
column.getChars().reserve_exact(rows * 2);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ void ColumnVariant::insertRangeFrom(const IColumn & src_, size_t start, size_t l
|
||||
variants[local_discr]->insertRangeFrom(*src.variants[*non_empty_src_local_discr], start, length);
|
||||
getLocalDiscriminators().resize_fill(local_discriminators->size() + length, local_discr);
|
||||
auto & offsets_data = getOffsets();
|
||||
offsets_data.reserve(offsets_data.size() + length);
|
||||
offsets_data.reserve_exact(offsets_data.size() + length);
|
||||
for (size_t i = 0; i != length; ++i)
|
||||
offsets_data.push_back(offset++);
|
||||
return;
|
||||
@ -505,9 +505,9 @@ void ColumnVariant::insertRangeFrom(const IColumn & src_, size_t start, size_t l
|
||||
/// nested_ranges[i].second - length in src.variants[i]
|
||||
std::vector<std::pair<size_t, size_t>> nested_ranges(num_variants, {0, 0});
|
||||
auto & offsets_data = getOffsets();
|
||||
offsets_data.reserve(offsets_data.size() + length);
|
||||
offsets_data.reserve_exact(offsets_data.size() + length);
|
||||
auto & local_discriminators_data = getLocalDiscriminators();
|
||||
local_discriminators_data.reserve(local_discriminators_data.size() + length);
|
||||
local_discriminators_data.reserve_exact(local_discriminators_data.size() + length);
|
||||
const auto & src_offsets_data = src.getOffsets();
|
||||
const auto & src_local_discriminators_data = src.getLocalDiscriminators();
|
||||
for (size_t i = start; i != start + length; ++i)
|
||||
@ -561,7 +561,7 @@ void ColumnVariant::insertManyFrom(const DB::IColumn & src_, size_t position, si
|
||||
else
|
||||
{
|
||||
size_t prev_offset = variants[local_discr]->size();
|
||||
offsets_data.reserve(offsets_data.size() + length);
|
||||
offsets_data.reserve_exact(offsets_data.size() + length);
|
||||
for (size_t i = 0; i != length; ++i)
|
||||
offsets_data.push_back(prev_offset + i);
|
||||
|
||||
@ -761,7 +761,7 @@ ColumnPtr ColumnVariant::filter(const Filter & filt, ssize_t result_size_hint) c
|
||||
const size_t num_variants = variants.size();
|
||||
std::vector<Filter> nested_filters(num_variants);
|
||||
for (size_t i = 0; i != num_variants; ++i)
|
||||
nested_filters[i].reserve(variants[i]->size());
|
||||
nested_filters[i].reserve_exact(variants[i]->size());
|
||||
|
||||
/// As we will iterate through local_discriminators anyway, we can count
|
||||
/// result size for each variant.
|
||||
@ -877,7 +877,7 @@ ColumnPtr ColumnVariant::indexImpl(const PaddedPODArray<Type> & indexes, size_t
|
||||
if (limit == 0)
|
||||
{
|
||||
for (size_t i = 0; i != num_variants; ++i)
|
||||
nested_perms[i].reserve(variants[i]->size());
|
||||
nested_perms[i].reserve_exact(variants[i]->size());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i != new_local_discriminators_data.size(); ++i)
|
||||
@ -940,7 +940,7 @@ ColumnPtr ColumnVariant::replicate(const Offsets & replicate_offsets) const
|
||||
size_t old_size = offsets->size();
|
||||
if (new_size > old_size)
|
||||
{
|
||||
new_offsets_data.reserve(new_size);
|
||||
new_offsets_data.reserve_exact(new_size);
|
||||
for (size_t i = old_size; i < new_size; ++i)
|
||||
new_offsets_data.push_back(i);
|
||||
}
|
||||
@ -956,7 +956,7 @@ ColumnPtr ColumnVariant::replicate(const Offsets & replicate_offsets) const
|
||||
/// local_discriminators column.
|
||||
std::vector<Offsets> nested_replicated_offsets(num_variants);
|
||||
for (size_t i = 0; i != num_variants; ++i)
|
||||
nested_replicated_offsets[i].reserve(variants[i]->size());
|
||||
nested_replicated_offsets[i].reserve_exact(variants[i]->size());
|
||||
|
||||
const auto & local_discriminators_data = getLocalDiscriminators();
|
||||
for (size_t i = 0; i != local_discriminators_data.size(); ++i)
|
||||
@ -1030,7 +1030,7 @@ MutableColumns ColumnVariant::scatter(ColumnIndex num_columns, const Selector &
|
||||
/// Create selector for each variant according to local_discriminators.
|
||||
std::vector<Selector> nested_selectors(num_variants);
|
||||
for (size_t i = 0; i != num_variants; ++i)
|
||||
nested_selectors[i].reserve(variants[i]->size());
|
||||
nested_selectors[i].reserve_exact(variants[i]->size());
|
||||
|
||||
const auto & local_discriminators_data = getLocalDiscriminators();
|
||||
for (size_t i = 0; i != local_discriminators_data.size(); ++i)
|
||||
@ -1288,7 +1288,7 @@ void ColumnVariant::applyNullMapImpl(const ColumnVector<UInt8>::Container & null
|
||||
else
|
||||
{
|
||||
ColumnVector<UInt8>::Container filter;
|
||||
filter.reserve(null_map.size());
|
||||
filter.reserve_exact(null_map.size());
|
||||
for (size_t i = 0; i != local_discriminators_data.size(); ++i)
|
||||
{
|
||||
if (null_map[i])
|
||||
|
@ -645,7 +645,7 @@ ColumnPtr ColumnVector<T>::filter(const IColumn::Filter & filt, ssize_t result_s
|
||||
Container & res_data = res->getData();
|
||||
|
||||
if (result_size_hint)
|
||||
res_data.reserve(result_size_hint > 0 ? result_size_hint : size);
|
||||
res_data.reserve_exact(result_size_hint > 0 ? result_size_hint : size);
|
||||
|
||||
const UInt8 * filt_pos = filt.data();
|
||||
const UInt8 * filt_end = filt_pos + size;
|
||||
|
@ -179,7 +179,7 @@ public:
|
||||
|
||||
void reserve(size_t n) override
|
||||
{
|
||||
data.reserve(n);
|
||||
data.reserve_exact(n);
|
||||
}
|
||||
|
||||
void shrinkToFit() override
|
||||
|
@ -133,7 +133,7 @@ namespace
|
||||
|
||||
void reserve(ssize_t result_size_hint, size_t src_size)
|
||||
{
|
||||
res_offsets.reserve(result_size_hint > 0 ? result_size_hint : src_size);
|
||||
res_offsets.reserve_exact(result_size_hint > 0 ? result_size_hint : src_size);
|
||||
}
|
||||
|
||||
void insertOne(size_t array_size)
|
||||
@ -205,9 +205,9 @@ namespace
|
||||
result_offsets_builder.reserve(result_size_hint, size);
|
||||
|
||||
if (result_size_hint < 0)
|
||||
res_elems.reserve(src_elems.size());
|
||||
res_elems.reserve_exact(src_elems.size());
|
||||
else if (result_size_hint < 1000000000 && src_elems.size() < 1000000000) /// Avoid overflow.
|
||||
res_elems.reserve((result_size_hint * src_elems.size() + size - 1) / size);
|
||||
res_elems.reserve_exact((result_size_hint * src_elems.size() + size - 1) / size);
|
||||
}
|
||||
|
||||
const UInt8 * filt_pos = filt.data();
|
||||
|
@ -210,7 +210,7 @@ template <typename Derived>
|
||||
void IColumn::getIndicesOfNonDefaultRowsImpl(Offsets & indices, size_t from, size_t limit) const
|
||||
{
|
||||
size_t to = limit && from + limit < size() ? from + limit : size();
|
||||
indices.reserve(indices.size() + to - from);
|
||||
indices.reserve_exact(indices.size() + to - from);
|
||||
|
||||
for (size_t i = from; i < to; ++i)
|
||||
{
|
||||
|
@ -842,7 +842,6 @@ void IMergeTreeDataPart::loadIndex()
|
||||
|
||||
for (size_t i = 0; i < key_size; ++i)
|
||||
{
|
||||
loaded_index[i]->shrinkToFit();
|
||||
loaded_index[i]->protect();
|
||||
if (loaded_index[i]->size() != marks_count)
|
||||
throw Exception(ErrorCodes::CANNOT_READ_ALL_DATA, "Cannot read all data from index file {}(expected size: "
|
||||
|
Loading…
Reference in New Issue
Block a user