> ## 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.

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 120+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# Indexes and constraints

> Annotate Squid SDK schema fields with @index and @unique to speed up GraphQL queries.

<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!
}
```

Only scalar, enum, and foreign-key fields can be indexed. Codegen rejects list
and JSON fields in both single-column and multi-column indexes.


## Related topics

- [Indexes and constraints](/en/sdk/squid-sdk/solana/reference/schema-files/indexes-constraints.md)
- [Tuning update-heavy tables](/en/cloud/resources/update-heavy-tables.md)
- [Entity relations](/en/sdk/squid-sdk/solana/reference/schema-files/entity-relations.md)
- [Schema changes and backfills](/en/cloud/resources/schema-changes-and-backfills.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.