Skip to content

Commit 38620a2

Browse files
perf(database): index entity_relations.relation_id for inbound graph traversal (#194)
The recursive graph query resolves inbound edges by joining relation_target_entities to entity_relations on relation_id. entity_relations only had indexes leading with entity_id, so that join was a sequential scan per frontier node. The query runs on every entity list page. Measured on 15k entities / 22k edges (local Docker, 2 CPU): - list 20 services: p50 263-378 ms -> 87 ms - property filter: p50 460 ms -> 100 ms - graph depth 3 bidirectional: p50 64 ms -> 28 ms Co-authored-by: Andrés Brand <andres.brand.partner@decathlon.com>
1 parent 6bbce97 commit 38620a2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Inbound graph traversal joins entity_relations on relation_id:
2+
-- relation_target_entities (by target_entity_uuid) -> entity_relations (by relation_id) -> entity
3+
-- The only indexes on entity_relations start with entity_id (primary key and idx_entity_relations_entity_id),
4+
-- so that join fell back to a sequential scan for every node of the traversal frontier.
5+
-- The recursive graph query runs on every entity list page, so the scan was paid on each list call.
6+
CREATE INDEX IF NOT EXISTS idx_entity_relations_relation_id ON entity_relations (relation_id);

0 commit comments

Comments
 (0)