> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.sqd.dev/feedback

```json
{
  "path": "/en/sdk/squid-sdk/reference/schema-file/indexes-and-constraints",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Indexes and constraints

> Annotate Squid SDK schema fields with @index and @unique to speed up GraphQL queries — match indexes to your most common entity filter patterns.

# Indexes and unique constraints

<Warning>
  The lack of indices is the most common cause of slow API queries
</Warning>

It is crucial to add database indexes to the entity fields on which one expects filtering and ordering. To add an index to a column, the corresponding entity field must be decorated with `@index`. The corresponding entity field will be decorated with [TypeORM `@Index()`](https://typeorm.io/indices#column-indices).

One can additionally decorate the field with `@unique` to enforce uniqueness. It corresponds to the [`@Index({ unique: true })`](https://typeorm.io/indices#unique-indices) TypeORM decorator.

### Example

```graphql theme={"system"}
type Transfer @entity {
  id: ID!
  to: Account!
  amount: BigInt! @index
  fee: BigInt! @index @unique
}
```

## Multi-column indices

Multi-column indices are defined on the entity level, with an optional `unique` constraint.

### Example

```graphql theme={"system"}
type Foo @entity @index(fields: ["foo", "bar"]) @index(fields: ["bar", "baz"]) 
  {
  id: ID!
  bar: Int!
  baz: [Enum!]
  foo: String!

type Extrinsic @entity @index(fields: ["hash", "block"], unique: true)  {
  id: ID!
  hash: String! @unique
  block: String!
}
```
