> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/tools/enterprise/control-center/gg9/querying-gg9.md).

# Queries

Executing SQL queries against a GridGain 9 cluster from the Control Center Queries screen, working with indexes, and using the queries log.

The **Queries** screen allows you to execute SQL queries against the GridGain 9 cluster and view the query results.

The screen consists of two tabs:

* **Queries List** — execute SQL queries
* **Queries Log** — view the log of executed queries

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-82e28b16ddb39f114eb10a87114b9b43155a50db%2Fcc-gg9-queries_list.png?alt=media)

You can add multiple tabs to the screen, each containing an SQL expression and the query results (after you have executed the query). To add a tab, click the **+** icon on the tab bar.

The screen also provides **Add Schema** and **Add Data** buttons in the top-right corner, which open the [Data and Schema Import](/docs/tools/enterprise/control-center/gg9/data-schema-import.md) feature for importing schemas from external databases or loading data into the cluster.

## Defining Queries

Type the SQL expression in the "SQL editor" section of the tab.

You can enter multiple expressions in a single query. These are executed sequentially by an SQL script.

## Executing Queries

To execute a SQL statement, click **Execute** on the tab toolbar.

The query results are displayed in the lower part of the screen, in a tab matching the query expression one.

The tab-level context menu includes the following options:

* **Copy** - copies the result set to the clipboard
* **Remove** - deletes query and closes the tab
* **Rename** - set a custom name for the tab

The row-level context menu includes the **Copy** option, which copies the corresponding row to the clipboard.

## Working with Indexes

You can create indexes via the context menu in the **Queries** screen. This action will open a new tab with the predefined SQL request.

![Create Index](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-19b16575f6b01f85218a42b6fb1ab44663290c6c%2Fcc-gg9-create_index.png?alt=media)

To view index details, click on the context menu and select **View Details**. A new tab will open and the request will run automatically.

![View Index Details](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-4461b02ecfe771cc1de3abfddf2c470437cab1eb%2Fcc-gg9-details_index.png?alt=media)

To drop an index, click on the context menu and select **Drop Index**. This will trigger the confirmation dialog and if the action is confirmed, a new tab will open and the request will run automatically.

{% hint style="info" %}
You cannot drop an index for `PRIMARY KEY`.
{% endhint %}

![Drop Index](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-cda63adc33130296117bac90871372806e11e24d%2Fcc-gg9-drop_index.png?alt=media)

## Queries Log

The **Queries Log** tab shows all tracked queries.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-293b91f5043c25dc3eaa8a6795117ebcc311595d%2Fcc-gg9-queries_log.png?alt=media)

For managed clusters, query tracking is enabled automatically.

For attached clusters, switch on the **Queries log** option in the cluster [**Monitoring configuration**](/docs/tools/enterprise/control-center/gg9/dashboard/my-cluster.md#monitoring-configuration) dialog and click **Save**:

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-07770bfdd7b4199fc90269db54694f9558ab6acc%2Fcc-gg9-update_cluster_config.png?alt=media)

You can filter the display by status, query duration, and other criteria for a more precise view.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-a1097c27793e1e35c6fa1b0987d8b18287eb0b9c%2Fcc-gg9-queries_filter.png?alt=media)

Each query includes the following details:

| Column           | Description                                                                                                                                                                |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ID               | Query ID.                                                                                                                                                                  |
| Query            | The query text.                                                                                                                                                            |
| Initiator node   | Node where the query is executed.                                                                                                                                          |
| Type             | Query type.                                                                                                                                                                |
| Schema           | The schema used. Hidden by default — enable via the column context menu.                                                                                                   |
| Status           | <p>Query status. Possible values:<br>- <code>Running</code><br>- <code>Finished</code><br>- <code>Failed</code><br>- <code>Canceled</code><br>- <code>Unknown</code></p>   |
| Statement number | Position of the statement within the SQL script. Hidden by default — enable via the column context menu.                                                                   |
| Transaction ID   | Transaction ID. Not applicable for DDL queries.                                                                                                                            |
| Start time       | The time the query started.                                                                                                                                                |
| Parent ID        | ID of the parent query that initiated this query. Available for queries executed via the SQL CLI on the cluster, but not for those run in the **Queries List** tab editor. |
| Duration         | Query duration.                                                                                                                                                            |

### Checking Failure Reasons

If a query is marked as `Failed`, click its status to see detailed error information.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-ccdb804ed812eae1c5a2407410ef4c762174cc17%2Fcc-gg9-rq_failed_details.png?alt=media)

### Canceling Queries

When a query is in `Running` status, you can cancel it from the row-level context menu. Once canceled, its status will change to `Canceled`.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-fb062ba81789e98769d7787f75770d730ea085a3%2Fcc-gg9-rq_cancel.png?alt=media)

### Explaining Queries

To analyze an executed query, run an `EXPLAIN` query using the row-level context menu. For more details on how the `EXPLAIN` query works in GridGain, refer to the [documentation](/docs/tools/enterprise/control-center/gg8/queries/querying.md#using-the-explain-statement).

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-74af4e8e5caffa10146fa3a4fe2990b6f9cfdebb%2Fcc-gg9-rq_explain.png?alt=media)

A new tab opens in the **Queries List**, displaying the results of the EXPLAIN query.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-e73f12a9b2c4bfcdd8ddb4f0b7fd40850d7174ab%2Fcc-gg9-rq_explain_query.png?alt=media)

### Selecting Queries to Track

To reduce GridGain Control Center load and minimize disk space usage, you can specify which queries to track by setting a minimum query duration. Only queries that exceed the specified duration will appear in the **Queries Log** tab.

To select queries to track:

* Click **Configure queries log** in the top-right corner of the tab.
* In the **Configure queries log** dialog, define query duration and click **Save**.

![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-9945dc3e15ca3b9af5df68a19971ce7864eb2908%2Fcc-gg9-rq_config.png?alt=media)

For example, entering "500" in the **Duration** field will track only queries lasting longer than 500 ms. This applies even to queries already in `Running` status when you save the configuration.
