From c296dc67ce44910c5d35a9d92802770211d76a7e Mon Sep 17 00:00:00 2001 From: gvolfing <107616712+gvolfing@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:13:05 +0200 Subject: [PATCH] Add index count to index info (#1229) --- src/query/interpreter.cpp | 12 ++++++++---- .../show_while_creating_invalid_state.py | 2 +- .../show_index_info/test_show_index_info.py | 18 +++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index a55cba115..1dab6f84c 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -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> 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(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(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(); diff --git a/tests/e2e/replication/show_while_creating_invalid_state.py b/tests/e2e/replication/show_while_creating_invalid_state.py index d85f7e25e..be58f71ce 100644 --- a/tests/e2e/replication/show_while_creating_invalid_state.py +++ b/tests/e2e/replication/show_while_creating_invalid_state.py @@ -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) diff --git a/tests/e2e/show_index_info/test_show_index_info.py b/tests/e2e/show_index_info/test_show_index_info.py index 8c2dc7cdd..d13b46d01 100644 --- a/tests/e2e/show_index_info/test_show_index_info.py +++ b/tests/e2e/show_index_info/test_show_index_info.py @@ -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