From 7febe64c82dbe22bf7cbcfec8e2274d38c351971 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 21 Nov 2018 06:19:29 +0300 Subject: [PATCH] Failproof #3589 --- dbms/src/DataTypes/DataTypeString.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/dbms/src/DataTypes/DataTypeString.cpp b/dbms/src/DataTypes/DataTypeString.cpp index 166f1f6fb4f..2023523aa41 100644 --- a/dbms/src/DataTypes/DataTypeString.cpp +++ b/dbms/src/DataTypes/DataTypeString.cpp @@ -187,17 +187,23 @@ void DataTypeString::deserializeBinaryBulk(IColumn & column, ReadBuffer & istr, avg_chars_size = (avg_value_size_hint - sizeof(offsets[0])) * avg_value_size_hint_reserve_multiplier; } - try + size_t size_to_reserve = data.size() + std::ceil(limit * avg_chars_size); + + /// Never reserve for too big size. + if (size_to_reserve < 256 * 1024 * 1024) { - data.reserve(data.size() + std::ceil(limit * avg_chars_size)); - } - catch (Exception & e) - { - e.addMessage( - "(avg_value_size_hint = " + toString(avg_value_size_hint) - + ", avg_chars_size = " + toString(avg_chars_size) - + ", limit = " + toString(limit) + ")"); - throw; + try + { + data.reserve(size_to_reserve); + } + catch (Exception & e) + { + e.addMessage( + "(avg_value_size_hint = " + toString(avg_value_size_hint) + + ", avg_chars_size = " + toString(avg_chars_size) + + ", limit = " + toString(limit) + ")"); + throw; + } } offsets.reserve(offsets.size() + limit);