B-tree Index

B-tree indexes power metadata lookups and secondary indexes on document collections. Backed by redb's ACID B-Tree storage.

Creating Indexes

-- Secondary index on a document collection
CREATE INDEX ON users FIELDS email;

-- Compound index
CREATE INDEX ON orders FIELDS customer_id, status;

-- Unique index
CREATE UNIQUE INDEX ON users FIELDS email;

When Used

  • Point lookups on document collections (WHERE email = 'alice@example.com')
  • Range scans (WHERE age > 25 AND age < 40)
  • Sorting (ORDER BY created_at DESC)
  • Constraint enforcement (UNIQUE)

Graph Edge Storage

Graph edges are persisted in redb B-Trees with forward and reverse indexes, keyed by (tenant_id: u32, "src\x00label\x00dst") tuples. Tenant isolation is a first-class key component, not a lexical prefix; the composite portion enables prefix scans for outbound traversal within a tenant.

View page sourceLast updated on Apr 24, 2026 by Farhan Syah