diff --git a/dbms/include/DB/Columns/ColumnFixedString.h b/dbms/include/DB/Columns/ColumnFixedString.h index 0c1db840714..da2cfbc5e4f 100644 --- a/dbms/include/DB/Columns/ColumnFixedString.h +++ b/dbms/include/DB/Columns/ColumnFixedString.h @@ -15,7 +15,6 @@ namespace DB class ColumnFixedString : public IColumn { public: - //typedef std::vector Chars_t; typedef PODArray Chars_t; private: @@ -78,7 +77,7 @@ public: throw Exception("Too large string '" + s + "' for FixedString column", ErrorCodes::TOO_LARGE_STRING_SIZE); size_t old_size = chars.size(); - chars.resize(old_size + n); + chars.resize_fill(old_size + n); memcpy(&chars[old_size], s.data(), s.size()); } @@ -103,7 +102,7 @@ public: void insertDefault() { - chars.resize(chars.size() + n); + chars.resize_fill(chars.size() + n); } int compareAt(size_t p1, size_t p2, const IColumn & rhs_, int nan_direction_hint) const diff --git a/dbms/include/DB/Common/PODArray.h b/dbms/include/DB/Common/PODArray.h index 905fa9e46d9..f762476257f 100644 --- a/dbms/include/DB/Common/PODArray.h +++ b/dbms/include/DB/Common/PODArray.h @@ -208,6 +208,18 @@ public: c_end = c_start + byte_size(n); } + /// Как resize, но обнуляет новые элементы. + void resize_fill(size_t n) + { + size_t old_size = size(); + if (n > old_size) + { + reserve(n); + memset(c_end, 0, n - old_size); + } + c_end = c_start + byte_size(n); + } + void clear() { c_end = c_start; diff --git a/dbms/src/Columns/ColumnConst.cpp b/dbms/src/Columns/ColumnConst.cpp index 6d655761939..3a25e47aafa 100644 --- a/dbms/src/Columns/ColumnConst.cpp +++ b/dbms/src/Columns/ColumnConst.cpp @@ -45,7 +45,7 @@ template <> ColumnPtr ColumnConst::convertToFullColumn() const ColumnPtr res_ptr = res; ColumnFixedString::Chars_t & vec = res->getChars(); - vec.resize(n * s); + vec.resize_fill(n * s); size_t offset = 0; for (size_t i = 0; i < s; ++i)