Skip to content

Commit

Permalink
Generate index stats from TableInfo for non-inited store
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Sep 26, 2024
1 parent b2e4b90 commit 2337578
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions dbms/src/Storages/System/StorageSystemDTLocalIndexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
#include <Databases/IDatabase.h>
#include <Interpreters/Context.h>
#include <Storages/DeltaMerge/DeltaMergeStore.h>
#include <Storages/DeltaMerge/Index/IndexInfo.h>
#include <Storages/KVStore/TMTStorages.h>
#include <Storages/KVStore/Types.h>
#include <Storages/MutableSupport.h>
#include <Storages/StorageDeltaMerge.h>
#include <Storages/System/StorageSystemDTLocalIndexes.h>
#include <TiDB/Schema/SchemaNameMapper.h>
#include <TiDB/Schema/TiDB.h>

namespace DB
{
Expand Down Expand Up @@ -55,6 +58,39 @@ StorageSystemDTLocalIndexes::StorageSystemDTLocalIndexes(const std::string & nam
}));
}

DM::LocalIndexesStats generateLocalIndexesStatsFromTableInfo(const TiDB::TableInfo & table_info)
{
auto local_index_infos = DM::generateLocalIndexInfos(nullptr, table_info, Logger::get());

DM::LocalIndexesStats stats;
if (!local_index_infos)
return stats;

for (const auto & index_info : *local_index_infos)
{
DM::LocalIndexStats index_stats;
index_stats.column_id = index_info.column_id;
index_stats.index_id = index_info.index_id;
index_stats.column_name = index_info.column_name;
index_stats.index_kind = "HNSW";
stats.emplace_back(std::move(index_stats));
}
return stats;
}

std::optional<DM::LocalIndexesStats> getLocalIndexesStatsFromStorage(const StorageDeltaMergePtr & dm_storage)
{
if (dm_storage->isTombstone())
return std::nullopt;

const auto & table_info = dm_storage->getTableInfo();
auto store = dm_storage->getStoreIfInited();
if (!store)
return generateLocalIndexesStatsFromTableInfo(table_info);

return store->getLocalIndexStats();
}

BlockInputStreams StorageSystemDTLocalIndexes::read(
const Names & column_names,
const SelectQueryInfo &,
Expand Down Expand Up @@ -87,16 +123,12 @@ BlockInputStreams StorageSystemDTLocalIndexes::read(

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;
const auto table_id = table_info.id;

if (dm_storage->isTombstone())
const auto index_stats = getLocalIndexesStatsFromStorage(dm_storage);
if (!index_stats)
continue;

auto index_stats = store->getLocalIndexStats();
for (auto & stat : index_stats)
for (const auto & stat : *index_stats)
{
size_t j = 0;
res_columns[j++]->insert(database_name);
Expand Down

0 comments on commit 2337578

Please sign in to comment.