Skip to content

[P3][lens] Secondary indexes for document and relational queries #52

Description

@cevheri

Summary

Roadmap item (README "Next"; DESIGN.md section 6 lists secondary indexes as an honest v1 deferral for both the document and relational lenses). Today every find()/where() is an O(n) collection scan by design; secondary indexes are the single largest lever on the query surface.

Why

  • The performance envelope (README) documents the O(n) scan honestly; indexes move the practical ceiling for read-heavy workloads.
  • The kernel already provides everything an index needs: ordered byte keys, composite-key ranges, and atomic multi-key transactions — an index is a lens-level convention (<reserved>index:<ns>:<field>:<value>:<id> style keys), not a kernel feature.

Scope sketch (exploratory — each choice must earn its place against the comprehension budget)

  • Index maintenance inside the same transact() as the row write (atomic by construction).
  • A catalog entry per index so cold-opening tools (Studio) can render them; reserved-namespace placement.
  • Query planning stays trivial: equality-predicate lookup via index when one exists, scan otherwise — no planner.
  • Open questions: value encoding for ordered numeric keys, index backfill for existing data, multi-field indexes (defer?).

Constraints

  • Kernel (src/core.ts) unchanged — this is lens-level, open-edge work.
  • No silent behavior changes to unindexed queries.
  • Changeset (minor) when it ships; bun run gate green with 100% coverage.

Activity

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions