Documentation

Optimize queries

Optimize SQL and InfluxQL queries to improve performance and reduce their memory and compute (CPU) requirements. Learn how to use observability tools to analyze query execution and view metrics.

Why is my query slow?

Query performance depends on time range and complexity. If a query is slower than you expect, it might be due to the following reasons:

  • It queries a large time-range of data.
  • It includes intensive operations, such as querying many string values or ORDER BY sorting or re-sorting large amounts of data.

Strategies for improving query performance

The following design strategies generally improve query performance and resource use:

  • Follow schema design best practices to make querying easier and more performant.
  • Query only the data you need–for example, include a WHERE clause that filters data by a time range. InfluxDB v3 stores data in a Parquet file for each measurement and day, and retrieves files from the Object store to answer a query. The smaller the time range in your query, the fewer files InfluxDB needs to retrieve from the Object store.
  • Downsample data to reduce the amount of data you need to query.

Some bottlenecks may be out of your control and are the result of a suboptimal execution plan, such as:

  • Applying the same sort (ORDER BY) to already sorted data.
  • Retrieving many Parquet files from the Object store–the same query performs better if it retrieves fewer - though, larger - files.
  • Querying many overlapped Parquet files.
  • Performing a large number of table scans.

Analyze and troubleshoot queries

Use the following tools to analyze and troubleshoot queries and find performance bottlenecks:

Enable trace logging for a query

Customers with an InfluxDB Cloud Serverless annual or support contract can contact InfluxData Support to enable tracing and request help troubleshooting your query. With tracing enabled, InfluxDB Support can trace system processes and analyze log information for a query instance. The tracing system follows the OpenTelemetry traces model for providing observability into a request.


Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

InfluxDB Cloud Serverless