Hint Type |
Description |
|---|---|
USE_HASH_AGGREGATION |
Forces the use of hash aggregation. Its reverse operation is NO_USE_HASH_AGGREGATION. |
NO_USE_HASH_AGGREGATION |
Avoids the use of hash aggregation. Its reverse operation is USE_HASH_AGGREGATION. |
GBY_PUSHDOWN |
Enables two-phase GROUP BY pushdown. Its reverse operation is NO_GBY_PUSHDOWN. |
NO_GBY_PUSHDOWN |
Disables two-phase GROUP BY pushdown. Its reverse operation is GBY_PUSHDOWN. |
DISABLE_OP_RICH_FORMAT |
In the plan, the physical operators specified in op_list are rolled back to vectorized 1.0. |
PQ_GBY |
Enforces the specified data distribution method for GROUP BY, and optionally specifies the degree of parallelism for aggregate operators during three-phase pushdown. |
USE_HASH_AGGREGATION Hint
The USE_HASH_AGGREGATION hint instructs the optimizer to force the use of the HASH aggregation algorithm when generating the execution plan for the SQL statement. It sets GROUP BY/DISTINCT to use HASH AGGREGATE, such as HASH GROUP BY and HASH DISTINCT. Its reverse operation is NO_USE_HASH_AGGREGATION.
Syntax
/*+USE_HASH_AGGREGATION([qb_name]) */
Example
-- Use the USE_HASH_AGGREGATION hint to force the query optimizer to use the hash aggregation algorithm for aggregate calculations.
-- In this query, this means that the sum of salaries after grouping by e.department_id will be calculated using a hash table.
SELECT /*+ USE_HASH_AGGREGATION */ e.department_id, sum(e.salary)
FROM employees e
WHERE e.department_id = 1001
GROUP BY e.department_id;
GROUP BY e.department_id;
## `NO_USE_HASH_AGGREGATION` Hint
The `NO_USE_HASH_AGGREGATION` hint instructs the optimizer to avoid using the hash aggregation algorithm when executing the SQL statement. It sets groupby/distinct to not use HASH AGGREGATE, but instead use MERGE GROUP BY and MERGE DISTINCT. Its reverse operation is `USE_HASH_AGGREGATION`.
### Syntax
```sql
/*+ NO_USE_HASH_AGGREGATION([qb_name]) */
Example
-- Use the NO_USE_HASH_AGGREGATION hint to instruct the query optimizer to avoid using hash aggregation algorithms.
-- The optimizer will choose another aggregation method, such as sorting aggregation, to compute the sum of salaries for the e.department_id group.
SELECT /*+ NO_USE_HASH_AGGREGATION */ e.department_id, sum(e.salary)
FROM employees e
WHERE e.department_id = 1001
GROUP BY e.department_id;
GROUP BY e.department_id;
## `GBY_PUSHDOWN` Hint
The `GBY_PUSHDOWN` hint instructs the optimizer to push the `GROUP BY` operation down to the data nodes in the distributed database when possible. This way, each node can perform grouping and aggregation on its local data and then send the results to a central node for final aggregation. Its reverse operation is `NO_GBY_PUSHDOWN`.
### Syntax
```sql
/*+ GBY_PUSHDOWN([qb_name]) */
Example
SELECT /*+ GBY_PUSHDOWN */ department_id, COUNT(*) as emp_count
FROM employees
GROUP BY department_id;
NO_GBY_PUSHDOWN Hint
The NO_GBY_PUSHDOWN hint is the opposite of the GBY_PUSHDOWN hint. It instructs the optimizer not to push the GROUP BY operation down to the data nodes but to perform the entire grouping and aggregation process at the central node. Its reverse operation is GBY_PUSHDOWN.
Syntax
/*+ NO_GBY_PUSHDOWN([qb_name]) */
Example
SELECT /*+ NO_GBY_PUSHDOWN */ department_id, COUNT(*) as emp_count
FROM employees
GROUP BY department_id;
PQ_GBY Hint
The PQ_GBY hint is used in parallel execution scenarios to force the optimizer to select a specified data distribution method for GROUP BY, and optionally specify the degree of parallelism (DOP) for aggregate operators during three-phase GROUP BY pushdown.
Syntax
/*+ PQ_GBY( [qb_name] distribute_method [, dop] ) */
Parameters
| Parameter | Description |
| qb_name | Optional. The query block name. If omitted, it applies to the current query block. |
| distribute_method | The data distribution method for GROUP BY. Valid values:
BASIC: uses the basic (non-parallel) form.NONE: partition-wise, without redistribution.HASH: HASH redistribution based on the grouping key.LOCAL: aggregates pulled to local nodes.HASH_LOCAL: HASH redistributes first, then aggregates locally.
GROUP BY pushdown. Commas can be omitted; PQ_GBY(HASH 4) is equivalent to PQ_GBY(HASH, 4). This value only participates in calculating the aggregate operator's DOP in auto-DOP scenarios. When the PARALLEL hint is explicitly specified in the statement, the DOP is determined by PARALLEL, and this parameter does not take effect. |
Examples
In the following example, table tbl1 is HASH-partitioned on column a. By default, GROUP BY a selects a partition-wise single-pass aggregation plan. Using PQ_GBY(HASH) forces the plan to use a two-pass aggregation with HASH redistribution based on column a.
CREATE TABLE tbl1 (id BIGINT, a INT NOT NULL, pad VARCHAR(50), PRIMARY KEY(id, a))
PARTITION BY HASH(a) PARTITIONS 8;
-- Default plan: Partition alignment, single-layer aggregation
EXPLAIN SELECT /*+ PARALLEL(4) */ a, count(*) FROM tbl1 GROUP BY a;
-- Forced HASH redistribution: The plan changes to EXCHANGE (HASH) with two layers of HASH GROUP BY.
EXPLAIN SELECT /*+ PARALLEL(4) PQ_GBY(HASH) */ a, count(*) FROM tbl1 GROUP BY a;
-- Specify dop at the same time: The comma can be omitted, and the two forms are equivalent.
EXPLAIN SELECT /*+ PARALLEL(4) PQ_GBY(HASH, 4) */ a, count(*) FROM tbl1 GROUP BY a;
EXPLAIN SELECT /*+ PARALLEL(4) PQ_GBY(HASH 4) */ a, count(*) FROM tbl1 GROUP BY a;
Note
This hint only changes the data distribution method for aggregation, not the aggregation algorithm (HASH aggregation or MERGE aggregation is controlled by hints like USE_HASH_AGGREGATION). For small datasets where the DOP does not take effect, or when the selected distribution method is not feasible, the plan may be the same as without the hint. You can confirm whether the hint was accepted via the Used Hint in the EXPLAIN EXTENDED output. The dop parameter only participates in calculating the aggregate operator's DOP in auto-DOP scenarios. When the PARALLEL hint is explicitly specified, the DOP is determined by PARALLEL.
The DISABLE_OP_RICH_FORMAT hint is used to roll back the physical operators specified in op_list to vectorized 1.0 in the plan.
Syntax
hint: disable_op_rich_format(op_list);
opt_list: op_name | op_list,op_name
op_name:
LIMIT
| MERGE_DISTINCT
| HASH_DISTINCT
| MATERIAL
| MERGE_JOIN
| GRANULE_ITERATOR
| EXPAND
| SORT
| HASH_UNION
| HASH_INTERSECT
| HASH_EXCEPT
| MERGE_UNION
| MERGE_INTERSECT
| MERGE_EXCEPT
| TABLE_SCAN
| HASH_JOIN
| NESTED_LOOP_JOIN
| SUBPLAN_FILTER
| SUBPLAN_SCAN
| UNPIVOT
| SCALAR_AGGREGATE
| MERGE_GROUP_BY
| HASH_GROUP_BY
| WINDOW_FUNCTION