The `EXPLAIN` clause is used to explain the plan used for a query.
The EXPLAIN clause is used to explain the plan used for a query. It is particularly useful when you want to understand how a query is executed and how it is optimized by the database.
When EXPLAIN is used, the statement returns an explanation, essentially revealing the execution plan to provide transparency and understanding of the query performance.
Syntax
Clause Syntax
@queryEXPLAIN[FULL]
Using the EXPLAIN clause in addition to the FULL keyword is expeciallly useful when you want to understand the performance of a query and can provide more details when debugging.
Examples
For example, consider the performance of the following query when the field email is not indexed. We can see that the execution plan will iterate over the whole table.
When a KNN search over an indexed vector field is combined with an additional non-KNN condition, that condition is pushed into the index search so that non-matching candidates are rejected during the search rather than afterwards. The plan shows this as a predicate attribute on the KnnScan operator. To display the query plan, add the EXPLAIN clause to the end of a query as shown in the example below.
The innermost KnnScan operator carries the predicate: 'flag = true' attribute — the condition that is evaluated inside the index search. The same condition also appears on the Filter operator above it. Adding EXPLAIN FULL includes per-operator metrics. The query plan is identical for a DISKANN index. For a guided walkthrough, see Filtering through vector search.