Optimizer Hints
SQL optimizer hints in GridGain 9: hint block syntax, precedence rules, and the supported hints such as FORCE_INDEX, NO_INDEX, and ENFORCE_JOIN_ORDER.
The query optimizer tries to execute the fastest execution plan. However, you can know about the data design, application design or data distribution in your cluster better. SQL hints can help the optimizer to make optimizations more rationally or build execution plan faster.
Hints Format
SQL hints are defined by a special comment /*+ HINT */, referred to as a hint block. Spaces before and after the hint name are required. The hint block must be placed right after the SELECT keyword, or after a table name in the FROM clause for table-specific hints (USE_SECONDARY_STORAGE, FORCE_INDEX, NO_INDEX), where it is scoped to that table. Multiple hints can be specified in a single hint block, separated by commas.
Example:
SELECT /*+ NO_INDEX, DISABLE_DECORRELATION */ T1.* FROM TBL1 T1 WHERE T1.V1 = ? AND T1.V2 = ?Hint Parameters
Hint parameters, if required, are placed in brackets after the hint name and separated by commas.
The hint parameter can be quoted. Quoted parameters are case-sensitive. You cannot specify both the case-sensitive and case-insensitive parameters in the same hint.
Example:
SELECT /*+ FORCE_INDEX(TBL1_IDX2,TBL2_IDX1) */ T1.V1, T2.V1 FROM TBL1 T1, TBL2 T2 WHERE T1.V1 = T2.V1 AND T1.V2 > ? AND T2.V2 > ?;
SELECT /*+ FORCE_INDEX('TBL2_idx1') */ T1.V1, T2.V1 FROM TBL1 T1, TBL2 T2 WHERE T1.V1 = T2.V1 AND T1.V2 > ? AND T2.V2 > ?;Hints Errors
The optimizer tries to apply every hint and its parameters, if possible. But it skips the hint or hint parameters if:
The hint is not supported.
Required hint parameters are not passed.
Hint parameters have been passed, but the hint does not support parameters.
The hint parameter is incorrect or refers to a nonexistent object, such as a nonexistent index or table.
The current hints or current parameters are incompatible with the previous ones, such as forcing the use and disabling of the same index.
For example, if a FORCE_INDEX hint references an index that does not exist, the following error will be thrown:
Hint Precedence
When the same table-specific hint type applies to a table from more than one level of a query, the hint closest to the table wins. Same-type hints are overridden, not merged: two NO_INDEX(...) lists at different levels are not combined — the inner list replaces the outer one for the affected table.
NO_INDEX and FORCE_INDEX set on different levels can also override each other. This lets you, for example, disable indexes broadly with a SELECT-level NO_INDEX and then re-enable a specific index for one table by attaching FORCE_INDEX to that table in the FROM clause.
Example:
In the example above, tbl1 is scanned using idx_val1 because its FROM-clause FORCE_INDEX overrides the outer NO_INDEX. tbl2 has no FROM-clause hint, so it inherits the SELECT-level NO_INDEX and is scanned without an index.
Supported Hints
DISABLE_DECORRELATION
Disables optimizations related to subquery decorrelation. By default, the optimizer attempts to decorrelate correlated subqueries into joins for better performance. This hint prevents that optimization.
Parameters:
This hint has no parameters.
Examples:
ENFORCE_JOIN_ORDER
Disables commute joins and enforces the join order defined by the user in a query.
Parameters:
This hint has no parameters.
Examples:
EXPAND_DISTINCT_AGG
If specified, the optimizer will rewrite DISTINCT aggregates into GROUP BY subqueries.
Parameters:
This hint has no parameters.
Examples:
FORCE_INDEX
Forces index scan.
Parameters:
Single index name to force the use of that specific index.
Multiple index names. They can relate to different tables. The optimizer will use the specified indexes for scanning.
Examples:
NO_INDEX
Disables index scan.
Parameters:
Empty. Disables all indexes, forcing a table scan.
Single index name to disable that specific index.
Multiple index names. They can relate to different tables. The optimizer will avoid using the specified indexes.
Examples:
USE_SECONDARY_STORAGE
Forces the query to use secondary storage instead of primary storage. Secondary storage is used to store a separate copy of data.
Parameters:
This hint has no parameters.
Examples:
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

