Why it matters

CBO is one of the largest wins for Hive performance. On join-heavy queries, CBO with fresh stats can produce plans 10x faster than the fallback rule-based optimizer.

Advertisement

The architecture

CBO uses Calcite as its planner framework. Calcite explores alternative plans (join orders, join implementations, aggregation placements) and picks the lowest-cost.

Cost model considers I/O (bytes read), CPU (row processing), and network (shuffle bytes). Costs are estimated using stats.

Hive CBO inputsTable statsrow count + sizeColumn statsNDV + min/maxCalcite CBOpicks lowest-cost planFresh stats → good plans; missing stats → naive plans
CBO needs stats to make good decisions.
Advertisement

How it works end to end

Join reordering: CBO picks the order that minimizes intermediate result sizes. Small tables get joined first; large tables last.

Join strategy selection: CBO picks between broadcast (small side broadcast to every node), shuffle (both sides hashed by join key), and bucket join (aligned buckets, no shuffle).

Predicate pushdown: filters move as close to scans as possible, minimizing data processed by later operators.