Skip to content

Commit

Permalink
remove from ColumnDefine
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <[email protected]>
  • Loading branch information
Lloyd-Pottiger committed Sep 27, 2024
1 parent 1d84d9e commit 571ef32
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
13 changes: 1 addition & 12 deletions dbms/src/Storages/DeltaMerge/DeltaMergeDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,11 @@ struct ColumnDefine
DataTypePtr type;
Field default_value;

/// Note: ColumnDefine is used in both Write path and Read path.
/// In the read path, vector_index is usually not available. Use AnnQueryInfo for
/// read related vector index information.
TiDB::VectorIndexDefinitionPtr vector_index;

explicit ColumnDefine(
ColId id_ = 0,
String name_ = "",
DataTypePtr type_ = nullptr,
Field default_value_ = Field{},
TiDB::VectorIndexDefinitionPtr vector_index_ = nullptr)
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_))
, vector_index(vector_index_)
{}
};

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ void DeltaMergeStore::applySchemaChanges(TiDB::TableInfo & table_info)

std::atomic_store(&original_table_header, std::make_shared<Block>(toEmptyBlock(original_table_columns)));

// release the lock because `applyLocalIndexChange ` will try to acquire the lock
// release the lock because `applyLocalIndexChange` will try to acquire the lock
// and generate tasks on segments
lock.unlock();

Expand Down
25 changes: 9 additions & 16 deletions dbms/src/Storages/DeltaMerge/tests/gtest_dm_vector_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ try
{
auto cols = DMTestEnv::getDefaultColumns(DMTestEnv::PkType::HiddenTiDBRowID, /*add_nullable*/ true);
auto vec_cd = ColumnDefine(vec_column_id, vec_column_name, tests::typeFromString("Array(Float32)"));
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
auto vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
.kind = tipb::VectorIndexKind::HNSW,
.dimension = 3,
.distance_metric = tipb::VectorDistanceMetric::L2,
Expand All @@ -229,7 +229,7 @@ try
}

dm_file = restoreDMFile();
dm_file = buildIndex(*vec_cd.vector_index);
dm_file = buildIndex(*vector_index);

// Read with exact match
{
Expand Down Expand Up @@ -836,7 +836,7 @@ try
{
auto cols = DMTestEnv::getDefaultColumns(DMTestEnv::PkType::HiddenTiDBRowID, /*add_nullable*/ true);
auto vec_cd = ColumnDefine(vec_column_id, vec_column_name, tests::typeFromString("Array(Float32)"));
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
auto vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
.kind = tipb::VectorIndexKind::HNSW,
.dimension = 3,
.distance_metric = tipb::VectorDistanceMetric::L2,
Expand Down Expand Up @@ -866,7 +866,7 @@ try
}

dm_file = restoreDMFile();
dm_file = buildIndex(*vec_cd.vector_index);
dm_file = buildIndex(*vector_index);

{
auto ann_query_info = std::make_shared<tipb::ANNQueryInfo>();
Expand Down Expand Up @@ -904,7 +904,7 @@ try
{
auto cols = DMTestEnv::getDefaultColumns(DMTestEnv::PkType::HiddenTiDBRowID, /*add_nullable*/ true);
auto vec_cd = ColumnDefine(vec_column_id, vec_column_name, tests::typeFromString("Array(Float32)"));
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
auto vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
.kind = tipb::VectorIndexKind::HNSW,
.dimension = 3,
.distance_metric = tipb::VectorDistanceMetric::L2,
Expand Down Expand Up @@ -933,7 +933,7 @@ try
}

dm_file = restoreDMFile();
dm_file = buildIndex(*vec_cd.vector_index);
dm_file = buildIndex(*vector_index);

// Pack #0 is filtered out according to VecIndex
{
Expand Down Expand Up @@ -1045,7 +1045,7 @@ try
{
auto cols = DMTestEnv::getDefaultColumns(DMTestEnv::PkType::HiddenTiDBRowID, /*add_nullable*/ true);
auto vec_cd = ColumnDefine(vec_column_id, vec_column_name, tests::typeFromString("Array(Float32)"));
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
auto vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
.kind = tipb::VectorIndexKind::HNSW,
.dimension = 1,
.distance_metric = tipb::VectorDistanceMetric::L2,
Expand Down Expand Up @@ -1076,7 +1076,7 @@ try
}

dm_file = restoreDMFile();
dm_file = buildIndex(*vec_cd.vector_index);
dm_file = buildIndex(*vector_index);

// Pack Filter using RowKeyRange
{
Expand Down Expand Up @@ -1223,11 +1223,6 @@ class VectorIndexSegmentTestBase
void prepareColumns(const ColumnDefinesPtr & columns) override
{
auto vec_cd = ColumnDefine(vec_column_id, vec_column_name, tests::typeFromString("Array(Float32)"));
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(TiDB::VectorIndexDefinition{
.kind = tipb::VectorIndexKind::HNSW,
.dimension = 1,
.distance_metric = tipb::VectorDistanceMetric::L2,
});
columns->emplace_back(vec_cd);
}

Expand Down Expand Up @@ -1752,9 +1747,7 @@ class VectorIndexSegmentOnS3Test
FileCache::initialize(global_context.getPathCapacity(), file_cache_config);

auto cols = DMTestEnv::getDefaultColumns();
auto vec_cd = cdVec();
vec_cd.vector_index = std::make_shared<TiDB::VectorIndexDefinition>(index_info);
cols->emplace_back(vec_cd);
cols->emplace_back(cdVec());
setColumns(cols);

auto dm_context = dmContext();
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/StorageDeltaMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void StorageDeltaMerge::updateTableColumnInfo()
table_column_defines.begin(),
table_column_defines.end(),
[](const ColumnDefine & col, FmtBuffer & fb) {
fb.fmtAppend("{} {} {}", col.name, col.type->getFamilyName(), col.vector_index);
fb.fmtAppend("{} {}", col.name, col.type->getFamilyName());
},
", ");
return fmt_buf.toString();
Expand Down

0 comments on commit 571ef32

Please sign in to comment.