> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/user-guide/6.2-user-guide/using/using-sql-to-query-kafka/managing-queries.md).

# Managing queries

Understand to manage queries for Lenses SQL Snapshot concepts engine for Apache Kafka

### Termination Control <a href="#termination-control" id="termination-control"></a>

```sql
SELECT * FROM topicA WHERE _key.deviceId=123 LIMIT 10
```

Adding a **LIMIT 10** in the SQL query will result in the SQL terminating early, as soon as 10 x messages have been discovered. It’s not a perfect solution as we might never find 10 x messages, and thus perform a full scan.

You can also set a maximum query or idle time:

```sql
SET max.query.time = 30s;
```

or max idle time, the idea is that there is no reason to keep polling if we have exhausted the entire topic:

```sql
SET max.idle.time = 5s;
```

You can also set the maximum Kafka data scanned per query. `max.size` is expressed as bytes. It is not a memory allocation, and it does not set the number of returned records. `LIMIT` sets the returned-record limit, but a query can reach `max.size` before it finds enough matching records.

```sql
SET max.size = '200m';
```

If SQL Studio shows `Query is finished, max size reached`, the query reached its configured Kafka byte-scan cap. It did not reach a row limit or memory limit. Set `max.size` to `'200m'`, then rerun the query to allow up to 200 MB of Kafka data to be scanned.

Use the smallest cap that meets your need. Raising the cap can increase Kafka and broker processing, network bandwidth between Kafka and Lenses, and response time. Narrow the query with topic, partition, offset, or timestamp filters where possible.

### Recent queries <a href="#recent-queries" id="recent-queries"></a>

Recent queries are displayed, but only for the current session, they are not currently retained.

Click on the play button to run a previous query. If a query is already running, you will be asked if you want to stop it first.

**View All queries**

```sql
SHOW ALL QUERIES
```

**View Running queries**

You can see all running queries by Lenses users using SQL:

```
SHOW QUERIES
```

### Kill Running queries <a href="#kill-running-queries" id="kill-running-queries"></a>

You can force stop a query by another user using SQL:

```sql
KILL QUERY <id>
```

### Concurrent queries limit <a href="#concurrent-queries-limit" id="concurrent-queries-limit"></a>

Starting with 6.1.3 version, there's a global limit on concurrent queries, as well as a limit per user. They can be set via the [agent configuration](/latest/devx/6.2/deployment/configuration/agent/overview.md):

```properties
lenses.sql.settings.max.concurrent.queries=200
lenses.sql.settings.max.concurrent.queries.per.user=2
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lenses.io/latest/user-guide/6.2-user-guide/using/using-sql-to-query-kafka/managing-queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
