#Duplicate index name
7 messages · Page 1 of 1 (latest)
Hi @summer dagger. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Convex requires index names to be unique per table; the docs explicitly say:
“Each index consists of:
- A name.
- Must be unique per table.” [Indexes]
So you cannot define two separate indexes with the same fields but different names on the same table; nor can you reuse the same name for two different index definitions on that table.
If your goal is to reuse one compound index in multiple ways (e.g. sometimes filtering on just the first field, sometimes on both), you can do that with a single index name by omitting conditions on the later fields when querying. [Best practices]
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@summer dagger Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@naive rune no I meant two indexes with different names but having the referencing the same fields
Let me check the knowledge base for you again. One moment! :books:
You can, but it’s unnecessary and not recommended.
The docs don’t forbid defining two indexes on the same table that reference the same fields with different names; they only require that each index name be unique per table. [Indexes]
However, Convex best practices explicitly suggest avoiding redundant indexes, e.g. by_team and by_team_and_user when the longer one can serve both purposes. [Best practices] Two indexes with the same fields are even more redundant: they cost extra storage and write overhead without adding capability.