clockworklabs/SpacetimeDB · error · Error

Only btree indexes are supported in TableCacheImpl

Error message

Only btree indexes are supported in TableCacheImpl

What it means

TableCacheImpl mirrors server-side indexes for client-side reads, and only the btree algorithm is implemented. When a table definition carries an index with any other algorithm (e.g. a hash index declared in the module), building the client-side index mirror throws 'Only btree indexes are supported in TableCacheImpl'.

Solutions

  1. Change the module's index to btree (the default index algorithm), republish, and regenerate the bindings
  2. Update the bindings package to a version that supports your index type, if one exists
  3. If the index must stay server-side only, keep it out of the client-visible table definition and regenerate

Example fix

// module (Rust), before
#[index(hash, btree_cols)]
// after
#[index(btree, btree_cols)] // then republish and regenerate bindings
Defensive patterns

Strategy: validation

Validate before calling

for (const idx of Object.values(tableDef.resolvedIndexes ?? {})) {
  if (idx.algorithm !== 'btree') {
    throw new Error(`index '${idx.name ?? '(unnamed)'}' uses unsupported algorithm '${idx.algorithm}'; use btree`);
  }
}

Type guard

function isSupportedIndex(idx: { algorithm: string }): boolean {
  return idx.algorithm === 'btree';
}

Prevention

When it happens

Trigger: Publishing a module with a non-btree index (e.g. #[index(hash, ...)] in Rust) and then connecting/registering that table with the TypeScript bindings, which attempt to construct the index accessor from the generated table definition.

Common situations: Adding hash indexes server-side for storage reasons while the TS client bindings do not support them yet; stale generated bindings after switching an index algorithm; new module features outpacing the released bindings package.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/79b0222801608abe. Report an issue: GitHub.

Appendix: source

Thrown at crates/bindings-typescript/src/sdk/table_cache.ts:120

    }
  }

  // TODO: this just scans the whole table; we should build proper index structures
  #makeReadonlyIndex<
    I extends TableDefForTableName<
      RemoteModule,
      TableName
    >['resolvedIndexes'][number],
  >(
    tableDef: TableDefForTableName<RemoteModule, TableName>,
    idx: I
  ): ReadonlyIndex<TableDefForTableName<RemoteModule, TableName>, I> {
    type TableDef = TableDefForTableName<RemoteModule, TableName>;
    type Row = Prettify<RowType<TableDef>>;

    // We do not yet support non-btree indexes
    if (idx.algorithm !== 'btree') {
      throw new Error('Only btree indexes are supported in TableCacheImpl');
    }

    const columns = idx.columns;

    // Extract the tuple key for this btree index (column order preserved)
    const getKey = (row: Row): readonly unknown[] =>
      columns.map(c => (row as Record<string, unknown>)[c]);

    // The server’s ranged scan fixes all prefix cols to equality and applies
    // the bound only to the *last* term. We mirror that.
    //
    // rangeArg for multi-col index is:
    //   [...prefixEqualValues, (lastTerm | Range<lastTerm>)]
    //
    // If only one element is provided, it’s the last term (scalar or Range).
    const matchRange = (row: Row, rangeArg: any): boolean => {
      const key = getKey(row);

View on GitHub (pinned to 6dee26c6ef)