Skip to main content
A table’s index option lists the field orders that serve its selections. An index has no name: a selection is matched to an index by the fields it uses.

What an index serves

An index [a, b, c] serves a selection that fixes a leading run of its fields by equality, then ranges over or orders by the next one. A table’s key and each unique field set are also orders, so customers({ email }) and customers.by("email") need no index entry when unique: [["email"]] is declared. A series is also ordered by valid time across its keys. This table holds for a clear table. On a protected table (labelled, erasable or with a lifetime), an index keeps only a token of its fields at the store. It serves a selection that fixes every one of its fields by equality with every verb, and any other selection only as ctx.list(selection.atMost(n)).

A selection no index serves

A selection that no declared order serves is refused, in the editor and at run time, with the index to add:
There is no unindexed scan. Declare the order each question needs.

Ranked fields

Ranked selections are served by the field’s type and, where they filter, by an index. A ranked read whose where fields no index lists before the ranked field is refused with FilterMissing and the entry to add.

Indexes on a protected table

Every order of a protected table keeps a token of its fields, so it answers exact lookups: orders.where({ customer }) on ["customer"]. A partial equality, a range or an order over it is evaluated in the kernel, bounded by .atMost(n); .first(n), ctx.page and ctx.count of such a selection refuse ProtectedShapeUnsupported. To keep an index’s fields clear and in order, so it serves every shape, declare a reviewed store exposure:
See Protected tables for the shapes each index serves, what the store sees, and what each costs.

Wide reads and declared covers (across)

Every index is maintained at the fact’s own partition. When a function reads a member-placed or shared table widely—under a family stem (tenant.all) or over a disjunctive share (label.principals)—declare a cover with across on the index entry (or on the table, t.text, t.vector, total, or changesAcross):
across serves reads. For example, unique: [["email"]] allows two tenant members to use the same email. With a table cover at tenant.all, a stem-cleared by-id selection can return both rows. Use .of(member) for an email point. To reserve a handle across the family, declare unique: [{ fields: ["handle"], scope: tenant.all, release }]. A stem-wide handle point also needs a row cover for its index. Shared claims
  • Pay only for wide paths. A table-level across covers every path, total and .changes; a path-level across covers only that index or ranked field. On a strict update, only changed covered values write to the cover.
  • Narrow without a cover. .of(member) narrows any read to one member’s partition (1 root place, no cover needed).
  • bijection check diagnostics. Every read site and function frame is statically bounded to at most 64 root places:
    • CoverRequired identifies the missing cover or the one Place a keyed point needs. Narrow with .of(member), or use a selection for multiple matches.
    • ReadPlacesUnbounded identifies a selector or source walk beyond the declared bounds. Bound the selector, choose one member, or use a stem your frame already clears and declare its cover.
    • CoverOverlap identifies a reduction whose inputs can include the same fact and whose plan lacks complete identity evidence. Narrow to a single member or select a disjoint plan. Eligible Root counts and ranks can use a bounded walk over distinct facts.

Choosing indexes

  • Put the fields a selection fixes first, and the field it orders or ranges over last.
  • One index serves every selection on a leading run of its fields, so ["customer", "placed"] also serves .where({ customer }). On a protected table that leading run is a partial equality, read only with .atMost(n): declare ["customer"] too when .where({ customer }) takes .first(n), ctx.page or ctx.count.
  • Each index is maintained on every write of the table. Declare the orders your functions read, and no others.