You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Add supported index key types to Index docs page (#4592)
Lists which types can and cannot be used as index keys for both
B-tree and direct indexes. Includes a workaround tip for
floating-point data (scaled integers) and links to the open
issue for Timestamp/TimeDuration support (#2650).
| Enums | No-payload (C-style) enums annotated with `#[derive(SpacetimeType)]`|
45
+
46
+
The following types are **not** supported as index keys:
47
+
48
+
| Type | Reason |
49
+
|------|--------|
50
+
|`f32`, `f64`| Floating-point values do not have a total ordering (`NaN` is not comparable) |
51
+
|`ScheduleAt`, `TimeDuration`, `Timestamp`| Not yet supported ([#2650](https://github.com/clockworklabs/SpacetimeDB/issues/2650)) |
52
+
|`Vec<T>`, arrays | Variable-length collections are not indexable |
53
+
| Enums with payloads | Only no-payload (C-style) enums are supported |
54
+
| Nested structs | Product types cannot be used as index keys |
55
+
56
+
If you attempt to use an unsupported type as an index key, you will get a compile error. For multi-column indexes, every column in the index must use a supported type.
57
+
58
+
:::tip Workaround for floating-point data
59
+
If you need to index floating-point coordinates (for example, `x` and `y` positions), consider storing them as scaled integers. For instance, multiply by 1000 and store as `i32` to get three decimal places of precision while remaining indexable.
60
+
:::
61
+
62
+
Direct indexes have additional restrictions: only `u8`, `u16`, `u32`, `u64`, and no-payload enums are supported.
63
+
34
64
### B-tree Indexes
35
65
36
66
B-trees maintain data in sorted order, enabling both equality lookups (`x = 5`) and range queries (`x > 5`, `x BETWEEN 1 AND 10`). The sorted structure also supports prefix matching on multi-column indexes. B-tree is the default and most commonly used index type.
0 commit comments