Add index count to index info (#1229)
This commit is contained in:
parent
989bb97514
commit
c296dc67ce
@ -3016,19 +3016,23 @@ PreparedQuery PrepareDatabaseInfoQuery(ParsedQuery parsed_query, bool in_explici
|
|||||||
|
|
||||||
switch (info_query->info_type_) {
|
switch (info_query->info_type_) {
|
||||||
case DatabaseInfoQuery::InfoType::INDEX: {
|
case DatabaseInfoQuery::InfoType::INDEX: {
|
||||||
header = {"index type", "label", "property"};
|
header = {"index type", "label", "property", "count"};
|
||||||
handler = [storage = current_db.db_acc_->get()->storage(), dba] {
|
handler = [storage = current_db.db_acc_->get()->storage(), dba] {
|
||||||
const std::string_view label_index_mark{"label"};
|
const std::string_view label_index_mark{"label"};
|
||||||
const std::string_view label_property_index_mark{"label+property"};
|
const std::string_view label_property_index_mark{"label+property"};
|
||||||
auto info = dba->ListAllIndices();
|
auto info = dba->ListAllIndices();
|
||||||
|
auto storage_acc = storage->Access();
|
||||||
std::vector<std::vector<TypedValue>> results;
|
std::vector<std::vector<TypedValue>> results;
|
||||||
results.reserve(info.label.size() + info.label_property.size());
|
results.reserve(info.label.size() + info.label_property.size());
|
||||||
for (const auto &item : info.label) {
|
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) {
|
for (const auto &item : info.label_property) {
|
||||||
results.push_back({TypedValue(label_property_index_mark), TypedValue(storage->LabelToName(item.first)),
|
results.push_back(
|
||||||
TypedValue(storage->PropertyToName(item.second))});
|
{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) {
|
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();
|
const auto type_1 = record_1[0].ValueString();
|
||||||
|
@ -1052,7 +1052,7 @@ def test_attempt_to_create_indexes_on_main_when_sync_replica_is_down():
|
|||||||
# 5/
|
# 5/
|
||||||
expected_data = {
|
expected_data = {
|
||||||
("sync_replica1", "127.0.0.1:10001", "sync", 0, 0, "invalid"),
|
("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)
|
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)
|
assert res_from_main == interactive_mg_runner.MEMGRAPH_INSTANCES["sync_replica2"].query(QUERY_TO_CHECK)
|
||||||
|
@ -18,15 +18,15 @@ from common import Row, cursor, execute_and_fetch_all
|
|||||||
def test_show_index_info(cursor):
|
def test_show_index_info(cursor):
|
||||||
index_info = execute_and_fetch_all(cursor, "SHOW INDEX INFO;")
|
index_info = execute_and_fetch_all(cursor, "SHOW INDEX INFO;")
|
||||||
expected_index_info = {
|
expected_index_info = {
|
||||||
("label", "Anatomy", None),
|
("label", "Anatomy", None, 0),
|
||||||
("label", "Compound", None),
|
("label", "Compound", None, 0),
|
||||||
("label", "Disease", None),
|
("label", "Disease", None, 0),
|
||||||
("label", "Gene", None),
|
("label", "Gene", None, 0),
|
||||||
("label+property", "Compound", "id"),
|
("label+property", "Compound", "id", 0),
|
||||||
("label+property", "Compound", "inchikey"),
|
("label+property", "Compound", "inchikey", 0),
|
||||||
("label+property", "Compound", "mgid"),
|
("label+property", "Compound", "mgid", 0),
|
||||||
("label+property", "Gene", "i5"),
|
("label+property", "Gene", "i5", 0),
|
||||||
("label+property", "Gene", "id"),
|
("label+property", "Gene", "id", 0),
|
||||||
}
|
}
|
||||||
assert set(index_info) == expected_index_info
|
assert set(index_info) == expected_index_info
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user