> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/elixir/creating-indexes-with-ecto.md).

# Creating Indexes With Ecto

Using indexes in the right places within relational databases is a great way to speed up queries.

To add a basic index in an Ecto migration, use `Ecto.Migration.index\2`:

```elixir
create index(:users, [:email])
```

Creating a composite index doesn't require jumping through any hoops; just put the relevant column names in the list:

```elixir
create index(:posts, [:user_id, :title])
```

See `h Ecto.Migration.index` for more details.
