# EXPLAIN

EXPLAIN describes how CoordinatorDB will execute a statement. Use `EXPLAIN QUERY PLAN` for an access-plan tree, or `EXPLAIN ANALYZE` to execute the statement and collect runtime measurements.

## Forms

* `EXPLAIN QUERY PLAN` returns the selected access plan without executing the statement.
* Plain `EXPLAIN` returns `explain_key`/`explain_value` rows describing the plan and does not run the statement.
* `EXPLAIN ANALYZE` executes a SELECT or data-changing statement once and returns an analyzed plan. It does not return the underlying query's result rows.

For analyzed writes, the changes take effect. Use ordinary transaction controls when a write should be rolled back after measurement.

CoordinatorDB does not support ClickHouse `EXPLAIN PIPELINE` or `EXPLAIN AST` syntax.

## Syntax

```text
EXPLAIN QUERY PLAN statement
EXPLAIN statement
EXPLAIN ANALYZE statement
```

## Example

### Looking up a row by primary key

```sql
CREATE TABLE lookup(id INTEGER PRIMARY KEY,v TEXT);
EXPLAIN QUERY PLAN SELECT v FROM lookup WHERE id=1;
```

```text
OK
┌─id─┬─parent─┬─notused─┬─detail────────────────────────────────────────────────────┐
│  1 │      0 │       0 │ PROJECTION v                                              │
│  2 │      1 │       0 │ ROWID_SCAN Table: lookup; Lookup: Eq(Literal(Integer(1))) │
└────┴────────┴─────────┴───────────────────────────────────────────────────────────┘
(2 rows)
```
