Docs
Search⌘ K
  • Home
  • About The Graph
  • Supported Networks
  • Protocol Contracts
  • AI Tooling
  • Subgraphs
    • Substreams
      • Indexer Software
        • Gateway Software
          • Data Services
            • Resources
              Subgraphs > Guides & Best Practices

              2 minutes

              Improve Query Speed with Pruning

              Pruning removes old entity versions from a Subgraph’s database up to a given block. A smaller database answers queries faster, often dramatically. Setting indexerHints in the manifest is the simplest way to prune.

              How to Prune a Subgraph With indexerHints

              Add a section called indexerHints in the manifest.

              indexerHints has three prune options:

              • prune: auto: Retains the minimum necessary history as set by the Indexer, optimizing query performance. This is the generally recommended setting and is the default for all Subgraphs created by graph-cli >= 0.66.0.
              • prune: <Number of blocks to retain>: Sets a custom limit on the number of historical blocks to retain.
              • prune: never: No pruning of historical data; retains the entire history and is the default if there is no indexerHints section. prune: never should be selected if Time Travel Queries are desired.

              Add indexerHints to your subgraph.yaml (requires specVersion 1.0.0 or later):

              1specVersion: 1.3.02schema:3  file: ./schema.graphql4indexerHints:5  prune: auto6dataSources:7  - kind: ethereum/contract8    name: Contract9    network: mainnet

              Important Considerations

              • If Time Travel Queries are desired as well as pruning, pruning must be performed accurately to retain Time Travel Query functionality. Due to this, it is generally not recommended to use indexerHints: prune: auto with Time Travel Queries. Instead, prune using indexerHints: prune: <Number of blocks to retain> to accurately prune to a block height that preserves the historical data required by Time Travel Queries, or use prune: never to maintain all data.

              • It is not possible to graft at a block height that has been pruned. If grafting is routinely performed and pruning is desired, it is recommended to use indexerHints: prune: <Number of blocks to retain> that will accurately retain a set number of blocks (e.g., enough for six months).

              Learn More

              • Time Travel Queries: query entity state at a past block.
              • Grafting: why your pruning window matters if you graft.
              • Guides & Best Practices overview: the full checklist and how this page fits with the rest of the section.
              ⁠Edit on GitHub⁠

              Categorize Data with EnumsSecure API Keys with Next.js
              On this page
              • How to Prune a Subgraph With indexerHints
              • Important Considerations
              • Learn More
              The GraphStatusTestnetBrand AssetsForumSecurityPrivacy PolicyTerms of Service