# ESTIMATED\_QUERY\_RUNTIME

Returns an estimate of the elapsed time, in seconds, required to run a query.

The elapsed time includes the execution time for the query as well as the time required by any blocking operations that delay the query from executing.

This function is intended to be used inside a [user-defined scalar function (UDF) that selects a resource pool](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/use-the-workload-manager-and-set-resource-limits/set-resource-limits/select-a-resource-pool-dynamically.md).

> **📝 Note**: At this time, `ESTIMATED_QUERY_RUNTIME` is an experimental function. It is not formally supported. However, feedback and suggestions on this function are welcome.

## Syntax

```sql
ESTIMATED_QUERY_RUNTIME()

```

## Return Type

Double

## Remarks

* For `ESTIMATED_QUERY_RUNTIME` to provide an accurate estimate, statistics must first be collected on the query that this function operates on. After an initial run of the query, statistics are automatically collected at ten minute intervals. You can collect statistics immediately by running `ANALYZE MEMORY`.
* Returns `-1` if SingleStore cannot estimate the time required to run the query, because statistics on the query have not been collected.

## Examples

## Example: Using `ESTIMATED_QUERY_RUNTIME()` Inside a Resource Pool Selector Function

*Setting Resource Limits* provides an [example](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/use-the-workload-manager-and-set-resource-limits/set-resource-limits/select-a-resource-pool-dynamically.md) of using `ESTIMATED_QUERY_RUNTIME()` inside of a user-defined scalar function (UDF). The UDF selects a resource pool dynamically.

## Example: Using `ESTIMATED_QUERY_RUNTIME()` Outside a Resource Pool Selector Function

While `ESTIMATED_QUERY_RUNTIME()` is intended to be used inside a resource pool selector function, you can use it outside the function for testing. The following example estimates the elapsed time required to run three simple queries.

First, do an initial run of the three queries, followed by `ANALYZE MEMORY` to collect statistics on the queries. The initial run returns `-1` because statistics have not yet been collected.

```sql
SELECT SLEEP(0.5), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(0.5) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                        -1 |
+------------+---------------------------+

```

```sql
SELECT SLEEP(1.5), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(1.5) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                        -1 |
+------------+---------------------------+

```

```sql
SELECT SLEEP(3.0), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(3.0) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                        -1 |
+------------+---------------------------+

```

Next, collect statistics on the queries:

```sql
ANALYZE MEMORY;

```

Re-run the previous query that sleeps for 0.5 seconds.

```sql
SELECT SLEEP(0.5), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(0.5) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                     0.507 |
+------------+---------------------------+

```

Re-run the previous query that takes 1.5 seconds.

```sql
SELECT SLEEP(1.5), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(1.5) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                     1.508 |
+------------+---------------------------+

```

Re-run the previous query that takes 3.0 seconds.

```sql
SELECT SLEEP(3.0), ESTIMATED_QUERY_RUNTIME();

```

```output

+------------+---------------------------+
| SLEEP(3.0) | ESTIMATED_QUERY_RUNTIME() |
+------------+---------------------------+
|          0 |                     3.009 |
+------------+---------------------------+

```

***

Modified at: November 19, 2025

Source: [/db/v9.1/reference/sql-reference/information-functions/estimated-query-runtime/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/information-functions/estimated-query-runtime/)

(An index of the documentation is available at /llms.txt)
