Skip to content

fix: single-column BTree index Range filter/delete#4737

Open
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:fix/single-col-btree-range
Open

fix: single-column BTree index Range filter/delete#4737
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:fix/single-col-btree-range

Conversation

@DexterKoelson
Copy link
Copy Markdown

@DexterKoelson DexterKoelson commented Mar 31, 2026

Fixes #4736

Description of Changes

Single-column BTree indexes accepted Range<T> in their type signatures (via IndexScanRangeBounds), but the runtime filter() and delete() implementations always serialized the argument as a point value using datastore_index_scan_point_bsatn. Passing a Range object caused SyntaxError: Cannot convert [object Object] to a BigInt because the Range object was fed directly to the column serializer.

The fix adds Range detection to the single-column BTree index code path in runtime.ts. When a Range is passed, it serializes the bounds and calls datastore_index_scan_range_bsatn / datastore_delete_by_index_scan_range_bsatn instead. Point queries continue to use the existing fast path. The multi-column index code already handled Range correctly — this brings single-column indexes to parity.

API and ABI breaking changes

None. This is a pure bugfix. Existing queries are unaffected, and Range queries that previously crashed now work as the types imply.

Expected complexity level and risk

Low. The change is localized to one code path in runtime.ts and mirrors the existing multi-column range serialization logic. All 170 existing tests pass.

Testing

  • All 170 vitest tests pass
  • Manually confirmed the fix resolves the reported SyntaxError in a production SpacetimeDB TypeScript module using ctx.db.players.fooId.filter(new Range(...)) on a single-column BTree index

The type system allowed Range<T> for single-column BTree index
.filter() and .delete(), but the runtime always serialized the
argument as a point value via datastore_index_scan_point_bsatn.
Passing a Range object caused:
  SyntaxError: Cannot convert [object Object] to a BigInt

Now detects Range instances and uses datastore_index_scan_range_bsatn
for both filter and delete on single-column BTree indexes.
@Centril Centril requested a review from coolreader18 April 1, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-column BTree index crashes when filtering with Range

1 participant