Help Center/
GaussDB/
Developer Guide(Distributed_3.x)/
SQL Optimization/
Hint-based Tuning/
AGG Hint
Updated on 2024-05-07 GMT+08:00
AGG Hint
Function
You can specify the AGG method when performing the AGG algorithm.
Syntax
use_hash_agg[(@queryblock)], use_sort_agg[(@queryblock)]
Parameter Description
- For details about @queryblock, see Hint Specifying the Query Block Where the Hint Is Located. @queryblock can be omitted, indicating that the hint takes effect in the current query block. If it is not specified, the hint does not have parentheses (()).
Example
- Use hash aggregation.
gaussdb=# explain (costs off) select c1 from t2 where c1 in( select /*+ use_hash_agg */ t1.c1 from t1,t3 where t1.c1=t3.c1 group by 1); QUERY PLAN ------------------------------------------------------ Streaming (type: GATHER) Node/s: All datanodes -> Hash Join Hash Cond: (t2.c1 = t1.c1) -> Seq Scan on t2 -> Hash -> HashAggregate Group By Key: t1.c1 -> Hash Join Hash Cond: (t1.c1 = t3.c1) -> Seq Scan on t1 -> Hash -> Seq Scan on t3 (13 rows)
- Use use_sort_agg for aggregation and then perform merge join.
gaussdb=# explain (costs off) select c1 from t2 where c1 in( select /*+ use_sort_agg */ t1.c1 from t1,t3 where t1.c1=t3.c1 group by 1); QUERY PLAN ------------------------------------------------------------ Streaming (type: GATHER) Node/s: All datanodes -> Hash Join Hash Cond: (t2.c1 = t1.c1) -> Seq Scan on t2 -> Hash -> Group Group By Key: t1.c1 -> Sort Sort Key: t1.c1 -> Hash Join Hash Cond: (t1.c1 = t3.c1) -> Seq Scan on t1 -> Hash -> Seq Scan on t3 (15 rows)
Parent topic: Hint-based Tuning
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot