Improve NameToId mapper on set properties (#1147)
This commit is contained in:
parent
b5413c6f82
commit
93992a275b
@ -2724,7 +2724,8 @@ concept AccessorWithProperties = requires(T value, storage::PropertyId property_
|
|||||||
/// RecordAccessor<Edge>
|
/// RecordAccessor<Edge>
|
||||||
template <AccessorWithProperties TRecordAccessor>
|
template <AccessorWithProperties TRecordAccessor>
|
||||||
void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetProperties::Op op,
|
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>;
|
using PropertiesMap = std::map<storage::PropertyId, storage::PropertyValue>;
|
||||||
std::optional<PropertiesMap> old_values;
|
std::optional<PropertiesMap> old_values;
|
||||||
const bool should_register_change =
|
const bool should_register_change =
|
||||||
@ -2808,9 +2809,15 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr
|
|||||||
}
|
}
|
||||||
case TypedValue::Type::Map: {
|
case TypedValue::Type::Map: {
|
||||||
PropertiesMap new_properties;
|
PropertiesMap new_properties;
|
||||||
for (const auto &[prop_id, prop_value] : rhs.ValueMap()) {
|
for (const auto &[string_key, value] : rhs.ValueMap()) {
|
||||||
auto key = context->db_accessor->NameToProperty(prop_id);
|
storage::PropertyId property_id;
|
||||||
new_properties.emplace(key, prop_value);
|
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);
|
update_props(new_properties);
|
||||||
break;
|
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!");
|
throw QueryRuntimeException("Vertex properties not set due to not having enough permission!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context);
|
SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context, cached_name_id_);
|
||||||
break;
|
break;
|
||||||
case TypedValue::Type::Edge:
|
case TypedValue::Type::Edge:
|
||||||
#ifdef MG_ENTERPRISE
|
#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!");
|
throw QueryRuntimeException("Edge properties not set due to not having enough permission!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
SetPropertiesOnRecord(&lhs.ValueEdge(), rhs, self_.op_, &context);
|
SetPropertiesOnRecord(&lhs.ValueEdge(), rhs, self_.op_, &context, cached_name_id_);
|
||||||
break;
|
break;
|
||||||
case TypedValue::Type::Null:
|
case TypedValue::Type::Null:
|
||||||
// Skip setting properties on Null (can occur in optional match).
|
// Skip setting properties on Null (can occur in optional match).
|
||||||
|
@ -1263,6 +1263,7 @@ class SetProperties : public memgraph::query::plan::LogicalOperator {
|
|||||||
private:
|
private:
|
||||||
const SetProperties &self_;
|
const SetProperties &self_;
|
||||||
const UniqueCursorPtr input_cursor_;
|
const UniqueCursorPtr input_cursor_;
|
||||||
|
std::unordered_map<std::string, storage::PropertyId> cached_name_id_{};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user