# Query Cancellation

Use query cancellation when a query is still running and you need to stop it before it finishes.

## Enable tracking first

Query cancellation depends on query tracking being enabled on both the server and the broker.

```properties
pinot.server.enable.query.cancellation=true
pinot.broker.enable.query.cancellation=true
```

## Preferred flow: cancel by client query ID

The cleanest cancellation flow is to set `clientQueryId` on the query and then cancel by that ID.

```sql
SET clientQueryId = 'query-2026-03-24-001';
SELECT * FROM stores LIMIT 100;
```

Then cancel it with the matching ID:

```sh
curl -X DELETE 'http://localhost:9000/queryClient/query-2026-03-24-001'
```

This is the best option for programs because the client query ID can also be used as the correlation ID for logs.

## Fallback flow: cancel by internal broker ID

If you do not control the client query ID, Pinot can still cancel a query using the broker-assigned internal ID. That flow is more operationally awkward because you need both the broker and the internal query ID.

## What this page covered

This page covered the prerequisites for cancellation, the recommended client-query-ID flow, and the internal-ID fallback.

## Next step

If you need the query ID for logs or tracing, read [Correlation IDs](/build-with-pinot/querying-and-sql/query-execution-controls/query-correlation-id.md).

## Related pages

* [Query options](/build-with-pinot/querying-and-sql/query-execution-controls/query-options.md)
* [Correlation IDs](/build-with-pinot/querying-and-sql/query-execution-controls/query-correlation-id.md)
* [Query quotas](/build-with-pinot/querying-and-sql/query-execution-controls/query-quotas.md)


---

# 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/build-with-pinot/querying-and-sql/query-execution-controls/query-cancellation.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.
