Table-Level Hints

Supported variants of syntax:

hint_name([@query_block_name])
hint_name([@query_block_name] [tbl_name [, tbl_name] ...])
hint_name([tbl_name@query_block_name [, tbl_name@query_block_name] ...])

See Syntax of query-block and table level hints for more information.

BKA(), NO_BKA()

circle-info

Available from MariaDB 12.0.

Enable or disable batched key access join algorithm.

BNL(), NO_BNL()

circle-info

Available from MariaDB 12.0.

Enable or disable block nested-loop join algorithm.

These hints override the settings of system variables used to manage usage of block-based join algorithms.

Examples

SET join_cache_level = 2;
SELECT /*+ BKA(t13) */ * FROM t12, t13
  WHERE t12.a=t13.a AND (t13.b+1 <= t13.b+1);

join_cache_level = 2 limits the use of block-based join algorithms to flat or incremental BNL (BKA joins are not allowed). However, with the BKA(t13) hint tables t12 and t13 will be joined using the BKA hashed algorithm.

The same works in the opposite direction too. Say we have a very permissive setting join_cache_level = 8 that allows all block-based join algorithms. However, with the NO_BKA(t13) hint tables t12 and t13 will be joined using the BNL hashed algorithm.

These hints can be applied either to particular tables or to the whole query-block. When applied to particular tables, the hint body should mention tables that receive data from previous tables, i.e. which appear later in the join order. That means the hints in examples above will work if the optimizer joins tables t12 and t13 in that order. If the optimizer joins tables in the reverse order, the hints should mention t12 in their body instead.

DERIVED_CONDITION_PUSHDOWN(), NO_DERIVED_CONDITION_PUSHDOWN()

circle-info

Available from MariaDB 12.1.

These hints enable or disable the Condition Pushdown into Derived Table Optimization, effectively overriding the optimizer switch setting condition_pushdown_for_derived=[on|off]. They apply to derived tables, views and CTEs of the query.

Examples

Here the hint disables pushing conditions (max_c > 300 or max_c < 135) into the view v1.

In the next example the optimization is disabled by the optimizer switch setting, however the hint allows pushing conditions into the view v1 inside cte:

Example with pushing down conditions into a derived table:

MERGE(), NO_MERGE()

circle-info

Available from MariaDB 12.1.

These hints enable or disable the Derived Table Merge Optimization, effectively overriding the optimizer switch setting derived_merge=[on|off].

Examples

Let's say there is a statement:

By default the derived table dt gets merged into the main SELECT, so the output of EXPLAIN displays only one line.

However, if the user does not want dt to be merged, they can add NO_MERGE() hint:

Now the output displays two lines indicating that dt has not been merged but materialized instead. The same effect could be achieved by applying query-block level variant of the hint: /*+ NO_MERGE()*/ (however, the hint would affect not only dt but all other derived tables of the query block, if there were any).

The hints can be applied to CTE's too:

However, they do not have effect on merging of views.

SPLIT_MATERIALIZED(), NO_SPLIT_MATERIALIZED()

circle-info

Available from MariaDB 12.0.

These hints control the Split-materialized optimization also known as Lateral Derived optimization.

Let's look at the statement which will employ the lateral derived optimization by default:

select_type = LATERAL DERIVED at the bottom line of EXPLAIN output indicates the optimization has been applied.

If the user applies the hint, the optimization will be disabled and there will be no more LATERAL DERIVED in the output:

As with other hints, users can use SPLIT_MATERIALIZED() to force the optimization when it is not chosen by the cost-based optimizer or disabled by default ( optimizer_switch='split_materialized=off' ).

Last updated

Was this helpful?