Documentation

Optimize queries

Limited availability

InfluxDB Clustered is currently 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.

Use the following tools to help you identify performance bottlenecks and troubleshoot problems in queries:

EXPLAIN and ANALYZE

To view the query engine’s execution plan and metrics for an SQL query, prepend EXPLAIN or EXPLAIN ANALYZE to the query. The report can reveal query bottlenecks such as a large number of table scans or parquet files, and can help triage the question, “Is the query slow due to the amount of work required or due to a problem with the schema, compactor, etc.?”

The following example shows how to use the InfluxDB v3 Python client library and pandas to view EXPLAIN and EXPLAIN ANALYZE results for a query:

from influxdb_client_3 import InfluxDBClient3
import pandas as pd
import tabulate # Required for pandas.to_markdown()

# Instantiate an InfluxDB client.
client = InfluxDBClient3(token = f"
DATABASE_TOKEN
"
,
host = f"cluster-host.com", database = f"
DATABASE_NAME
"
)
sql_explain = '''EXPLAIN SELECT temp FROM home WHERE time >= now() - INTERVAL '90 days' AND room = 'Kitchen' ORDER BY time''' table = client.query(sql_explain) df = table.to_pandas() print(df.to_markdown(index=False)) assert df.shape == (2, 2), f'Expect {df.shape} to have 2 columns, 2 rows' assert 'physical_plan' in df.plan_type.values, "Expect physical_plan" assert 'logical_plan' in df.plan_type.values, "Expect logical_plan"

View EXPLAIN example results

sql_explain_analyze = '''EXPLAIN ANALYZE
                      SELECT *
                      FROM home
                      WHERE time >= now() - INTERVAL '90 days'
                      ORDER BY time'''

table = client.query(sql_explain_analyze)
df = table.to_pandas()
print(df.to_markdown(index=False))

assert df.shape == (1,2)
assert 'Plan with Metrics' in df.plan_type.values, "Expect plan metrics"

client.close()

Replace the following:

  • DATABASE_NAME: your InfluxDB Clustered database
  • DATABASE_TOKEN: a database token with sufficient permissions to the specified database

View EXPLAIN ANALYZE example results


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:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.