Skip to content

Propagate a boolean through the graph

Download the complete SQL script, including dataset setup for a fresh database.

Start an alert at person 1 and spread it to everyone reachable along outgoing follows. Save a reached flag on the graph. Run the setup once, then execute the whole script in one session.

The lor_land semiring ANDs across an edge and ORs contributions from incoming neighbours. Combining that result with the previous seen vector preserves everyone reached in earlier rounds.

SELECT warren.vector_from_query('example_social', 'seen',
'SELECT 1::bigint, true', dtype := 'bool');
DO $$
DECLARE reached double precision;
BEGIN
FOR iteration IN 1..10 LOOP
PERFORM warren.spmv('example_social', 'seen', 'spread', 'lor_land',
transpose := true, persist := false);
PERFORM warren.vector_map('example_social', 'seen', 'seen OR spread');
reached := warren.vector_reduce('example_social', 'seen', 'nnz');
RAISE NOTICE 'After % hops: % people reached', iteration, reached;
IF reached = 10000 THEN RETURN; END IF;
END LOOP;
END $$;
SELECT p.id, p.name, v.value <> 0 AS reached
FROM warren.vector_values('example_social', 'seen', NULL::bigint) v
JOIN warren_examples.people p ON p.id = v.node_id
ORDER BY p.id LIMIT 20;
SELECT warren.vector_reduce('example_social', 'seen', 'nnz') AS people_reached,
(SELECT count(*) FROM warren.bfs('example_social', ARRAY[1::bigint], 10)) AS bfs_crosscheck;

In Messages, the reached population grows from 6 after one hop to 8,091 after six, then all 10,000 after nine. The final result agrees with BFS.

The result is the persisted vector seen, attached to the current graph version. vector_values exposes its boolean values as numbers: 1 for true and 0 for false. The query converts them to SQL booleans with value <> 0 and joins their original ids back to your people.

Replace the seed query with your application’s flagged rows, returning (id, true) for each. The default fill is false. Multiple starts propagate in the same computation. This pattern models reachability or potential exposure; a true flag alone does not establish real-world impact.

The ten-round limit and early-exit count of 10,000 belong to this dataset. Adjust them for your graph. For shortest distances and an explanatory route from multiple seeds, continue with taint analysis.