> 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/gg8/queries/querying.md).

# Queries Screen

Executing SQL and scan queries against GridGain 8 clusters from the Control Center Queries screen, plus the queries log and query statistics.

The **Queries** screen allows you to execute SQL queries against the GridGain 8 (Apache Ignite 2) cluster and view results. You can also view running queries and query statistics.

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

## Overview of SQL Screen

The **Queries** screen consists of three tabs:

* **Queries list** — execute SQL queries
* **Queries log** — view the list of running and recently completed queries
* **Query statistics** — view query statistics

The **Queries list** tab displays the **Search** tree that lets you view the tables, caches, system views, and nodes that are available in the cluster.

The tree consists of the following branches:

* The Schemas branch contains the SQL tables.
* The Caches branch contains the names of the caches.
* The System views branch contains the cluster's system views. See [Querying System Views](#querying-system-views).
* The Nodes branch contains node IDs. You can [execute a SQL query on a specific node](#executing-queries-on-a-specific-node).

{% hint style="info" %}
When you use the CREATE TABLE command to create a table, GridGain creates an underlying cache. Therefore, when you create a table, a new cache appears in the tree.
{% endhint %}

## Executing Queries

### SQL Queries

Control Center allows you to execute both DML and DDL statements supported by GridGain/Apache Ignite. See the SQL Reference guide for details.

To execute a SQL statement, click the `+` icon in the queries tab bar and select **SQL query** from the dropdown list. Then, enter a statement in the query editor, and click **Execute**.

You can also select a statement you need out of a longer query and **Execute statement** instead.

The query results are displayed below the query editor. You can copy all results in the table by clicking ⋮ in the results tab and selecting **Copy**. Alternatively, you can use the context menu for the row to copy a single row of results.

#### Advanced Settings

Control Center provides a number of additional options that are not required for simpler queries. Click the cogwheel icon to open the Advanced Settings panel.

#### Selecting a Schema

You can set the schema for SQL statements in the **Default schema** field. The drop-down field contains a list of existing schemas. Control Center uses the schema that you selected in the **Default schema** field to resolve any unqualified reference that is included within any SQL statement that is executed on the tab. Refer to the Understanding Schemas page for more information about schemas in GridGain.

#### Working with Indexes

You can create indexes via the context menu in the **Queries** screen.

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

{% hint style="info" %}
Indexes for `PRIMARY KEY` are not displayed. Only custom indexes are available.
{% endhint %}

To view index details, click on the context menu and select **View Details**.

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

To drop an index, click on the context menu and select **Drop Index**.

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

#### Non-Colocated Joins

**Allow non-collocated joins**. Set this flag if you want to execute a join query that joins tables on a non-affinity key. If you don't set the flag, the results of the query might be incorrect. Refer to this section for details.

#### Join Order

**Enforce join order**. This option enforces GridGain to use the order of joins as the order is specified in the query, rather than to rely on the optimizer. The optimizer cannot always determine the best order. Refer to this section for details.

#### Lazy Loading

**Lazy result set**. You set this flag to lazily load the results of the query. Use of this flag can help to prevent OutOfMemory exceptions that may occur when the result set is too large. Refer to the Lazy Result Loading section for details.

#### Executing Queries on a Specific Node

In a multi-node cluster, the data that is held in a table is distributed among all server nodes. When you run a SQL query, the query is distributed among the nodes in a map-reduce manner. However, you can limit the scope of the query to a specific node. If you limit the scope, the query is run against the data that is held on the specified node.

Click **Select particular node**, and, in the dialog box that appears, you select the node.

#### Using the Explain Statement

You can use the `EXPLAIN` statement to view the execution plan for a SELECT query. The execution plan can help you to analyze the query for performance optimization. Simply add 'EXPLAIN' at the beginning of the statement and click **Execute**.

Distributed queries are executed in a map-reduce manner. The execution plan consists of two parts: the map query (the query executed on each node with data) and the reduce query (the "reduce" part, which is performed on the node that initiates the query, the coordinator node).

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

### Querying System Views

The **System views** branch of the **Search** tree lists the cluster's system views that expose internal information about the cluster, such as nodes, caches, and node metrics.

![System Views](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-034c4d3cee538f18c9e2b8618626a767ba09bf87%2Fcc-gg8-system-views-tree.png?alt=media)

To query a system view, right-click it in the tree and select **Select 100 rows**.

![System Views](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-f98c8bfb8e04521551b1523e299100316b7fe7d5%2Fcc-gg8-system-views-select.png?alt=media)

A fully-qualified statement appears into the query editor, which you can then run or edit:

```sql
SELECT * FROM "SYS"."NODES" LIMIT 100
```

### Scan Queries

Control Center allows you to execute scan queries - simple search queries used to retrieve data from a cache in a distributed manner. When executed without parameters, a scan query returns all entries from the cache.

To execute a scan query, click the `+` icon in the **Queries list** tab bar and select **Scan query** from the dropdown list, then select a cache to query from the **Choose cache** list.

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

Alternatively, you can select the **Run scan query** option from the context menu for a specific cache:

* In the **Search** tree on the left, or
* In the [Caches screen](/docs/tools/enterprise/control-center/gg8/caches/caches.md).

Once the cache is selected, the scan query runs with all the advanced options set to default values. The query result is displayed at the bottom of the **Queries list** tab.

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

#### Advanced Options

To run your scan query with advanced options:

1. Open the **Advanced settings** section by clicking the **Expand** triangle next to the label.

   ![](https://2850516351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkuTXWg0NDbRx6XUeYpGD%2Fuploads%2Fgit-blob-840a4da026ba975a9e3d3c8713592c4f3e9df80b%2Fcc-gg8-scan-3.png?alt=media)
2. To limit the query to a specific node, click **Select particular node** and pick the required node in the dialog that opens.
3. To limit the query to a specific partition, type its ID in the **Partition number** field.
4. To use regex filters, define **Key** and **Value** regular expressions.
5. Click **Execute**.

#### Miscellaneous Functions

* To export the query results to a CSV file, select the **Export to CSV** check box.
* Use the query tab's context menu to:
  * **Rename** the tab
  * **Remove** the tab
  * **Copy** the tab

## Queries Log

The **Queries log** tab displays all the tracked queries.

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

| Column       | Description                                                                                                                                                                                                             |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type         | <p>- <code>SCAN</code>, a scan query<br>- <code>SQL\_FIELDS</code>, an SQL query that is executed via JDBC/ODBC or via the SqlFieldsQuery API</p>                                                                       |
| Query        | The query text.                                                                                                                                                                                                         |
| Initiator ID | The originator of the query. Can be a client host and port (e.g., `jdbc-thin:127.0.0.1:58016`), a user name, a job name, or any other information identifying who initiated the query. Displays `N/A` if not available. |
| Reducer      | The reducer node.                                                                                                                                                                                                       |
| Schema       | The schema.                                                                                                                                                                                                             |
| Status       | The query status: Running, Finished, Canceled, Failed, or Unknown.                                                                                                                                                      |
| Start Time   | The time the query started.                                                                                                                                                                                             |
| Duration     | The duration of the query.                                                                                                                                                                                              |

{% hint style="info" %}
You can reduce the space the query table occupies on your disk using [Disk Space Optimizations](/docs/tools/enterprise/control-center/admin-guide/disk-space-optimization.md).
{% endhint %}

The **Filters** pane, on the right, enables you to granularly define what queries should be included in the list. The **Query type** field is a drop-down list where you can select a single specific type or **ALL** for all types to be included.

### Selecting Queries to Track

To reduce the Control Center load and the disk space occupied by the tracked queries, you can specify which of the running queries must be tracked. Only those queries you specify will be available for display in the **Queries log** tab.

To select queries to track:

1. Click **Configure queries log** in the top right corner of the tab.
2. In the **Configure queries log** dialog that opens, define the query parameters.

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

   For example, if you enter "500" in the **Duration** field, as shown above, only queries longer than 500 ms will be tracked. This includes those queries that are running (are in the Running status) when you save the configuration.
3. Click **Save**.

### Stopping Queries

You can stop a running query by pressing ⋮ and selecting **Kill query**.

## Query Statistics

The **Query statistics** tab displays statistics on the queries that have been executed in the cluster. The list includes the queries that where executed via Control Center and also via other tools.

The list is limited to the most recent 1000 queries.

The statistics include the following:

* how many times the query was executed
* how many times the query failed or succeeded
* what were the minimum and maximum execution time
* when the query was most recently executed

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

You can find the queries that match a specific text string by using the **Filters** field. Simply enter the text in the input field, and the list is filtered as you type.
