Join Operation Hints

Function

These hints specify the join method, which can be nested loop join, hash join, or merge join.

Syntax

[no] nestloop|hashjoin|mergejoin(table_list)

Parameter Description

  • no indicates that the specified hint will not be used for a join.

  • table_list specifies the tables to be joined. The values are the same as those of join_table_list but contain no parentheses.

For example:

no nestloop(t1 t2 t3): nestloop is not used for joining t1, t2, and t3. The three tables may be joined in either of the two ways: Join t2 and t3, and then t1; join t1 and t2, and then t3. This hint takes effect only for the last join. If necessary, you can hint other joins. For example, you can add no nestloop(t2 t3) to join t2 and t3 first and to forbid the use of nestloop.

Example

Hint the query plan in Example as follows:

explain
select /*+ nestloop(store_sales store_returns item) */ i_product_name product_name ...

nestloop is used for the last join between store_sales, store_returns, and item. The optimized plan is as follows:

Feedback
编组 3备份
    openGauss 2024-12-26 01:04:31
    cancel