SELECT keyword in the form of a /*+ ... */ comment. Separate multiple Hints with spaces or commas. An example is as follows:SELECT /*+ [hint_text] [hint_text] ... */ * FROM ...;
@sel_1, @sel_2. For example, consider the following SQL:SELECT * FROM (SELECT * FROM t) t1, (SELECT * FROM t) t2;
SELECT statement, is named sel_1. The two SELECT subqueries are named sel_2 and sel_3 respectively, with the numbers increasing sequentially. Within a Hint, you can use QB_NAME to control the Hint's scope and target. If a QB_NAME is not explicitly specified in a Hint, the Hint's scope is the Query Block where the Hint itself resides. An example is as follows:SELECT /*+ HASH_JOIN_PROBE(@sel_2 t1) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;SELECT /*+ HASH_JOIN_PROBE(t1@sel_2) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;
@QB_NAME is appended after the parameters to specify the scope of the Hint.Term | Syntax | Description |
SHUFFLE_JOIN | SHUFFLE_JOIN([@QB_NAME] tbl1_name, tbl2_name ...) | Specifies that the JOIN operation uses the Shuffle method to distribute data. |
BROADCAST_JOIN | BROADCAST_JOIN([@QB_NAME] tbl1_name, tbl2_name ...) | Specifies that the JOIN operation uses the Broadcast method to distribute data. |
HASH_JOIN_BUILD | HASH_JOIN_BUILD([@QB_NAME] tbl1_name, tbl2_name ...) | Specifies the Build-side table in a Hash Join operation. |
HASH_JOIN_PROBE | HASH_JOIN_PROBE([@QB_NAME] tbl1_name, tbl2_name ...) | Specifies the Probe-side table in a Hash Join operation. |
LEADING | LEADING([@QB_NAME] tbl1_name, tbl2_name ...) | Specifies the join Order for JOIN operations. |
SET_VAR | SET_VAR(setting_name = value) | Temporarily modifies system variables at the SQL level. |
PX_JOIN_FILTER_ID / NO_PX_JOIN_FILTER_ID | PX_JOIN_FILTER_ID(rf_id1, rf_id2 ...) NO_PX_JOIN_FILTER_ID(rf_id1, rf_id2 ...) | Controls enabling/disabling the Runtime Filter. |
SHUFFLE_JOIN(t1_name, t2_name ...) controls the columnar read-only analysis engine optimizer to use the Shuffle Join algorithm when JOIN operations are executed: it shuffles and redistributes data from the left and right tables based on the JOIN key before the JOIN is performed.EXPLAIN SELECT /*+ SHUFFLE_JOIN(t1) */ * FROM t1, t2 WHERE t1.id = t2.id;
t1 and t2, and the SHUFFLE_JOIN hint specifies Shuffle Join as the data distribution method. The final execution plan is shown in the figure below. In Details, the EXCHANGE TYPE on lines 2 and 5 changes to HASH, indicating that Hash Shuffle is used.
EXPLAIN SELECT /*+ SHUFFLE_JOIN((t1@sel_2, t2@sel_2)) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;
t1 and t2 in parentheses and specify a QB_NAME for each table. This allows you to specify that the JOIN intermediate result of t1 and t2 uses Shuffle Join when it is joined with t3.
BROADCAST_JOIN(t1_name, t2_name ...) controls the columnar read-only analysis engine optimizer to use the Broadcast Join algorithm when JOIN operations are executed: it broadcasts data from the specified tables to all computing nodes before the JOIN is performed.EXPLAIN SELECT /*+ BROADCAST_JOIN(t1) */ * FROM t1, t2 WHERE t1.id = t2.id;
t1 and t2, and the BROADCAST_JOIN hint specifies Broadcast Join as the JOIN method. The final execution plan is shown in the figure below. In Details, the EXCHANGE TYPE on lines 2 and 5 changes to BCJ, indicating that Broadcast is used.
EXPLAIN SELECT /*+ BROADCAST_JOIN((t1@sel_2, t3@sel_1)) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;
t1 and t3 in parentheses and specify a QB_NAME for each table. This allows you to specify that the JOIN intermediate result of t1 and t3 uses Broadcast Join when it is joined with the outer table. The result is shown in the figure below.
HASH_JOIN_BUILD.HASH_JOIN_BUILD(t1_name, t2_name ...) controls the columnar read-only analysis engine optimizer to use the Hash Join algorithm for the specified tables and to designate those tables as the Build side of the Hash Join, meaning they are used to build the hash table.EXPLAIN SELECT /*+ HASH_JOIN_BUILD(t2) */ * FROM t t1, t t2 WHERE t1.a = t2.a;
t2 table as the Build side of the Hash Join. The final execution plan is shown in the figure below.
EXPLAIN SELECT /*+ HASH_JOIN_BUILD((t1@sel_2, t3@sel_1)) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;

HASH_JOIN_PROBE(t1_name, t2_name ...) controls the columnar read-only analysis engine optimizer to use the Hash Join algorithm for the specified tables and to designate those tables as the Probe side of the Hash Join, meaning they are used to probe the hash table.EXPLAIN SELECT /*+ HASH_JOIN_PROBE(t2) */ * FROM t t1, t t2 WHERE t1.a = t2.a;
t2 table is designated as the Probe side of the Hash Join. The final execution plan is shown in the figure below.
EXPLAIN SELECT /*+ HASH_JOIN_PROBE((t1@sel_2, t3@sel_1)) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;

LEADING(t1_name, t2_name ...) controls the join order (Join Order) generated by the columnar read-only analysis engine optimizer during the Join Reorder stage. The optimizer determines the Join Order according to the sequence specified in LEADING.EXPLAIN SELECT /*+ LEADING(t1, t3, t2, t4) */ * FROM t1, t2, t3, t4 WHERE t1.a = t2.a AND t2.a = t3.a AND t3.a = t4.a;
LEADING hint explicitly specifies that the t1 table first JOINs with the t3 table, then with the t2 table, and finally with the t4 table. The final execution plan is shown in the figure below.
LEADING, which can generate a Bushy Tree through bracket nesting. An example is provided below:EXPLAIN SELECT /*+ LEADING((t1, t3), (t2, t4)) */ * FROM t1, t2, t3, t4 WHERE t1.a = t2.a AND t2.a = t3.a AND t3.a = t4.a;
LEADING hint uses (t1, t3) to instruct the optimizer to first JOIN t1 with t3, uses (t2, t4) to instruct the optimizer to first JOIN t2 with t4, and finally uses ((t1, t3), (t2, t4)) to instruct the optimizer to JOIN the results of the two preceding JOINs. The final execution plan is shown in the figure below.
LEADING hints exist in the same query, the hints become ineffective.LEADING, the Hint becomes ineffective.SET_VAR(setting_name = value) is used to temporarily modify a system variable during SQL execution. After the SQL execution completes, the modified system variable automatically reverts to its original value. The usage is as follows:SELECT /*+ SET_VAR(max_threads = 64) */ * FROM t1;
SET_VAR Hint.SET_VAR Hint. Before using it, confirm that the target system variable has Hint modification enabled. For a list of system variables that support modification via Hint, see System Variables.PX_JOIN_FILTER_ID(rf_id1, rf_id2 ...) and NO_PX_JOIN_FILTER_ID(rf_id1, rf_id2 ...) are used to control the enabling and disabling of Runtime Filters with specified IDs by the optimizer.-c (that is, --comments) option when starting the client. For example:mysql -h 127.0.0.1 -P 4000 -u root -c
SELECT /*+ SHUFFLE_JOIN(t1) */ * FROM test1.t1, test2.t2 WHERE t1.id = t2.id;
t1 table is not in the current database and the Hint does not specify a database name, the Hint becomes ineffective. The Warning message is as follows:tdsql> SHOW WARNINGS;+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+| Level | Code | Message |+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+| Warning | 1815 | There are no matching table names for (t1) in optimizer hint /*+ SHUFFLE_JOIN(t1) */ or /*+ SHUFFLE_JOIN(t1) */. Maybe you can use the table alias name |+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
SELECT /*+ HASH_JOIN_PROBE(t2) */ * FROM (SELECT t1.a, t1.b FROM t t1, t t2 WHERE t1.a = t2.a) t1, t t3 WHERE t1.b = t3.b;
t2 table in the Hint, the Hint does not take effect. The Warning message is as follows:tdsql> SHOW WARNINGS;+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+| Level | Code | Message |+---------+------+---------------------------------------------------------------------------------------------------------------------------------+| Warning | 1815 | There are no matching table names for (t2) in optimizer hint /*+ HASH_JOIN_PROBE(t2) */. Maybe you can use the table alias name |+---------+------+---------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
EXPLAIN to view the SQL execution plan and confirm the QB_NAME of the Query Block where each table resides.
SELECT). Otherwise, it will not take effect. For example:tdsql> SELECT * /*+ SET_VAR(max_threads = 64) */ FROM t;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use line 1 column 42 near "/*+ SET_VAR(max_threads = 64) */ FROM t"
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários