jrgemignani commented on code in PR #2376:
URL: https://github.com/apache/age/pull/2376#discussion_r3112944131


##########
age--1.7.0--y.y.y.sql:
##########
@@ -408,3 +408,13 @@ $function$;
 
 COMMENT ON FUNCTION ag_catalog.age_pg_upgrade_status() IS
 'Returns the current pg_upgrade readiness status of the AGE installation.';
+
+--
+-- VLE cache invalidation trigger function
+-- Installed on graph label tables to catch SQL-level mutations
+-- and increment the per-graph version counter for VLE cache invalidation.
+--
+CREATE FUNCTION ag_catalog.age_invalidate_graph_cache()
+    RETURNS trigger
+    LANGUAGE c
+AS 'MODULE_PATHNAME';

Review Comment:
   Added



##########
regress/sql/age_global_graph.sql:
##########
@@ -146,6 +146,103 @@ RESET client_min_messages;
 SELECT * FROM drop_graph('ag_graph_1', true);
 SELECT * FROM drop_graph('ag_graph_2', true);
 SELECT * FROM drop_graph('ag_graph_3', true);
+
+-----------------------------------------------------------------------------------------------------------------------------
+--
+-- VLE cache invalidation tests
+--
+-- These tests verify that the graph version counter properly invalidates
+-- the VLE hash table cache when the graph is mutated, and that thin
+-- entry lazy property fetch returns correct data.
+--
+
+-- Setup: create a graph with a chain a->b->c->d
+SELECT * FROM create_graph('vle_cache_test');
+
+SELECT * FROM cypher('vle_cache_test', $$
+  CREATE (a:Node {name: 'a'})-[:Edge]->(b:Node {name: 'b'})-[:Edge]->(c:Node 
{name: 'c'})-[:Edge]->(d:Node {name: 'd'})
+$$) AS (v agtype);
+
+-- VLE query: find all paths from a's neighbors (should find b, b->c, b->c->d)
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (a:Node {name: 'a'})-[:Edge*1..3]->(n:Node)
+  RETURN n.name
+  ORDER BY n.name
+$$) AS (name agtype);
+
+-- Now add a new node e connected to d. This should invalidate the cache.
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (d:Node {name: 'd'})
+  CREATE (d)-[:Edge]->(:Node {name: 'e'})
+$$) AS (v agtype);
+
+-- VLE query again: should now also find e via a->b->c->d->e (4 hops won't 
reach,
+-- but d->e is 1 hop from d, and a->b->c->d->e would be 4 hops from a).
+-- Increase range to *1..4 to include e
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (a:Node {name: 'a'})-[:Edge*1..4]->(n:Node)
+  RETURN n.name
+  ORDER BY n.name
+$$) AS (name agtype);
+
+-- Test cache invalidation on DELETE: remove node c and its edges
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (c:Node {name: 'c'})
+  DETACH DELETE c
+$$) AS (v agtype);
+
+-- VLE query: should only find b now (c is gone, so b->c path is broken)
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (a:Node {name: 'a'})-[:Edge*1..4]->(n:Node)
+  RETURN n.name
+  ORDER BY n.name
+$$) AS (name agtype);
+
+-- Test cache invalidation on SET: change b's name property
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (b:Node {name: 'b'})
+  SET b.name = 'b_modified'
+  RETURN b.name
+$$) AS (name agtype);
+
+-- VLE query: verify the updated property is returned via lazy fetch
+SELECT * FROM cypher('vle_cache_test', $$
+  MATCH (a:Node {name: 'a'})-[:Edge*1..4]->(n:Node)
+  RETURN n.name
+  ORDER BY n.name
+$$) AS (name agtype);
+
+-- Test VLE with edge properties (exercises thin entry edge property fetch)
+SELECT * FROM drop_graph('vle_cache_test', true);
+SELECT * FROM create_graph('vle_cache_test2');
+
+SELECT * FROM cypher('vle_cache_test2', $$
+  CREATE (a:N {name: 'a'})-[:E {weight: 1}]->(b:N {name: 'b'})-[:E {weight: 
2}]->(c:N {name: 'c'})
+$$) AS (v agtype);
+
+-- VLE path output to verify edge properties are fetched correctly via
+-- thin entry lazy fetch. Returning the full path forces build_path()
+-- to call get_edge_entry_properties() for each edge in the result.
+-- The output must contain the correct weight values (1 and 2).
+SELECT * FROM cypher('vle_cache_test2', $$
+  MATCH p=(a:N {name: 'a'})-[:E *1..2]->(n:N)
+  RETURN p
+  ORDER BY n.name
+$$) AS (p agtype);
+
+-- VLE edge properties via UNWIND + relationships() to individually verify
+-- each edge's properties are correctly fetched from the heap via TID.
+SELECT * FROM cypher('vle_cache_test2', $$
+  MATCH p=(a:N {name: 'a'})-[:E *1..2]->(n:N)
+  WITH p, n
+  UNWIND relationships(p) AS e
+  RETURN n.name, e.weight
+  ORDER BY n.name, e.weight
+$$) AS (name agtype, weight agtype);
+
+-- Cleanup
+SELECT * FROM drop_graph('vle_cache_test2', true);
+
 
-----------------------------------------------------------------------------------------------------------------------------

Review Comment:
   added



-- 
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]

Reply via email to