Skip to content

perf(storage): add index on raw_conversations.acquired_at #727

Closed

Description

@Sinity

Problem

raw_conversations has no index on acquired_at, but queries like iter_raw_conversations sort by ORDER BY acquired_at DESC and paginate with LIMIT ? OFFSET ?. For large archives (millions of raw records), this requires a full sort scan on every query.

Additionally, get_known_source_mtimes does SELECT source_path, file_mtime FROM raw_conversations WHERE file_mtime IS NOT NULL with no pagination — loads the entire table into memory.

And EFFECTIVE_RAW_PROVIDER_SQL uses COALESCE(payload_provider, provider_name) which cannot use the simple provider indexes — requires a full scan.

Acceptance criteria

  • Add index on raw_conversations(acquired_at) for sort-enabled queries.
  • Add functional index or generated column for COALESCE(payload_provider, provider_name).
  • Measure query time improvement on the live 68GB archive.

Found by

2026-05-03 performance hot-path analysis (wave 4 subagent analysis). Previously noted in project memory as a known issue — keyset pagination was already used for verify_raw_corpus to work around this.

Activity

  1. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Scope absorbed into #719 (slow ingest investigation). The missing acquired_at index is a performance concern.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions