# Use the multi-stage query engine (v2)

To query using distributed joins, window functions, and other multi-stage operators in real time, you must enable the multi-stage query engine (v2). To enable v2, do any of the following:

* Enable the multi-stage query engine [in the Query Console](#enable-the-multi-stage-query-engine-in-the-query-console)
* Programmatically access the multi-stage query engine:
  * Query [using REST APIs](#use-rest-apis)
  * Query outside of the APIs [using the query option](#use-the-query-option)

To learn more about what the multi-stage query engine is, see [Multi-stage query engine (v2)](https://docs.pinot.apache.org/release-1.0.0/reference/cluster-1).&#x20;

## Enable the multi-stage query engine in the Query Console

* To enable the multi-stage query engine, in the Pinot Query Console, select the **Use Multi-Stage Engine** check box.

<figure><img src="https://content.gitbook.com/content/gYpmZ5dnYUh7aQjLUJ9b/blobs/ylFKzZJoDbpmavT8o2Wq/Screenshot%202023-09-14%20at%209.59.22%20AM.png" alt=""><figcaption><p>Pinot Query Console with Use Multi Stage Engine enabled</p></figcaption></figure>

## Programmatically access the multi-stage query engine

To query the Pinot multi-stage query engine, use REST APIs or the query option:

### Use REST APIs

The Controller admin API and the Broker query API allow optional JSON payload for configuration. For example:

* [For Controller Admin API](https://docs.pinot.apache.org/release-1.0.0/for-users/api/pinot-rest-admin-interface)

```bash
curl -X POST http://localhost:9000/sql -d 
'
{
  "sql": "select * from baseballStats limit 10",
  "trace": false,
  "queryOptions": "useMultistageEngine=true"
}
'
```

* [For Broker Query API](https://docs.pinot.apache.org/release-1.0.0/for-users/api/querying-pinot-using-standard-sql)

```bash
curl -X POST http://localhost:8000/query/sql -d '
{
  "sql": "select * from baseballStats limit 10",
  "trace": false,
  "queryOptions": "useMultistageEngine=true"
}
'
```

### Use the query option

To enable the multi-stage engine via a query outside of the API, add the `useMultistageEngine=true` option to the top of your query.&#x20;

For example:

<pre class="language-sql"><code class="lang-sql"><strong>SET useMultistageEngine=true; -- indicator to enable the multi-stage engine.
</strong>SELECT * from baseballStats limit 10
</code></pre>


---

# 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://docs.pinot.apache.org/release-1.0.0/for-developers/advanced/v2-multi-stage-query-engine.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.
