ClickHouse: fixed FixedString. [#METR-9372]

This commit is contained in:
Michael Kolupaev 2013-12-03 10:01:04 +00:00
parent 6f46eb052c
commit d2010d7876
3 changed files with 15 additions and 4 deletions

View File

@ -15,7 +15,6 @@ namespace DB
class ColumnFixedString : public IColumn class ColumnFixedString : public IColumn
{ {
public: public:
//typedef std::vector<UInt8> Chars_t;
typedef PODArray<UInt8> Chars_t; typedef PODArray<UInt8> Chars_t;
private: private:
@ -78,7 +77,7 @@ public:
throw Exception("Too large string '" + s + "' for FixedString column", ErrorCodes::TOO_LARGE_STRING_SIZE); throw Exception("Too large string '" + s + "' for FixedString column", ErrorCodes::TOO_LARGE_STRING_SIZE);
size_t old_size = chars.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()); memcpy(&chars[old_size], s.data(), s.size());
} }
@ -103,7 +102,7 @@ public:
void insertDefault() 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 int compareAt(size_t p1, size_t p2, const IColumn & rhs_, int nan_direction_hint) const

View File

@ -208,6 +208,18 @@ public:
c_end = c_start + byte_size(n); 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() void clear()
{ {
c_end = c_start; c_end = c_start;

View File

@ -45,7 +45,7 @@ template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
ColumnPtr res_ptr = res; ColumnPtr res_ptr = res;
ColumnFixedString::Chars_t & vec = res->getChars(); ColumnFixedString::Chars_t & vec = res->getChars();
vec.resize(n * s); vec.resize_fill(n * s);
size_t offset = 0; size_t offset = 0;
for (size_t i = 0; i < s; ++i) for (size_t i = 0; i < s; ++i)