Add index count to index info (#1229)

This commit is contained in:
gvolfing 2023-10-27 18:13:05 +02:00 committed by GitHub
parent 989bb97514
commit c296dc67ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 14 deletions

View File

@ -3016,19 +3016,23 @@ PreparedQuery PrepareDatabaseInfoQuery(ParsedQuery parsed_query, bool in_explici
switch (info_query->info_type_) {
case DatabaseInfoQuery::InfoType::INDEX: {
header = {"index type", "label", "property"};
header = {"index type", "label", "property", "count"};
handler = [storage = current_db.db_acc_->get()->storage(), dba] {
const std::string_view label_index_mark{"label"};
const std::string_view label_property_index_mark{"label+property"};
auto info = dba->ListAllIndices();
auto storage_acc = storage->Access();
std::vector<std::vector<TypedValue>> results;
results.reserve(info.label.size() + info.label_property.size());
for (const auto &item : info.label) {
results.push_back({TypedValue(label_index_mark), TypedValue(storage->LabelToName(item)), TypedValue()});
results.push_back({TypedValue(label_index_mark), TypedValue(storage->LabelToName(item)), TypedValue(),
TypedValue(static_cast<int>(storage_acc->ApproximateVertexCount(item)))});
}
for (const auto &item : info.label_property) {
results.push_back({TypedValue(label_property_index_mark), TypedValue(storage->LabelToName(item.first)),
TypedValue(storage->PropertyToName(item.second))});
results.push_back(
{TypedValue(label_property_index_mark), TypedValue(storage->LabelToName(item.first)),
TypedValue(storage->PropertyToName(item.second)),
TypedValue(static_cast<int>(storage_acc->ApproximateVertexCount(item.first, item.second)))});
}
std::sort(results.begin(), results.end(), [&label_index_mark](const auto &record_1, const auto &record_2) {
const auto type_1 = record_1[0].ValueString();

View File

@ -1052,7 +1052,7 @@ def test_attempt_to_create_indexes_on_main_when_sync_replica_is_down():
# 5/
expected_data = {
("sync_replica1", "127.0.0.1:10001", "sync", 0, 0, "invalid"),
("sync_replica2", "127.0.0.1:10002", "sync", 5, 0, "ready"),
("sync_replica2", "127.0.0.1:10002", "sync", 6, 0, "ready"),
}
res_from_main = interactive_mg_runner.MEMGRAPH_INSTANCES["main"].query(QUERY_TO_CHECK)
assert res_from_main == interactive_mg_runner.MEMGRAPH_INSTANCES["sync_replica2"].query(QUERY_TO_CHECK)

View File

@ -18,15 +18,15 @@ from common import Row, cursor, execute_and_fetch_all
def test_show_index_info(cursor):
index_info = execute_and_fetch_all(cursor, "SHOW INDEX INFO;")
expected_index_info = {
("label", "Anatomy", None),
("label", "Compound", None),
("label", "Disease", None),
("label", "Gene", None),
("label+property", "Compound", "id"),
("label+property", "Compound", "inchikey"),
("label+property", "Compound", "mgid"),
("label+property", "Gene", "i5"),
("label+property", "Gene", "id"),
("label", "Anatomy", None, 0),
("label", "Compound", None, 0),
("label", "Disease", None, 0),
("label", "Gene", None, 0),
("label+property", "Compound", "id", 0),
("label+property", "Compound", "inchikey", 0),
("label+property", "Compound", "mgid", 0),
("label+property", "Gene", "i5", 0),
("label+property", "Gene", "id", 0),
}
assert set(index_info) == expected_index_info