Skip navigation links
Apache Calcite

Package org.apache.calcite.rel.hint

Defines hints interfaces and utilities for relational expressions.

See: Description

Package org.apache.calcite.rel.hint Description

Defines hints interfaces and utilities for relational expressions.

The Syntax

We support the Oracle style hint grammar for both query hint(right after the "SELECT" keyword) and the table hint(right after the table name reference). i.e.
   select /*+ NO_HASH_JOIN, RESOURCE(mem='128mb', parallelism='24') */
   from
     emp /*+ INDEX(idx1, idx2) */
     join
     dept /*+ PROPERTIES(k1='v1', k2='v2') */
     on emp.deptno=dept.deptno
 

Customize Hint Match Rules

Calcite implements a framework to define and propagate the hints. In order to make the hints propagate efficiently, every hint referenced in the sql statement needs to register the match rules for hints propagation.

A match rule is defined though HintPredicate. NodeTypeHintPredicate matches a relational expression by its node type; you can also define a custom instance with more complicated rules, i.e. JOIN with specified relations from the hint options.

Here is the code snippet to illustrate how to config the strategies:

       // Initialize a HintStrategyTable.
       HintStrategyTable strategies = HintStrategyTable.builder()
         .addHintStrategy("time_zone", HintPredicates.SET_VAR)
         .addHintStrategy("index", HintPredicates.TABLE_SCAN)
         .addHintStrategy("resource", HintPredicates.PROJECT)
         .addHintStrategy("use_hash_join",
             HintPredicates.and(HintPredicates.JOIN,
                 HintPredicates.explicit((hint, rel) -> {
                   ...
                 })))
         .hintStrategy("use_merge_join",
             HintStrategyTable.strategyBuilder(
                 HintPredicates.and(HintPredicates.JOIN, joinWithFixedTableName()))
                 .excludedRules(EnumerableRules.ENUMERABLE_JOIN_RULE).build())
         .build();
       // Config the strategies in the config.
       SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
         .withHintStrategyTable(strategies)
         .build();
       // Use the config to initialize the SqlToRelConverter.
   ...
 

Hints Propagation

There are two cases that need to consider the hints propagation:

Design Doc

Calcite SQL and Planner Hints Design.
Skip navigation links
Apache Calcite

Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.