clockworklabs / clockworklabs/SpacetimeDB

Index name colliding

Open
#4,719 0 comments 0 reactions 0 assignees View on GitHub

@rudcode is already working on this.

Since Mar 29, 2026.

  • #4725 by @rudcode — open
Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

I have tables like this:

#[spacetimedb::table(accessor = product_category, public)]
pub struct ProductCategory {
    #[primary_key]
    #[auto_inc]
    pub id: u64,
    #[index(btree)]
    pub store_id: u64,
    pub name: String,
}

#[spacetimedb::table(accessor = product, public)]
pub struct Product {
    #[primary_key]
    #[auto_inc]
    pub id: u64,
    #[index(btree)]
    pub store_id: u64,
    #[index(btree)]
    pub category_id: u64,
    pub name: String,
    pub description: Option<String>,
    pub price: u128,
}

it compile just fine when using spacetime build
but when I spacetime publish it return error:

name product_category_id_idx_btree is used for multiple entities

From what I see its because of the index is generated by {accessor}_{field}_idx_btree, so it output the same product_category_id_idx_btree for both of the table. It's nice if we can specify the name of index with something like

#[index(btree, name="prod_category_id_idx_btree2")]

or maybe even better automagically handle that colliding name in macros

oh, after reading the spactimedb code I see the index name will auto generated with this format:
{table_name}_{cols}_idx_{algo}
maybe the simple fix is to change the separator to be double __:
{table_name}__{cols}_idx_{algo}
or use another character for separator, I don't know, what do you think?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the index-name generation used by the #[index(btree)] attributes and compare the spacetime build and spacetime publish paths for the supplied ProductCategory and Product tables. Done means these tables publish successfully without the product_category_id_idx_btree duplicate-name error; linked pull request 4725 indicates work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.