Skip to content

feat: add missing DB indexes for structured queries #657

Closed

Description

@ajianaz

Summary

The memories table has 17K+ rows but several frequently-queried columns lack indexes:

Column Has Index? Impact
memory_type No WHERE memory_type = decision = full scan
importance No WHERE importance > 0.5 = full scan
pinned No WHERE pinned = 1 = full scan

Proposed Indexes

CREATE INDEX idx_memories_type ON memories(memory_type);
CREATE INDEX idx_memories_importance ON memories(importance);
CREATE INDEX idx_memories_pinned ON memories(pinned);

Acceptance Criteria

Functional

  • Add migration to create 3 new indexes: idx_memories_type, idx_memories_importance, idx_memories_pinned
  • EXPLAIN QUERY PLAN uses index for WHERE memory_type = ?

Verification (CMO can run without reading code)

  • sqlite3 uteke.db ".indexes memories" → lists all 3 new indexes
  • EXPLAIN QUERY PLAN SELECT * FROM memories WHERE memory_type = 'decision' → output contains idx_memories_type
  • EXPLAIN QUERY PLAN SELECT * FROM memories WHERE importance > 0.5 → contains idx_memories_importance
  • EXPLAIN QUERY PLAN SELECT * FROM memories WHERE pinned = 1 → contains idx_memories_pinned
  • Insert 100 new memories → write time not noticeably slower (< 2ms per insert)
  • Existing DB with data: migration runs without error, no data loss

Tests

  • Integration: run migration on existing 17K+ row DB → verify all indexes created
  • Benchmark: 1000 inserts pre-index vs post-index → < 10% regression

Priority

Medium — performance optimization for structured query support.

Activity

  1. added
    enhancement
    scope:db
    on Jul 14, 2026
  2. ajianaz commented on Jul 14, 2026

    @ajianaz
    CollaboratorAuthor

    Depends on

    This issue should be resolved before #658 (POST /query) for optimal query performance.

  3. ajianaz commented on Jul 14, 2026

    @ajianaz
    CollaboratorAuthor

    Duplicate of #675 (same scope, newer issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:mediumscope:db

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions