Add text index creation and deletion
This commit is contained in:
parent
0357d19238
commit
a5d849b5e9
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -628,6 +628,14 @@ class DbAccessor final {
|
|||||||
return accessor_->DropIndex(label, property);
|
return accessor_->DropIndex(label, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils::BasicResult<storage::StorageIndexDefinitionError, void> CreateTextIndex(storage::LabelId label) {
|
||||||
|
return accessor_->CreateTextIndex(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
utils::BasicResult<storage::StorageIndexDefinitionError, void> DropTextIndex(storage::LabelId label) {
|
||||||
|
return accessor_->DropTextIndex(label);
|
||||||
|
}
|
||||||
|
|
||||||
utils::BasicResult<storage::StorageExistenceConstraintDefinitionError, void> CreateExistenceConstraint(
|
utils::BasicResult<storage::StorageExistenceConstraintDefinitionError, void> CreateExistenceConstraint(
|
||||||
storage::LabelId label, storage::PropertyId property) {
|
storage::LabelId label, storage::PropertyId property) {
|
||||||
return accessor_->CreateExistenceConstraint(label, property);
|
return accessor_->CreateExistenceConstraint(label, property);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -55,6 +55,7 @@ void Indices::UpdateOnSetProperty(PropertyId property, const PropertyValue &valu
|
|||||||
|
|
||||||
Indices::Indices(const Config &config, StorageMode storage_mode) {
|
Indices::Indices(const Config &config, StorageMode storage_mode) {
|
||||||
std::invoke([this, config, storage_mode]() {
|
std::invoke([this, config, storage_mode]() {
|
||||||
|
text_index_ = std::make_unique<TextIndex>();
|
||||||
if (storage_mode == StorageMode::IN_MEMORY_TRANSACTIONAL || storage_mode == StorageMode::IN_MEMORY_ANALYTICAL) {
|
if (storage_mode == StorageMode::IN_MEMORY_TRANSACTIONAL || storage_mode == StorageMode::IN_MEMORY_ANALYTICAL) {
|
||||||
label_index_ = std::make_unique<InMemoryLabelIndex>();
|
label_index_ = std::make_unique<InMemoryLabelIndex>();
|
||||||
label_property_index_ = std::make_unique<InMemoryLabelPropertyIndex>();
|
label_property_index_ = std::make_unique<InMemoryLabelPropertyIndex>();
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
// by the Apache License, Version 2.0, included in the file
|
// by the Apache License, Version 2.0, included in the file
|
||||||
// licenses/APL.txt.
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
#include "utils/memcxx.hpp"
|
||||||
|
|
||||||
namespace memgraph::storage {
|
namespace memgraph::storage {
|
||||||
|
|
||||||
class TextIndex {
|
class TextIndex {
|
||||||
@ -20,20 +22,42 @@ class TextIndex {
|
|||||||
TextIndex &operator=(const TextIndex &) = delete;
|
TextIndex &operator=(const TextIndex &) = delete;
|
||||||
TextIndex &operator=(TextIndex &&) = delete;
|
TextIndex &operator=(TextIndex &&) = delete;
|
||||||
|
|
||||||
virtual ~TextIndex() = default;
|
~TextIndex() = default;
|
||||||
|
|
||||||
virtual void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, const Transaction &tx) = 0;
|
void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, const Transaction &tx) {}
|
||||||
|
|
||||||
// Not used for in-memory
|
void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx) {}
|
||||||
virtual void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx) = 0;
|
|
||||||
|
|
||||||
virtual bool DropIndex(LabelId label) = 0;
|
/// @throw std::bad_alloc
|
||||||
|
bool CreateIndex(LabelId label, const std::optional<durability::ParallelizedSchemaCreationInfo> ¶llel_exec_info) {
|
||||||
|
auto index_config = memcxx_mock::text_search::IndexConfig{.mappings = "TODO antepusic"};
|
||||||
|
auto new_index = memcxx_mock::text_search::Mock::create_index(label.ToString(), index_config);
|
||||||
|
index_[label] = new_index;
|
||||||
|
return true;
|
||||||
|
|
||||||
virtual bool IndexExists(LabelId label) const = 0;
|
// TODO add documents to index
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::vector<LabelId> ListIndices() const = 0;
|
bool DropIndex(LabelId label) {
|
||||||
|
memcxx_mock::text_search::Mock::drop_index(label.ToString());
|
||||||
|
index_.erase(label);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual uint64_t ApproximateVertexCount(LabelId label) const = 0;
|
bool IndexExists(LabelId label) { return index_.contains(label); }
|
||||||
|
|
||||||
|
std::vector<LabelId> ListIndices() {
|
||||||
|
std::vector<LabelId> ret;
|
||||||
|
ret.reserve(index_.size());
|
||||||
|
for (const auto &item : index_) {
|
||||||
|
ret.push_back(item.first);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ApproximateVertexCount(LabelId label) { return 10; }
|
||||||
|
|
||||||
|
std::map<LabelId, memcxx_mock::text_search::IndexContext> index_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace memgraph::storage
|
} // namespace memgraph::storage
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -255,6 +255,17 @@ class Storage {
|
|||||||
|
|
||||||
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(LabelId label, PropertyId property) = 0;
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(LabelId label, PropertyId property) = 0;
|
||||||
|
|
||||||
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateTextIndex(LabelId label) {
|
||||||
|
// TODO: pass vertices to CreateIndex
|
||||||
|
storage_->indices_.text_index_->CreateIndex(label, std::nullopt);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropTextIndex(LabelId label) {
|
||||||
|
storage_->indices_.text_index_->DropIndex(label);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
virtual utils::BasicResult<StorageExistenceConstraintDefinitionError, void> CreateExistenceConstraint(
|
virtual utils::BasicResult<StorageExistenceConstraintDefinitionError, void> CreateExistenceConstraint(
|
||||||
LabelId label, PropertyId property) = 0;
|
LabelId label, PropertyId property) = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user