Skip to content

Commit f0eeb19

Browse files
committed
perf(episodic): add idx_events_linked_id to prevent O(N) batch scans
Add `idx_events_linked_id` index to the `events` table in `EpisodicStore` to prevent O(N) full table scans during batch fetch queries filtering by `linked_id` (e.g., `WHERE linked_id IN (...)`). This provides significant speedups during operations such as `count_links_for_semantic_batch`.
1 parent 61cba58 commit f0eeb19

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/ledgermind/core/stores/episodic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def _init_db(self):
9292
# Performance: Add index for duplicate detection
9393
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_duplicate ON events (source, kind, content, timestamp)")
9494

95+
# Performance: Add index for foreign key-like column to prevent O(N) full table scans
96+
# during batch fetch queries like `WHERE linked_id IN (...)`
97+
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_linked_id ON events (linked_id)")
98+
9599
def _serialize_context(self, context_data: Any) -> str:
96100
if not context_data:
97101
return "{}"

0 commit comments

Comments
 (0)