AF
Ash Framework•3mo ago
cr0nk

Understanding indexes

I come from the Node.js/MongoDB world and I'm learning Elixir and Ash. I'm trying to ensure my resources/tables are correctly indexed (using AshPostgres). For that I have the following questions when using Ash: 1. Is the primary :id attribute always indexed? 2. If one would like to make a partial index like [:user_id, :is_active] we should use custom_indexes inside the postgres definition, right? - would this then also be usable by queries that only filter on :user_id (but not filtering on the :is_active )? 3. Is identities attribute is only for making unique indexes? 4. Do I need to use the custom_indexes if I want to just index one attribute like created_at for example, or is there another preferred way of doing that? Thanks in advance! Looking forward to build something cool with Ash 🙂
Solution:
1. In Postgres at least, yes. Primary keys get a unique index. 2. This is more of a Postgres question than an ash question, I'd suggest looking at their docs. IIRC you're describing a composite index not a partial one (a partial one would be one with a where clause). 3. Yes. The identities have other uses but they imply a unique constraint and the migration generator will create one 4. Yes, that is how you'd do it 🙂...
Jump to solution
2 Replies
Solution
ZachDaniel
ZachDaniel•3mo ago
1. In Postgres at least, yes. Primary keys get a unique index. 2. This is more of a Postgres question than an ash question, I'd suggest looking at their docs. IIRC you're describing a composite index not a partial one (a partial one would be one with a where clause). 3. Yes. The identities have other uses but they imply a unique constraint and the migration generator will create one 4. Yes, that is how you'd do it 🙂
cr0nk
cr0nkOP•3mo ago
Thanks for the clarification!

Did you find this page helpful?