jrgemignani commented on code in PR #2376:
URL: https://github.com/apache/age/pull/2376#discussion_r3088396598
##########
src/backend/utils/adt/age_vle.c:
##########
@@ -364,54 +364,70 @@ static bool is_an_edge_match(VLE_local_context *vlelctx,
edge_entry *ee)
return false;
}
- /* get our edge's properties */
- edge_property = DATUM_GET_AGTYPE_P(get_edge_entry_properties(ee));
- /* get the containers */
- agtc_edge_property_constraint = &vlelctx->edge_property_constraint->root;
- agtc_edge_property = &edge_property->root;
- /* get the number of properties in the edge to be matched */
- num_edge_properties = AGTYPE_CONTAINER_SIZE(agtc_edge_property);
-
/*
- * Check to see if the edge_properties object has AT LEAST as many pairs
- * to compare as the edge_property_constraint object has pairs. If not, it
- * can't possibly match.
+ * Fast path: if the label matched (or wasn't constrained) and there
+ * are no property constraints, the edge is a match. This avoids
+ * accessing edge properties entirely for label-only VLE patterns
+ * like [:KNOWS*1..3] which are the common case.
*/
- if (num_edge_property_constraints > num_edge_properties)
+ if (num_edge_property_constraints == 0)
{
- return false;
+ return true;
}
/*
- * If the number of constraints are the same as the number of properties,
- * then the datums would be the same if they match.
+ * Fetch edge properties once and cache locally. With thin entries,
+ * get_edge_entry_properties() does a heap_fetch, so we avoid calling
+ * it multiple times for the same edge.
*/
- if (num_edge_property_constraints == num_edge_properties)
{
- Datum edge_props = get_edge_entry_properties(ee);
- uint32 edge_props_hash = datum_image_hash(edge_props, false, -1);
+ Datum edge_props_datum = get_edge_entry_properties(ee);
+
+ edge_property = DATUM_GET_AGTYPE_P(edge_props_datum);
+ agtc_edge_property_constraint =
&vlelctx->edge_property_constraint->root;
+ agtc_edge_property = &edge_property->root;
+ num_edge_properties = AGTYPE_CONTAINER_SIZE(agtc_edge_property);
+
+ /*
+ * Check to see if the edge_properties object has AT LEAST as many
+ * pairs to compare as the edge_property_constraint object has pairs.
+ * If not, it can't possibly match.
+ */
+ if (num_edge_property_constraints > num_edge_properties)
+ {
+ return false;
+ }
- /* check the hash first */
- if (vlelctx->edge_property_constraint_hash == edge_props_hash)
+ /*
+ * If the number of constraints are the same as the number of
+ * properties, then the datums would be the same if they match.
+ */
+ if (num_edge_property_constraints == num_edge_properties)
{
- /* if the hashes match, check the datum images */
- if (datum_image_eq(vlelctx->edge_property_constraint_datum,
- edge_props, false, -1))
+ uint32 edge_props_hash = datum_image_hash(edge_props_datum,
+ false, -1);
+ /* check the hash first */
+ if (vlelctx->edge_property_constraint_hash == edge_props_hash)
{
- return true;
+ /* if the hashes match, check the datum images */
+ if (datum_image_eq(vlelctx->edge_property_constraint_datum,
+ edge_props_datum, false, -1))
+ {
+ return true;
+ }
}
- }
- /* if we got here they aren't the same */
- return false;
- }
+ /* if we got here they aren't the same */
+ return false;
+ }
- /* get the iterators */
- constraint_it = agtype_iterator_init(agtc_edge_property_constraint);
- property_it = agtype_iterator_init(agtc_edge_property);
+ /* get the iterators */
+ constraint_it = agtype_iterator_init(agtc_edge_property_constraint);
+ property_it = agtype_iterator_init(agtc_edge_property);
- /* return the value of deep contains */
- return agtype_deep_contains(&property_it, &constraint_it, false);
+ /* return the value of deep contains */
+ return agtype_deep_contains(&property_it, &constraint_it, false);
Review Comment:
Per Opus, not really an issue. Additionally, a potential future PR will be
addressing this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]