Optimization: don't go to disk if no prop

This commit is contained in:
Andreja Tonev 2024-03-12 17:08:46 +01:00
parent 66376fea0e
commit 796fe44c99

View File

@ -27,7 +27,7 @@
namespace memgraph::storage { namespace memgraph::storage {
struct Vertex { struct Vertex {
Vertex(Gid gid, Delta *delta) : gid(gid), deleted(false), delta(delta) { Vertex(Gid gid, Delta *delta) : gid(gid), deleted(false), has_prop(false), delta(delta) {
MG_ASSERT(delta == nullptr || delta->action == Delta::Action::DELETE_OBJECT || MG_ASSERT(delta == nullptr || delta->action == Delta::Action::DELETE_OBJECT ||
delta->action == Delta::Action::DELETE_DESERIALIZED_OBJECT, delta->action == Delta::Action::DELETE_DESERIALIZED_OBJECT,
"Vertex must be created with an initial DELETE_OBJECT delta!"); "Vertex must be created with an initial DELETE_OBJECT delta!");
@ -55,6 +55,7 @@ struct Vertex {
bool deleted; bool deleted;
// uint8_t PAD; // uint8_t PAD;
// uint16_t PAD; // uint16_t PAD;
bool has_prop;
class HotFixMove { class HotFixMove {
public: public:
@ -80,6 +81,7 @@ struct Vertex {
PropertyValue GetProperty(PropertyId property) const { PropertyValue GetProperty(PropertyId property) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
const auto prop = PDS::get()->Get(gid, property); const auto prop = PDS::get()->Get(gid, property);
if (prop) return *prop; if (prop) return *prop;
return {}; return {};
@ -87,21 +89,25 @@ struct Vertex {
bool SetProperty(PropertyId property, const PropertyValue &value) { bool SetProperty(PropertyId property, const PropertyValue &value) {
// if (deleted) return {}; // if (deleted) return {};
has_prop = true;
return PDS::get()->Set(gid, property, value); return PDS::get()->Set(gid, property, value);
} }
bool HasProperty(PropertyId property) const { bool HasProperty(PropertyId property) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
return PDS::get()->Has(gid, property); return PDS::get()->Has(gid, property);
} }
bool HasAllProperties(const std::set<PropertyId> &properties) const { bool HasAllProperties(const std::set<PropertyId> &properties) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
return std::all_of(properties.begin(), properties.end(), [this](const auto &prop) { return HasProperty(prop); }); return std::all_of(properties.begin(), properties.end(), [this](const auto &prop) { return HasProperty(prop); });
} }
bool IsPropertyEqual(PropertyId property, const PropertyValue &value) const { bool IsPropertyEqual(PropertyId property, const PropertyValue &value) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return value.IsNull();
const auto val = GetProperty(property); const auto val = GetProperty(property);
return val == value; return val == value;
} }
@ -117,17 +123,20 @@ struct Vertex {
if (!pds->Set(gid, property, value)) { if (!pds->Set(gid, property, value)) {
return false; return false;
} }
has_prop = true;
} }
return true; return true;
} }
void ClearProperties() { void ClearProperties() {
if (!has_prop) return;
auto *pds = PDS::get(); auto *pds = PDS::get();
pds->Clear(gid); pds->Clear(gid);
} }
std::map<PropertyId, PropertyValue> Properties() { std::map<PropertyId, PropertyValue> Properties() {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
return PDS::get()->Get(gid); return PDS::get()->Get(gid);
} }
@ -159,11 +168,13 @@ struct Vertex {
uint64_t PropertySize(PropertyId property) const { uint64_t PropertySize(PropertyId property) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
return PDS::get()->GetSize(gid, property); return PDS::get()->GetSize(gid, property);
} }
std::optional<std::vector<PropertyValue>> ExtractPropertyValues(const std::set<PropertyId> &properties) const { std::optional<std::vector<PropertyValue>> ExtractPropertyValues(const std::set<PropertyId> &properties) const {
// if (deleted) return {}; // if (deleted) return {};
if (!has_prop) return {};
std::vector<PropertyValue> value_array; std::vector<PropertyValue> value_array;
value_array.reserve(properties.size()); value_array.reserve(properties.size());
for (const auto &prop : properties) { for (const auto &prop : properties) {