Add better method signatures
This commit is contained in:
@@ -624,11 +624,11 @@ class DbAccessor final {
|
||||
return accessor_->DropUniqueConstraint(label, properties);
|
||||
}
|
||||
|
||||
bool UniqueConstraintExists(storage::LabelId label, storage::PropertyId prop) const {
|
||||
bool UniqueConstraintExists(const storage::LabelId &label, const storage::PropertyId &prop) const {
|
||||
return accessor_->UniqueConstraintExists(label, prop);
|
||||
}
|
||||
|
||||
bool IndexedScanExists(storage::LabelId label, storage::PropertyId prop) const {
|
||||
bool IndexedScanExists(const storage::LabelId &label, const storage::PropertyId &prop) const {
|
||||
return LabelPropertyIndexExists(label, prop) || UniqueConstraintExists(label, prop);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -587,8 +587,7 @@ class IndexLookupRewriter final : public HierarchicalLogicalOperatorVisitor {
|
||||
continue;
|
||||
}
|
||||
const auto &property = filter.property_filter->property_;
|
||||
if (!db_->LabelPropertyIndexExists(GetLabel(label), GetProperty(property)) &&
|
||||
!db_->UniqueConstraintExists(GetLabel(label), GetProperty(property))) {
|
||||
if (!db_->IndexedScanExists(GetLabel(label), GetProperty(property))) {
|
||||
continue;
|
||||
}
|
||||
auto is_better_type = [&found](PropertyFilter::Type type) {
|
||||
|
||||
@@ -87,10 +87,14 @@ class VertexCountCache {
|
||||
return db_->GetIndexStats(label, property);
|
||||
}
|
||||
|
||||
bool UniqueConstraintExists(storage::LabelId label, storage::PropertyId prop) const {
|
||||
bool UniqueConstraintExists(const storage::LabelId &label, const storage::PropertyId &prop) const {
|
||||
return db_->UniqueConstraintExists(label, prop);
|
||||
}
|
||||
|
||||
bool IndexedScanExists(const storage::LabelId &label, const storage::PropertyId &prop) const {
|
||||
return db_->IndexedScanExists(label, prop);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::pair<storage::LabelId, storage::PropertyId> LabelPropertyKey;
|
||||
|
||||
|
||||
@@ -59,11 +59,12 @@ class UniqueConstraints {
|
||||
|
||||
virtual std::vector<std::pair<LabelId, std::set<PropertyId>>> ListConstraints() const = 0;
|
||||
|
||||
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property) const = 0;
|
||||
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const = 0;
|
||||
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper) const = 0;
|
||||
virtual uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property) const = 0;
|
||||
virtual uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const PropertyValue &value) const = 0;
|
||||
virtual uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &,
|
||||
const std::optional<utils::Bound<PropertyValue>> &) const = 0;
|
||||
|
||||
virtual void Clear() = 0;
|
||||
|
||||
|
||||
@@ -1957,7 +1957,9 @@ UniqueConstraints::DeletionStatus DiskStorage::DiskAccessor::DropUniqueConstrain
|
||||
return UniqueConstraints::DeletionStatus::SUCCESS;
|
||||
}
|
||||
|
||||
bool DiskStorage::DiskAccessor::UniqueConstraintExists(LabelId label, PropertyId property) const { return false; }
|
||||
bool DiskStorage::DiskAccessor::UniqueConstraintExists(const LabelId &label, const PropertyId &property) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
Transaction DiskStorage::CreateTransaction(IsolationLevel isolation_level, StorageMode storage_mode) {
|
||||
/// We acquire the transaction engine lock here because we access (and
|
||||
|
||||
@@ -169,7 +169,7 @@ class DiskStorage final : public Storage {
|
||||
UniqueConstraints::DeletionStatus DropUniqueConstraint(LabelId label,
|
||||
const std::set<PropertyId> &properties) override;
|
||||
|
||||
bool UniqueConstraintExists(LabelId label, PropertyId property) const override;
|
||||
bool UniqueConstraintExists(const LabelId &label, const PropertyId &property) const override;
|
||||
|
||||
private:
|
||||
/// Flushes vertices and edges to the disk with the commit timestamp.
|
||||
|
||||
@@ -310,12 +310,14 @@ std::vector<std::pair<LabelId, std::set<PropertyId>>> DiskUniqueConstraints::Lis
|
||||
return {constraints_.begin(), constraints_.end()};
|
||||
}
|
||||
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(LabelId label, PropertyId property) const { return 10; };
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(const LabelId &label, const PropertyId &property) const {
|
||||
return 10;
|
||||
};
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const PropertyValue &value) const {
|
||||
return 10;
|
||||
};
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
uint64_t DiskUniqueConstraints::ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper) const {
|
||||
return 10;
|
||||
|
||||
@@ -54,9 +54,10 @@ class DiskUniqueConstraints : public UniqueConstraints {
|
||||
|
||||
std::vector<std::pair<LabelId, std::set<PropertyId>>> ListConstraints() const override;
|
||||
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property) const override;
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const override;
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property) const override;
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const PropertyValue &value) const override;
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper) const override;
|
||||
void Clear() override;
|
||||
|
||||
@@ -1107,7 +1107,7 @@ UniqueConstraints::DeletionStatus InMemoryStorage::InMemoryAccessor::DropUniqueC
|
||||
return UniqueConstraints::DeletionStatus::SUCCESS;
|
||||
}
|
||||
|
||||
bool InMemoryStorage::InMemoryAccessor::UniqueConstraintExists(LabelId label, PropertyId property) const {
|
||||
bool InMemoryStorage::InMemoryAccessor::UniqueConstraintExists(const LabelId &label, const PropertyId &property) const {
|
||||
auto *in_memory = static_cast<InMemoryStorage *>(storage_);
|
||||
auto *mem_unique_constraints =
|
||||
static_cast<InMemoryUniqueConstraints *>(in_memory->constraints_.unique_constraints_.get());
|
||||
|
||||
@@ -203,7 +203,7 @@ class InMemoryStorage final : public Storage {
|
||||
return static_cast<InMemoryStorage *>(storage_)->indices_.label_property_index_->IndexExists(label, property);
|
||||
}
|
||||
|
||||
bool UniqueConstraintExists(LabelId label, PropertyId property) const override;
|
||||
bool UniqueConstraintExists(const LabelId &label, const PropertyId &property) const override;
|
||||
|
||||
IndicesInfo ListAllIndices() const override;
|
||||
|
||||
|
||||
@@ -410,14 +410,14 @@ std::vector<std::pair<LabelId, std::set<PropertyId>>> InMemoryUniqueConstraints:
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(LabelId label, PropertyId property) const {
|
||||
uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(const LabelId &label, const PropertyId &property) const {
|
||||
auto it = constraints_.find({label, {property}});
|
||||
MG_ASSERT(it != constraints_.end(), "Unique constraints for label {} and property {} doesn't exist", label.AsUint(),
|
||||
property.AsUint());
|
||||
return 1;
|
||||
};
|
||||
|
||||
uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const PropertyValue &value) const {
|
||||
auto it = constraints_.find({label, {property}});
|
||||
MG_ASSERT(it != constraints_.end(), "Unique constraints for label {} and property {} doesn't exist", label.AsUint(),
|
||||
@@ -426,7 +426,7 @@ uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(LabelId label, Proper
|
||||
};
|
||||
|
||||
uint64_t InMemoryUniqueConstraints::ApproximateVertexCount(
|
||||
LabelId label, PropertyId property, const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const LabelId &label, const PropertyId &property, const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper) const {
|
||||
auto it = constraints_.find({label, {property}});
|
||||
MG_ASSERT(it != constraints_.end(), "Unique constraints for label {} and property {} doesn't exist", label.AsUint(),
|
||||
|
||||
@@ -131,9 +131,10 @@ class InMemoryUniqueConstraints : public UniqueConstraints {
|
||||
Transaction *transaction_;
|
||||
};
|
||||
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property) const override;
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const override;
|
||||
uint64_t ApproximateVertexCount(LabelId label, PropertyId property,
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property) const override;
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const PropertyValue &value) const override;
|
||||
uint64_t ApproximateVertexCount(const LabelId &label, const PropertyId &property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper) const override;
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ class Storage {
|
||||
virtual UniqueConstraints::DeletionStatus DropUniqueConstraint(LabelId label,
|
||||
const std::set<PropertyId> &properties) = 0;
|
||||
|
||||
virtual bool UniqueConstraintExists(LabelId label, PropertyId property) const = 0;
|
||||
virtual bool UniqueConstraintExists(const LabelId &label, const PropertyId &property) const = 0;
|
||||
|
||||
protected:
|
||||
Storage *storage_;
|
||||
|
||||
@@ -213,7 +213,8 @@ class InteractiveDbAccessor {
|
||||
return label_property_index_.at(key);
|
||||
}
|
||||
|
||||
bool UniqueConstraintExists(memgraph::storage::LabelId label_id, memgraph::storage::PropertyId property_id) {
|
||||
bool UniqueConstraintExists(const memgraph::storage::LabelId &label_id,
|
||||
const memgraph::storage::PropertyId &property_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -226,6 +227,10 @@ class InteractiveDbAccessor {
|
||||
return dba_->GetIndexStats(label, property);
|
||||
}
|
||||
|
||||
bool IndexedScanExists(const memgraph::storage::LabelId &label, const memgraph::storage::PropertyId &prop) const {
|
||||
return dba_->IndexedScanExists(label, prop);
|
||||
}
|
||||
|
||||
// Save the cached vertex counts to a stream.
|
||||
void Save(std::ostream &out) {
|
||||
out << "vertex-count " << vertices_count_ << std::endl;
|
||||
|
||||
@@ -487,7 +487,7 @@ class FakeDbAccessor {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t VerticesCount(memgraph::storage::LabelId label, memgraph::storage::PropertyId property,
|
||||
int64_t VerticesCount(const memgraph::storage::LabelId &label, const memgraph::storage::PropertyId &property,
|
||||
const memgraph::storage::PropertyValue &value) const {
|
||||
return 0;
|
||||
}
|
||||
@@ -496,10 +496,15 @@ class FakeDbAccessor {
|
||||
return label_index_.find(label) != label_index_.end();
|
||||
}
|
||||
|
||||
bool UniqueConstraintExists(memgraph::storage::LabelId label, memgraph::storage::PropertyId property) const {
|
||||
bool UniqueConstraintExists(const memgraph::storage::LabelId &label,
|
||||
const memgraph::storage::PropertyId &property) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IndexedScanExists(const memgraph::storage::LabelId &label, const memgraph::storage::PropertyId &prop) const {
|
||||
return LabelPropertyIndexExists(label, prop) || UniqueConstraintExists(label, prop);
|
||||
}
|
||||
|
||||
bool LabelPropertyIndexExists(memgraph::storage::LabelId label, memgraph::storage::PropertyId property) const {
|
||||
for (auto &index : label_property_index_) {
|
||||
if (std::get<0>(index) == label && std::get<1>(index) == property) {
|
||||
|
||||
Reference in New Issue
Block a user