Improve NameToId mapper on set properties (#1147)

This commit is contained in:
Antonio Filipovic 2023-09-06 00:12:27 +02:00 committed by GitHub
parent b5413c6f82
commit 93992a275b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -2724,7 +2724,8 @@ concept AccessorWithProperties = requires(T value, storage::PropertyId property_
/// RecordAccessor<Edge>
template <AccessorWithProperties TRecordAccessor>
void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetProperties::Op op,
ExecutionContext *context) {
ExecutionContext *context,
std::unordered_map<std::string, storage::PropertyId> &cached_name_id) {
using PropertiesMap = std::map<storage::PropertyId, storage::PropertyValue>;
std::optional<PropertiesMap> old_values;
const bool should_register_change =
@ -2808,9 +2809,15 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr
}
case TypedValue::Type::Map: {
PropertiesMap new_properties;
for (const auto &[prop_id, prop_value] : rhs.ValueMap()) {
auto key = context->db_accessor->NameToProperty(prop_id);
new_properties.emplace(key, prop_value);
for (const auto &[string_key, value] : rhs.ValueMap()) {
storage::PropertyId property_id;
if (auto it = cached_name_id.find(std::string(string_key)); it != cached_name_id.end()) [[likely]] {
property_id = it->second;
} else {
property_id = context->db_accessor->NameToProperty(string_key);
cached_name_id.emplace(string_key, property_id);
}
new_properties.emplace(property_id, value);
}
update_props(new_properties);
break;
@ -2853,7 +2860,7 @@ bool SetProperties::SetPropertiesCursor::Pull(Frame &frame, ExecutionContext &co
throw QueryRuntimeException("Vertex properties not set due to not having enough permission!");
}
#endif
SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context);
SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context, cached_name_id_);
break;
case TypedValue::Type::Edge:
#ifdef MG_ENTERPRISE
@ -2862,7 +2869,7 @@ bool SetProperties::SetPropertiesCursor::Pull(Frame &frame, ExecutionContext &co
throw QueryRuntimeException("Edge properties not set due to not having enough permission!");
}
#endif
SetPropertiesOnRecord(&lhs.ValueEdge(), rhs, self_.op_, &context);
SetPropertiesOnRecord(&lhs.ValueEdge(), rhs, self_.op_, &context, cached_name_id_);
break;
case TypedValue::Type::Null:
// Skip setting properties on Null (can occur in optional match).

View File

@ -1263,6 +1263,7 @@ class SetProperties : public memgraph::query::plan::LogicalOperator {
private:
const SetProperties &self_;
const UniqueCursorPtr input_cursor_;
std::unordered_map<std::string, storage::PropertyId> cached_name_id_{};
};
};