# EXPLAIN ANALYZE

Para optimizar y depurar consultas, InfluxDB ofrece herramientas como `EXPLAIN` y `EXPLAIN ANALYZE`, que permiten analizar cómo se ejecutan internamente las consultas y detectar cuellos de botella o ineficiencias.

## **¿Qué es EXPLAIN ANALYZE?** <a href="#undefined" id="undefined"></a>

* `EXPLAIN` muestra el plan de ejecución lógico y físico de una consulta, permitiendo visualizar los pasos que seguirá el motor para procesarla.
* `EXPLAIN ANALYZE` ejecuta la consulta y, además del plan, incluye métricas de tiempo de ejecución, contadores de filas y detalles de cada operador, facilitando la depuración y optimización.

## **¿Por qué es importante en InfluxDB 2.x?** <a href="#undefined" id="undefined"></a>

* Permite identificar operaciones costosas (escaneos completos, ordenamientos, etc.).
* Ayuda a entender cómo InfluxDB accede a los datos (por ejemplo, uso de índices, lectura de archivos Parquet).

## **Cómo usar EXPLAIN ANALYZE en InfluxDB 2.x** <a href="#undefined" id="undefined"></a>

### **Sintaxis básica**

{% code title="sql" overflow="wrap" %}

```sql
EXPLAIN ANALYZE
SELECT campo1, campo2
FROM medicion
WHERE time >= '2023-01-01' AND time <= '2023-12-31'
GROUP BY etiqueta
ORDER BY time DESC
```

{% endcode %}

### **¿Dónde se ejecuta?**

* En la consola de InfluxDB (CLI), desde clientes compatibles o mediante la API.
* Compatible tanto con InfluxQL como con SQL en InfluxDB 2.x y 3.x.

## **Interpretación del Plan de Ejecución** <a href="#undefined" id="undefined"></a>

### **Componentes del reporte**

<table><thead><tr><th width="224">Componente</th><th>Descripción</th></tr></thead><tbody><tr><td>Plan lógico</td><td>Representa la lógica de la consulta select → create_iterator (por cada shard).</td></tr><tr><td>Plan físico</td><td>Detalla los operadores físicos (lectura de archivos, ordenamientos).</td></tr><tr><td>Métricas de ejecución</td><td>Incluye tiempo de ejecución, filas procesadas, y contadores de cada operador.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://darioaplicano.gitbook.io/influxdb2.x/sesion-4/guion-de-la-sesion/documentacion/consultas-avanzadas-y-optimizacion/explain-analyze.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
