Index-Level Hints
Overview
These hints follow the syntax of index-level hints which includes two variants:
hint_name(table_name [index_name [, index_name] ...])
hint_name(table_name@query_block [index_name [, index_name] ...])They enable or disable the specified indexes for index scans for specific operations. The following rules apply:
for enabling (or whitelisting) hints (
GROUP_INDEX,JOIN_INDEX,INDEX,ORDER_INDEX):if the hint body includes only a table name and no index names, the optimizer is free to choose any applicable index of that table;
if the body includes both a table name and one or more index names, the optimizer will only consider the specified indexes for that table;
for disabling (or blacklisting) hints (
NO_GROUP_INDEX,NO_JOIN_INDEX,NO_INDEX,NO_ORDER_INDEX):if the hint body includes only a table name and no index names, the optimizer will not use any indexes for that table;
if the body includes both a table name and one or more index names, the optimizer will not use the specified indexes for that table but can use any other not listed.
GROUP_INDEX(), NO_GROUP_INDEX()
GROUP_INDEX(), NO_GROUP_INDEX() These hints are available from MariaDB 12.1.
These hints enable or disable the specified indexes for index scans for GROUP BY operations but do not affect other operations: access to table data and sorting. Equivalent to old-style hints FORCE INDEX FOR GROUP BY and IGNORE INDEX FOR GROUP BY.
Examples
JOIN_INDEX(), NO_JOIN_INDEX()
JOIN_INDEX(), NO_JOIN_INDEX()These hints are available from MariaDB 12.1.
Enable or disable the specified indexes for an access method (range, ref, etc.). Equivalent to old-style hints FORCE INDEX FOR JOIN and IGNORE INDEX FOR JOIN.
Example
INDEX(), NO_INDEX()
INDEX(), NO_INDEX()These hints are available from MariaDB 12.1.
Enable or disable the specified indexes for all scopes (access to table data, grouping and sorting). Equivalent to old-style hints FORCE INDEX and IGNORE INDEX.
Examples
ORDER_INDEX(), NO_ORDER_INDEX()
ORDER_INDEX(), NO_ORDER_INDEX()These hints are available from MariaDB 12.1.
These hints enable or disable the specified indexes for sorting rows but do not affect other operations: access to table data and grouping. Equivalent to old-style hints FORCE INDEX FOR ORDER BY and IGNORE INDEX FOR ORDER BY.
Example
Combining Multiple Index Hints
Multiple index hints can be combined in a single query unless they conflict with each other. For example:
Here the hints do not conflict with each other because they target different operations.
A conflict may happen when the same class of hints is applied to a single table, for example:
or when an umbrella hint INDEX/NO_INDEX is specified:
Here the warning will be generated:
because INDEX hint is essentially a combination of JOIN_INDEX|GROUP_INDEX|ORDER_INDEX.
If a single SQL query includes both old-style and new-style index hints, old-style hints are silently ignored, for example:
New-style INDEX(t1 i_a) has effect while old-style IGNORE INDEX(i_a) does not.
INDEX_MERGE(), NO_INDEX_MERGE()
INDEX_MERGE(), NO_INDEX_MERGE()This hint is available from MariaDB 12.2.
The INDEX_MERGE and NO_INDEX_MERGE optimizer hints provide granular control over the optimizer's use of index merge strategies. They allow users to override the optimizer's cost-based calculations and global switch settings, to force or prevent the merging of indexes for specific tables.
Syntax
Behavior
The hints operate by modifying the set of keys the optimizer considers for merge operations. The specific behavior depends on whether specific index keys are provided within the hint.
INDEX_MERGE Hint
This hint instructs the optimizer to employ an index merge strategy.
Without arguments: When specified as
INDEX_MERGE(tbl), the optimizer considers all available keys for that table and selects the cheapest index merge combination.With specific keys: When specified with keys, for instance,
INDEX_MERGE(tbl key1, key2), the optimizer considers only the listed keys for the merge operation. All other keys are excluded from consideration for index merging.The
INDEX_MERGEhint overrides the global optimizer_switch. Even if a specific strategy (such as index_merge_intersection) is disabled globally, the hint forces the optimizer to attempt the strategy using the specified keys.
NO_INDEX_MERGE Hint
This hint instructs the optimizer to avoid index merge strategies.
Without arguments: When specified as
NO_INDEX_MERGE(tbl), index merge optimizations are completely disabled for the specified table.With specific keys: When specified with keys, for instance,
NO_INDEX_MERGE(tbl key1), the listed keys are excluded from consideration. The optimizer may still perform a merge using other available keys. However, if excluding the listed keys leaves insufficient row-ordered retrieval (ROR) scans available, no merge is performed.
Algorithm Selection and Limitations
While these hints control which keys are candidates for merging, they do not directly dictate the specific merge algorithm (Intersection, Union, or Sort-Union).
Indirect Control: You can influence the strategy indirectly by combining these hints with optimizer_switch settings, but specific algorithm selection is not guaranteed.
Invalid Hints: If a hint directs the optimizer to use specific indexes, but those indexes do not provide sufficient ROR scans to form a valid plan, the server is unable to honor the hint. In this scenario, the server emits a warning.
Examples
In the following examples, the index_merge_intersection switch is globally disabled. However, the INDEX_MERGE hint forces the optimizer to consider specific keys (f2 and f4), resulting in an intersection strategy.
You can see that we disable intersection with NO_INDEX_MERGE for the following query and the behavior reflects in the EXPLAIN output. The query after that shows with the hint enabling merge–an intersection of f3,f4 is used. In the last example, a different intersection is used: f3,PRIMARY.
No intersection (no merged indexes):
Intersection of keys f3, f4:
Intersection of keys PRIMARY, f3:
NO_ICP()
NO_ICP()This hint is available from MariaDB 12.0.
Disables Index Condition Pushdown for a specified table or a subset of its indexes. Effectively overrides the optimizer_switch setting index_condition_pushdown=on.
Examples
NO_RANGE_OPTIMIZATION()
NO_RANGE_OPTIMIZATION()This hint is available from MariaDB 12.0.
An index-level hint that disables range optimization for certain index(es) or a whole table. There is no corresponding optimizer switch setting for this optimization.
Examples
MRR(), NO_MRR()
MRR(), NO_MRR()These hints are available from MariaDB 12.0.
These hints allow to control the multi-range read optimization, effectively overriding the optimizer switch setting mrr=[on|off].
Examples
ROWID_FILTER(), NO_ROWID_FILTER()
ROWID_FILTER(), NO_ROWID_FILTER()These hints are available from MariaDB 12.1.
Allows to control the ROWID filter optimization. Effectively they override the optimizer switch setting rowid_filter=[on|off].
Rules for
ROWID_FILTER()hint:if the hint body includes only a table name and no index names, the optimizer is free to choose any indexes applicable for rowid-filtering optimization;
if the body includes both a table name and one or more index names, the optimizer will only consider the specified indexes for rowid-filtering;
the hint forces the use of rowid-filtering (if applicable) despite being less efficient than not using the optimization (from the optimizer's point of view);
Rules for
NO_ROWID_FILTER()hint:if the hint body includes only a table name and no index names, the optimizer will not use any indexes for rowid-filtering;
if the body includes both a table name and one or more index names, the optimizer will not use the specified indexes for rowid-filtering but can use any other not listed.
Examples
Interaction with Other Index Hints
If [NO_]INDEX(), [NO_]JOIN_INDEX() hints are specified for the same table, then only indexes whitelisted by INDEX() or JOIN_INDEX() can be considered for rowid filters. ROWID_FILTER( hint cannot force the use of indexes that are disabled by NO_INDEX() / NO_JOIN_INDEX() or omitted from INDEX() / JOIN_INDEX(). For example, if one index should be used for data access and another for a rowid filter, the filter index must be mentioned in both hints:
Last updated
Was this helpful?

