Skip to content

perf(memory): covering index on messages and load_history_filtered CTE refactor#911

Merged
bug-ops merged 2 commits intomainfrom
feat/864-db-optimization
Feb 25, 2026
Merged

perf(memory): covering index on messages and load_history_filtered CTE refactor#911
bug-ops merged 2 commits intomainfrom
feat/864-db-optimization

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Feb 25, 2026

Closes #895, closes #896, part of #864.

Changes

Migration 015 — adds composite covering index (conversation_id, id) on messages table, replacing the single-column conversation_id index. Eliminates the post-filter sort step for oldest_message_ids and load_history_filtered access patterns.

load_history_filtered — replaces double-sort subquery (ORDER BY id DESC LIMIT + outer ORDER BY id ASC) with a CTE. Query semantics are identical; the CTE makes the intent explicit and gives the SQLite optimizer a cleaner execution plan.

Test plan

  • cargo clippy -p zeph-memory -- -D warnings — clean
  • cargo nextest run -p zeph-memory --lib --features mock — 279 passed, 2 skipped
  • cargo +nightly fmt --check — clean

@github-actions github-actions bot added performance Performance optimization documentation Improvements or additions to documentation memory Persistence and memory rust size/S and removed performance Performance optimization labels Feb 25, 2026
@bug-ops bug-ops force-pushed the feat/864-db-optimization branch from 968e83f to a8324e5 Compare February 25, 2026 21:05
@github-actions github-actions bot added the performance Performance optimization label Feb 25, 2026
…uery

Add composite index (conversation_id, id) on messages table via migration
015, replacing the single-column index for filter+order access patterns
used by oldest_message_ids and load_history_filtered.

Replace the double-sort subquery in load_history_filtered with a CTE,
eliminating the redundant ORDER BY on the derived table.

Closes #895, closes #896, part of #864.
Document covering index (conversation_id, id) and load_history_filtered
CTE refactor in docs/architecture/performance.md and zeph-memory README.
@bug-ops bug-ops force-pushed the feat/864-db-optimization branch from a8324e5 to 952c5ed Compare February 25, 2026 21:13
@bug-ops bug-ops enabled auto-merge (squash) February 25, 2026 21:15
@bug-ops bug-ops merged commit ff587d4 into main Feb 25, 2026
28 checks passed
@bug-ops bug-ops deleted the feat/864-db-optimization branch February 25, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation memory Persistence and memory performance Performance optimization rust size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify load_history_filtered double-sort subquery Audit and add covering index on messages table

1 participant