diff --git a/dbms/src/Columns/ColumnArray.cpp b/dbms/src/Columns/ColumnArray.cpp index 5635b8efc26..118398b8c95 100644 --- a/dbms/src/Columns/ColumnArray.cpp +++ b/dbms/src/Columns/ColumnArray.cpp @@ -321,19 +321,13 @@ bool ColumnArray::hasEqualOffsets(const ColumnArray & other) const ColumnPtr ColumnArray::convertToFullColumnIfConst() const { ColumnPtr new_data; - ColumnPtr new_offsets; if (auto full_column = getData().convertToFullColumnIfConst()) new_data = full_column; else new_data = data; - if (auto full_column = offsets->convertToFullColumnIfConst()) - new_offsets = full_column; - else - new_offsets = offsets; - - return std::make_shared(new_data, new_offsets); + return std::make_shared(new_data, offsets); } diff --git a/dbms/src/Columns/ColumnNullable.cpp b/dbms/src/Columns/ColumnNullable.cpp index c5e7e77e7ad..38cd0d96ab1 100644 --- a/dbms/src/Columns/ColumnNullable.cpp +++ b/dbms/src/Columns/ColumnNullable.cpp @@ -35,17 +35,6 @@ ColumnNullable::ColumnNullable(ColumnPtr nested_column_, ColumnPtr null_map_) } -ColumnPtr ColumnNullable::convertToFullColumnIfConst() const -{ - ColumnPtr new_col_holder; - - if (auto full_col = nested_column->convertToFullColumnIfConst()) - new_col_holder = std::make_shared(full_col, null_map); - - return new_col_holder; -} - - void ColumnNullable::updateHashWithValue(size_t n, SipHash & hash) const { const auto & arr = getNullMap(); diff --git a/dbms/src/Columns/ColumnNullable.h b/dbms/src/Columns/ColumnNullable.h index 2b589b5697e..f4c561edf50 100644 --- a/dbms/src/Columns/ColumnNullable.h +++ b/dbms/src/Columns/ColumnNullable.h @@ -53,7 +53,6 @@ public: size_t byteSize() const override; size_t allocatedBytes() const override; ColumnPtr replicate(const Offsets_t & replicate_offsets) const override; - ColumnPtr convertToFullColumnIfConst() const override; void updateHashWithValue(size_t n, SipHash & hash) const override; void getExtremes(Field & min, Field & max) const override; diff --git a/dbms/src/Columns/ColumnTuple.cpp b/dbms/src/Columns/ColumnTuple.cpp index c8537825f03..7ddbf2e36bd 100644 --- a/dbms/src/Columns/ColumnTuple.cpp +++ b/dbms/src/Columns/ColumnTuple.cpp @@ -284,18 +284,6 @@ size_t ColumnTuple::allocatedBytes() const return res; } -ColumnPtr ColumnTuple::convertToFullColumnIfConst() const -{ - const size_t tuple_size = columns.size(); - Columns new_columns(columns); - - for (size_t i = 0; i < tuple_size; ++i) - if (auto converted = columns[i]->convertToFullColumnIfConst()) - new_columns[i] = converted; - - return std::make_shared(new_columns); -} - void ColumnTuple::getExtremes(Field & min, Field & max) const { const size_t tuple_size = columns.size(); diff --git a/dbms/src/Columns/ColumnTuple.h b/dbms/src/Columns/ColumnTuple.h index a3c5e7a5ede..e2931bf5d3b 100644 --- a/dbms/src/Columns/ColumnTuple.h +++ b/dbms/src/Columns/ColumnTuple.h @@ -57,7 +57,6 @@ public: void reserve(size_t n) override; size_t byteSize() const override; size_t allocatedBytes() const override; - ColumnPtr convertToFullColumnIfConst() const override; void forEachSubcolumn(ColumnCallback callback) override; const Columns & getColumns() const { return columns; } diff --git a/dbms/src/Columns/IColumn.h b/dbms/src/Columns/IColumn.h index e02917398a3..c3bfa47383d 100644 --- a/dbms/src/Columns/IColumn.h +++ b/dbms/src/Columns/IColumn.h @@ -44,9 +44,6 @@ public: /** If column isn't constant, returns nullptr (or itself). * If column is constant, transforms constant to full column (if column type allows such tranform) and return it. - * Special case: - * If column is composed from several other columns (tuple for example), and contains both constant and full columns, - * then each constant column is transformed, and final result is returned. */ virtual ColumnPtr convertToFullColumnIfConst() const { return {}; } @@ -245,8 +242,8 @@ public: /// Zero, if could be determined. virtual size_t allocatedBytes() const = 0; - /// If the column contains subcolumns (such as Array, Nullable, etc), enumerate them. - /// Shallow: doesn't do recursive calls. + /// If the column contains subcolumns (such as Array, Nullable, etc), do callback on them. + /// Shallow: doesn't do recursive calls; don't do call for itself. using ColumnCallback = std::function; virtual void forEachSubcolumn(ColumnCallback) {} @@ -270,6 +267,23 @@ public: /// It's a special kind of column, that contain single value, but is not a ColumnConst. virtual bool isDummy() const { return false; } + /** Memory layout properties. + * + * Each value of a column can be placed in memory contiguously or not. + * + * Example: simple columns like UInt64 or FixedString store their values contiguously in single memory buffer. + * + * Example: Tuple store values of each component in separate subcolumn, so the values of Tuples with at least two components are not contiguous. + * Another example is Nullable. Each value have null flag, that is stored separately, so the value is not contiguous in memory. + * + * There are some important cases, when values are not stored contiguously, but for each value, you can get contiguous memory segment, + * that will unambiguously identify the value. In this case, methods getDataAt and insertData are implemented. + * Example: String column: bytes of strings are stored concatenated in one memory buffer + * and offsets to that buffer are stored in another buffer. The same is for Array of fixed-size contiguous elements. + * + * To avoid confusion between these cases, we don't have isContiguous method. + */ + /// Values in column have fixed size (including the case when values span many memory segments). virtual bool valuesHaveFixedSize() const { return isFixedAndContiguous(); } @@ -293,6 +307,8 @@ public: virtual ~IColumn() {} + /** Print column name, size, and recursively print all subcolumns. + */ String dumpStructure() const; protected: diff --git a/dbms/src/DataTypes/IDataType.h b/dbms/src/DataTypes/IDataType.h index de31b17cfd2..de51afa9225 100644 --- a/dbms/src/DataTypes/IDataType.h +++ b/dbms/src/DataTypes/IDataType.h @@ -204,7 +204,7 @@ public: /** Create constant column for corresponding type, with specified size and value. */ - virtual ColumnPtr createConstColumn(size_t size, const Field & field) const; + ColumnPtr createConstColumn(size_t size, const Field & field) const; /** Get default value of data type. * It is the "default" default, regardless the fact that a table could contain different user-specified default.