// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace TiDB { struct TableInfo; } // namespace TiDB namespace DB { namespace DM { /// S: Scale factor of delta tree node. /// M: Capacity factor of leaf node. /// F: Capacity factor of Intern node. /// For example, the max capacity of leaf node would be: M * S. static constexpr size_t DT_S = 3; static constexpr size_t DT_M = 55; static constexpr size_t DT_F = 20; using Ids = std::vector; template > class DeltaTree; template class DTEntryIterator; template > class DTEntriesCopy; struct EmptyValueSpace { void removeFromInsert(UInt64) {} }; using EntryIterator = DTEntryIterator; using DefaultDeltaTree = DeltaTree; using DeltaTreePtr = std::shared_ptr; using BlockPtr = std::shared_ptr; using RowId = UInt64; using ColId = DB::ColumnID; using Handle = DB::HandleID; using ColIds = std::vector; using HandlePair = std::pair; using RowsAndBytes = std::pair; using OptionTableInfoConstRef = std::optional>; struct ColumnDefine { ColId id; String name; DataTypePtr type; Field default_value; explicit ColumnDefine(ColId id_ = 0, String name_ = "", DataTypePtr type_ = nullptr, Field default_value_ = Field{}) : id(id_) , name(std::move(name_)) , type(std::move(type_)) , default_value(std::move(default_value_)) {} }; using ColumnMap = std::unordered_map; using MutableColumnMap = std::unordered_map; using LockGuard = std::lock_guard; inline static const UInt64 INITIAL_EPOCH = 0; // TODO maybe we should use those variables instead of macros? #define EXTRA_HANDLE_COLUMN_NAME ::DB::MutableSupport::tidb_pk_column_name #define VERSION_COLUMN_NAME ::DB::MutableSupport::version_column_name #define TAG_COLUMN_NAME ::DB::MutableSupport::delmark_column_name #define EXTRA_TABLE_ID_COLUMN_NAME ::DB::MutableSupport::extra_table_id_column_name #define EXTRA_HANDLE_COLUMN_ID ::DB::TiDBPkColumnID #define VERSION_COLUMN_ID ::DB::VersionColumnID #define TAG_COLUMN_ID ::DB::DelMarkColumnID #define EXTRA_TABLE_ID_COLUMN_ID ::DB::ExtraTableIDColumnID #define EXTRA_HANDLE_COLUMN_INT_TYPE ::DB::MutableSupport::tidb_pk_column_int_type #define EXTRA_HANDLE_COLUMN_STRING_TYPE ::DB::MutableSupport::tidb_pk_column_string_type #define VERSION_COLUMN_TYPE ::DB::MutableSupport::version_column_type #define TAG_COLUMN_TYPE ::DB::MutableSupport::delmark_column_type #define EXTRA_TABLE_ID_COLUMN_TYPE ::DB::MutableSupport::extra_table_id_column_type inline const ColumnDefine & getExtraIntHandleColumnDefine() { static ColumnDefine EXTRA_HANDLE_COLUMN_DEFINE_{ EXTRA_HANDLE_COLUMN_ID, EXTRA_HANDLE_COLUMN_NAME, EXTRA_HANDLE_COLUMN_INT_TYPE}; return EXTRA_HANDLE_COLUMN_DEFINE_; } inline const ColumnDefine & getExtraStringHandleColumnDefine() { static ColumnDefine EXTRA_HANDLE_COLUMN_DEFINE_{ EXTRA_HANDLE_COLUMN_ID, EXTRA_HANDLE_COLUMN_NAME, EXTRA_HANDLE_COLUMN_STRING_TYPE}; return EXTRA_HANDLE_COLUMN_DEFINE_; } inline const ColumnDefine & getExtraHandleColumnDefine(bool is_common_handle) { if (is_common_handle) return getExtraStringHandleColumnDefine(); return getExtraIntHandleColumnDefine(); } inline const ColumnDefine & getVersionColumnDefine() { static ColumnDefine VERSION_COLUMN_DEFINE_{VERSION_COLUMN_ID, VERSION_COLUMN_NAME, VERSION_COLUMN_TYPE}; return VERSION_COLUMN_DEFINE_; } inline const ColumnDefine & getTagColumnDefine() { static ColumnDefine TAG_COLUMN_DEFINE_{TAG_COLUMN_ID, TAG_COLUMN_NAME, TAG_COLUMN_TYPE}; return TAG_COLUMN_DEFINE_; } inline const ColumnDefine & getExtraTableIDColumnDefine() { static ColumnDefine EXTRA_TABLE_ID_COLUMN_DEFINE_{ EXTRA_TABLE_ID_COLUMN_ID, EXTRA_TABLE_ID_COLUMN_NAME, EXTRA_TABLE_ID_COLUMN_TYPE}; return EXTRA_TABLE_ID_COLUMN_DEFINE_; } static_assert( static_cast(static_cast(std::numeric_limits::min())) == std::numeric_limits::min(), "Unsupported compiler!"); static_assert( static_cast(static_cast(std::numeric_limits::max())) == std::numeric_limits::max(), "Unsupported compiler!"); static constexpr bool DM_RUN_CHECK = true; struct Attr { String col_name; ColId col_id; DataTypePtr type; }; using Attrs = std::vector; } // namespace DM } // namespace DB template <> struct fmt::formatter { template auto format(const DB::DM::ColumnDefine & cd, FormatContext & ctx) const -> decltype(ctx.out()) { return fmt::format_to(ctx.out(), "{}/{}", cd.id, cd.type->getName()); } };