Optimizing aggregation in the Vitess query planner
Jul 22, 2024Andres Taylor

Summary
This post details a specific optimization within the Vitess query planner to address an issue where aggregation was not being pushed down to MySQL, leading to excessive data fetching by VTGate and potential OOM errors. The optimization involves strategically delaying the 'ordering under aggregation' rewriter until the 'split aggregation' phase. This allows the aggregation to be pushed down under the join, with only the SUM of SUMs being handled at the VTGate level. The post illustrates the initial plan, the problematic intermediate plan, and the final optimized plan, highlighting the importance of tree rewriting phases in query planning.