{"record":{"id":"79b0222801608abe","repo":"clockworklabs/SpacetimeDB","slug":"only-btree-indexes-are-supported-in-tablecacheimpl","errorCode":null,"errorMessage":"Only btree indexes are supported in TableCacheImpl","messagePattern":"Only btree indexes are supported in TableCacheImpl","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/sdk/table_cache.ts","lineNumber":120,"sourceCode":"    }\n  }\n\n  // TODO: this just scans the whole table; we should build proper index structures\n  #makeReadonlyIndex<\n    I extends TableDefForTableName<\n      RemoteModule,\n      TableName\n    >['resolvedIndexes'][number],\n  >(\n    tableDef: TableDefForTableName<RemoteModule, TableName>,\n    idx: I\n  ): ReadonlyIndex<TableDefForTableName<RemoteModule, TableName>, I> {\n    type TableDef = TableDefForTableName<RemoteModule, TableName>;\n    type Row = Prettify<RowType<TableDef>>;\n\n    // We do not yet support non-btree indexes\n    if (idx.algorithm !== 'btree') {\n      throw new Error('Only btree indexes are supported in TableCacheImpl');\n    }\n\n    const columns = idx.columns;\n\n    // Extract the tuple key for this btree index (column order preserved)\n    const getKey = (row: Row): readonly unknown[] =>\n      columns.map(c => (row as Record<string, unknown>)[c]);\n\n    // The server’s ranged scan fixes all prefix cols to equality and applies\n    // the bound only to the *last* term. We mirror that.\n    //\n    // rangeArg for multi-col index is:\n    //   [...prefixEqualValues, (lastTerm | Range<lastTerm>)]\n    //\n    // If only one element is provided, it’s the last term (scalar or Range).\n    const matchRange = (row: Row, rangeArg: any): boolean => {\n      const key = getKey(row);\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/sdk/table_cache.ts#L102-L138","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Change the module's index to btree (the default index algorithm), republish, and regenerate the bindings","Update the bindings package to a version that supports your index type, if one exists","If the index must stay server-side only, keep it out of the client-visible table definition and regenerate"],"exampleFix":"// module (Rust), before\n#[index(hash, btree_cols)]\n// after\n#[index(btree, btree_cols)] // then republish and regenerate bindings","handlingStrategy":"validation","validationCode":"for (const idx of Object.values(tableDef.resolvedIndexes ?? {})) {\n  if (idx.algorithm !== 'btree') {\n    throw new Error(`index '${idx.name ?? '(unnamed)'}' uses unsupported algorithm '${idx.algorithm}'; use btree`);\n  }\n}","typeGuard":"function isSupportedIndex(idx: { algorithm: string }): boolean {\n  return idx.algorithm === 'btree';\n}","tryCatchPattern":null,"preventionTips":["Keep module indexes on btree while consuming tables from the TS client","Regenerate bindings whenever module index definitions change","Check the bindings changelog before adopting non-btree server-side indexes"],"tags":["index","schema","table-cache","typescript"],"backgroundTag":"unsupported-index-type","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}