> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# get_query_profile

> Obtains the profile of a query by using its query_id.

Obtains the profile of a query by using its `query_id`. This function returns empty if the `query_id` does not exist or is incorrect.

To use this function, you must enable the profiling feature, that is, set the session variable `enable_profile` to `true` (`set enable_profile = true;`). If this feature is not enabled, an empty profile is returned.

This function is supported from v3.0.

If the FE configuration item `authorization_enable_query_profile_access_check` is set to `true`, this function returns only the profiles of queries run by the current user, unless the user has the SYSTEM-level OPERATE privilege. In that case, passing a non-constant `query_id`, or a `query_id` whose profile is not cached on the FE the session is connected to, also requires the OPERATE privilege. When `authorization_enable_admin_user_protection` is also enabled, only `root` can pass a `query_id` that is not cached on the connected FE. To read your own profile without the OPERATE privilege, obtain the id first with `select last_query_id();` and pass the returned literal, as shown in the examples below.

## Syntax

```Haskell theme={null}
get_query_profile(x)
```

## Parameters

`x`: the query\_id string. The supported data type is VARCHAR.

## Return value

The query profile contains the following fields. For more information about the query profile, see [Query Profile](/documents/4.2/best_practices/query_tuning/query_profile_overview.md).

```SQL theme={null}
Query:
  Summary:
  Planner:
  Execution Profile 7de16a85-761c-11ed-917d-00163e14d435:
    Fragment 0:
      Pipeline (id=2):
        EXCHANGE_SINK (plan_node_id=18):
        LOCAL_MERGE_SOURCE (plan_node_id=17):
      Pipeline (id=1):
        LOCAL_SORT_SINK (plan_node_id=17):
        AGGREGATE_BLOCKING_SOURCE (plan_node_id=16):
      Pipeline (id=0):
        AGGREGATE_BLOCKING_SINK (plan_node_id=16):
        EXCHANGE_SOURCE (plan_node_id=15):
    Fragment 1:
       ...
    Fragment 2:
       ...
```

## Examples

```sql theme={null}
-- Enable the profiling feature.
set enable_profile = true;

-- Run a simple query.
select 1;

-- Get the query_id of the query.
select last_query_id();
+--------------------------------------+
| last_query_id()                      |
+--------------------------------------+
| bd3335ce-8dde-11ee-92e4-3269eb8da7d1 |
+--------------------------------------+

-- Obtain the query profile.
select get_query_profile('502f3c04-8f5c-11ee-a41f-b22a2c00f66b');

-- Use the regexp_extract function to obtain the QueryPeakMemoryUsage in the profile that matches the specified pattern.
select regexp_extract(get_query_profile('bd3335ce-8dde-11ee-92e4-3269eb8da7d1'), 'QueryPeakMemoryUsage: [0-9\.]* [KMGB]*', 0);
+-----------------------------------------------------------------------------------------------------------------------+
| regexp_extract(get_query_profile('bd3335ce-8dde-11ee-92e4-3269eb8da7d1'), 'QueryPeakMemoryUsage: [0-9.]* [KMGB]*', 0) |
+-----------------------------------------------------------------------------------------------------------------------+
| QueryPeakMemoryUsage: 3.828 KB                                                                                        |
+-----------------------------------------------------------------------------------------------------------------------+
```

## Related functions

* [last\_query\_id](/documents/4.2/sql-reference/sql-functions/utility-functions/last_query_id.md)
* [regexp\_extract](/documents/4.2/sql-reference/sql-functions/like-predicate-functions/regexp_extract.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.