SQL Performance Tips
Ways to improve GridGain 9 SQL performance: batching statements, avoiding slow correlated subqueries, timing requests in the CLI, and dropping cached plans.
Query Batching
GridGain handles batched requests faster than individual requests, so we recommend using multi-statement execution when possible.
When executing multiple queries in a single call, similar requests are automatically batched together. When writing large scripts that perform multiple different kinds of operations, we recommend the following order:
All required DDL operations;
Assigning access permissions;
Loading data into the tables.
As execution of each statement is considered complete when the first page is ready to be returned, when working with large data sets, SELECT statements may be affected by later statements in the same script.
Performance Consideration For Correlated Subqueries
GridGain supports correlated subqueries, but the performance of certain complex correlated subqueries may be insufficient, especially when used in high-volume transactional or analytical workloads.
What Are Correlated Subqueries
A correlated subquery is a subquery that depends on values from the outer query for execution. It is evaluated once for every row of the outer query.
For example, for a schema that is defined in the following way:
CREATE TABLE projects (id INT PRIMARY KEY, name VARCHAR);
CREATE TABLE employees (id INT PRIMARY KEY, department_id INT, name VARCHAR, salary DECIMAl);
CREATE TABLE departments (id INT PRIMARY KEY, name VARCHAR);
CREATE TABLE assignments (project_id INT, employee_id INT, PRIMARY KEY (project_id, employee_id));The correlated subquery may look like this:
Here, the subquery references e.id from the outer query, meaning it's re-evaluated for every employee row, leading to N separate subquery executions for N employees.
Performance Impact
In GridGain 9, repeated subquery executions are not automatically optimized. As a result:
Scalar subqueries may become bottlenecks.
Even small tables can cause high CPU and memory consumption when repeatedly queried.
Certain queries may perform slower than expected.
Improving Performance
In general, highly-selective outer queries with cheap scalar subqueries (like single-row index lookup) will perform just fine. Here is an example:
Similar query but without predicate may result in lower performance. If the query with predicate finishes in 0.007s, similar query without predicate could take up to 2.4s.
Here is another example:
Query like the one above may easily be rewritten with regular JOIN:
Rewritten query on the same environment finishes significantly faster.
Examples of Improved Queries
The first example shows how you can correctly query the database without evaluating each row:
This example demonstrates drastic performance improvement you can gain by improving your queries:
Timing SQL Requests
When working on SQL queries, it may be important to check execution times on the client. You can use the CLI tool to execute timed queries. Depending on how you execute your queries, the behavior is slightly different:
When starting the interactive mode, each request sent will be timed.
When executing a script, all script commands will be executed and the total script execution will be timed.
Dropping Cached Plans
As optimizing the query plan is a resource-intensive operation, GridGain caches the plan and reuses it for subsequent related queries. As data is updated, the plan may be outdated and require recalculation. By default, the plans expire after the period specified in the ignite.planner.planCacheExpiresAfterSeconds parameter (1800 seconds by default).
To force the update earlier, you can use the sql planner invalidate-cache CLI tool command.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

