hub perf: an index for the memberships of a human and of an agent (membership.human_id, membership.agent_id)
tsk-va3qmgcv7nmm Open
The bell look (listing.look) and the older listing.stamp find the memberships of a human by membership.human_id. No index leads with that column, so the database scans membership (the SQLite plan shows SCAN membership and SCAN mine). The outside-chat join reads membership.agent_id, and no index leads with that either: SQLite builds an automatic index, PostgreSQL uses a hash join or a seq scan. The existing unique constraints (project_id, human_id, active) and (project_id, agent_id, active) both lead with project_id. Found in the fix round of PR 2406 (tsk-03bdryjrp9bt); decision record hub/context/notifications.md db06e7c2. Proposal: a migration that adds an index on membership(human_id) and one on membership(agent_id), partial where active if the code always filters on active; check the existing migrations for the pattern and the MariaDB and SQLite equivalents. Measure: EXPLAIN in a test, as hub/tests/test_bell_statements.py (test_a_look_is_one_statement_that_searches_the_chat_marks) does. Size: small. Part of the 3,000-client goal (analysis tsk-xgtzhy14nz2b).