-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
storage: Add system.dt_local_indexes #9379
Merged
ti-chi-bot
merged 1 commit into
pingcap:feature/vector-index
from
Lloyd-Pottiger:add-dt_local_indexes
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 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 <Storages/KVStore/Types.h> | ||
#include <TiDB/Schema/VectorIndex.h> | ||
|
||
namespace DB::DM | ||
{ | ||
|
||
enum class IndexType | ||
{ | ||
Vector = 1, | ||
}; | ||
|
||
struct IndexInfo | ||
{ | ||
IndexType type; | ||
ColumnID column_id; | ||
String column_name; | ||
// Now we only support vector index. | ||
// In the future, we may support more types of indexes, using std::variant. | ||
TiDB::VectorIndexDefinitionPtr index_definition; | ||
}; | ||
|
||
using IndexInfos = std::vector<IndexInfo>; | ||
using IndexInfosPtr = std::shared_ptr<IndexInfos>; | ||
|
||
} // namespace DB::DM |
135 changes: 135 additions & 0 deletions
135
dbms/src/Storages/System/StorageSystemDTLocalIndexes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2024 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. | ||
|
||
#include <Columns/ColumnString.h> | ||
#include <DataStreams/OneBlockInputStream.h> | ||
#include <DataTypes/DataTypeNullable.h> | ||
#include <DataTypes/DataTypeString.h> | ||
#include <DataTypes/DataTypesNumber.h> | ||
#include <Databases/DatabaseTiFlash.h> | ||
#include <Databases/IDatabase.h> | ||
#include <Interpreters/Context.h> | ||
#include <Storages/DeltaMerge/DeltaMergeStore.h> | ||
#include <Storages/KVStore/Types.h> | ||
#include <Storages/MutableSupport.h> | ||
#include <Storages/StorageDeltaMerge.h> | ||
#include <Storages/System/StorageSystemDTLocalIndexes.h> | ||
#include <TiDB/Schema/SchemaNameMapper.h> | ||
|
||
namespace DB | ||
{ | ||
StorageSystemDTLocalIndexes::StorageSystemDTLocalIndexes(const std::string & name_) | ||
: name(name_) | ||
{ | ||
setColumns(ColumnsDescription({ | ||
{"database", std::make_shared<DataTypeString>()}, | ||
{"table", std::make_shared<DataTypeString>()}, | ||
|
||
{"tidb_database", std::make_shared<DataTypeString>()}, | ||
{"tidb_table", std::make_shared<DataTypeString>()}, | ||
{"keyspace_id", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())}, | ||
{"table_id", std::make_shared<DataTypeInt64>()}, | ||
|
||
{"column_name", std::make_shared<DataTypeString>()}, | ||
{"column_id", std::make_shared<DataTypeUInt64>()}, | ||
{"index_kind", std::make_shared<DataTypeString>()}, | ||
|
||
{"rows_stable_indexed", std::make_shared<DataTypeUInt64>()}, // Total rows | ||
{"rows_stable_not_indexed", std::make_shared<DataTypeUInt64>()}, // Total rows | ||
{"rows_delta_indexed", std::make_shared<DataTypeUInt64>()}, // Total rows | ||
{"rows_delta_not_indexed", std::make_shared<DataTypeUInt64>()}, // Total rows | ||
})); | ||
} | ||
|
||
BlockInputStreams StorageSystemDTLocalIndexes::read( | ||
const Names & column_names, | ||
const SelectQueryInfo &, | ||
const Context & context, | ||
QueryProcessingStage::Enum & processed_stage, | ||
const size_t /*max_block_size*/, | ||
const unsigned /*num_streams*/) | ||
{ | ||
check(column_names); | ||
processed_stage = QueryProcessingStage::FetchColumns; | ||
|
||
MutableColumns res_columns = getSampleBlock().cloneEmptyColumns(); | ||
|
||
SchemaNameMapper mapper; | ||
|
||
auto databases = context.getDatabases(); | ||
for (const auto & d : databases) | ||
{ | ||
String database_name = d.first; | ||
const auto & database = d.second; | ||
const DatabaseTiFlash * db_tiflash = typeid_cast<DatabaseTiFlash *>(database.get()); | ||
|
||
auto it = database->getIterator(context); | ||
for (; it->isValid(); it->next()) | ||
{ | ||
const auto & table_name = it->name(); | ||
auto & storage = it->table(); | ||
if (storage->getName() != MutableSupport::delta_tree_storage_name) | ||
continue; | ||
|
||
auto dm_storage = std::dynamic_pointer_cast<StorageDeltaMerge>(storage); | ||
const auto & table_info = dm_storage->getTableInfo(); | ||
auto table_id = table_info.id; | ||
auto store = dm_storage->getStoreIfInited(); | ||
if (!store) | ||
continue; | ||
|
||
if (dm_storage->isTombstone()) | ||
continue; | ||
|
||
auto index_stats = store->getLocalIndexStats(); | ||
for (auto & stat : index_stats) | ||
{ | ||
size_t j = 0; | ||
res_columns[j++]->insert(database_name); | ||
res_columns[j++]->insert(table_name); | ||
|
||
String tidb_db_name; | ||
KeyspaceID keyspace_id = NullspaceID; | ||
if (db_tiflash) | ||
{ | ||
tidb_db_name = db_tiflash->getDatabaseInfo().name; | ||
keyspace_id = db_tiflash->getDatabaseInfo().keyspace_id; | ||
} | ||
res_columns[j++]->insert(tidb_db_name); | ||
String tidb_table_name = table_info.name; | ||
res_columns[j++]->insert(tidb_table_name); | ||
if (keyspace_id == NullspaceID) | ||
res_columns[j++]->insert(Field()); | ||
else | ||
res_columns[j++]->insert(static_cast<UInt64>(keyspace_id)); | ||
res_columns[j++]->insert(table_id); | ||
|
||
res_columns[j++]->insert(stat.column_name); | ||
res_columns[j++]->insert(stat.column_id); | ||
res_columns[j++]->insert(stat.index_kind); | ||
|
||
res_columns[j++]->insert(stat.rows_stable_indexed); | ||
res_columns[j++]->insert(stat.rows_stable_not_indexed); | ||
res_columns[j++]->insert(stat.rows_delta_indexed); | ||
res_columns[j++]->insert(stat.rows_delta_not_indexed); | ||
} | ||
} | ||
} | ||
|
||
return BlockInputStreams( | ||
1, | ||
std::make_shared<OneBlockInputStream>(getSampleBlock().cloneWithColumns(std::move(res_columns)))); | ||
} | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2024 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 <Storages/IStorage.h> | ||
|
||
#include <ext/shared_ptr_helper.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
class Context; | ||
|
||
class StorageSystemDTLocalIndexes | ||
: public ext::SharedPtrHelper<StorageSystemDTLocalIndexes> | ||
, public IStorage | ||
{ | ||
public: | ||
std::string getName() const override { return "SystemDTLocalIndexes"; } | ||
std::string getTableName() const override { return name; } | ||
|
||
BlockInputStreams read( | ||
const Names & column_names, | ||
const SelectQueryInfo & query_info, | ||
const Context & context, | ||
QueryProcessingStage::Enum & processed_stage, | ||
size_t max_block_size, | ||
unsigned num_streams) override; | ||
|
||
private: | ||
const std::string name; | ||
|
||
protected: | ||
explicit StorageSystemDTLocalIndexes(const std::string & name_); | ||
}; | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What're these comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total rows of all segments.