PlanetScale
PlanetScale logoPlanetScale · Feature trail

Vitess SQL Evaluation Engine

8 posts · Oct 2022 – Mar 2025

What this trail covers

Vitess's SQL evaluation engine has evolved from an AST-based interpreter to a high-performance bytecode virtual machine. This transition, driven by the need for greater efficiency and maintainability in handling complex SQL expressions across sharded environments, involved static typing of SQL expressions at compile time and the implementation of a specialized VM. The new VM offers significant performance gains while remaining easier to maintain than the previous Go interpreter. This post details a specific optimization within the query planner to push aggregation down to MySQL, reducing data fetched by VTGate and preventing OOM errors. The solution involves delaying the 'ordering under aggregation' rewriter until the 'split aggregation' phase, allowing aggregation to be pushed down under the join.

All PlanetScale trails