# Piece of CAKE: Adaptive Execution Engines via Microsecond-Scale Learning

arXiv: https://arxiv.org/abs/2602.04181 · HTML: https://mlsanity.com/paper/2602.04181/

## Key facts

- No citing papers in the map yet (data through 14 Oct 2026).
- Builds on 21 of its 74 references that are in the map.
- First posted on arXiv 4 Feb 2026.

## Builds on (most cited first, 21 of 21)

- [Proximal Policy Optimization Algorithms](https://mlsanity.com/paper/1707.06347/) (2017)
- [The Case for Learned Index Structures](https://mlsanity.com/paper/1712.01208/) (2017)
- [Neo: A Learned Query Optimizer](https://mlsanity.com/paper/1904.03711/) (2019)
- [Evaluating the Performance of Reinforcement Learning Algorithms](https://mlsanity.com/paper/2006.16958/) (2020)
- [A Survey on Contextual Multi-armed Bandits](https://mlsanity.com/paper/1508.03326/) (2015)
- [Lero: A Learning-to-Rank Query Optimizer](https://mlsanity.com/paper/2302.06873/) (2023)
- [Tsunami: A Learned Multi-dimensional Index for Correlated Data and Skewed Workloads](https://mlsanity.com/paper/2006.13282/) (2020)
- [SkinnerDB: Regret-Bounded Query Evaluation via Reinforcement Learning](https://mlsanity.com/paper/1901.05152/) (2019)
- [Deep Contextual Multi-armed Bandits](https://mlsanity.com/paper/1807.09809/) (2018)
- [The Three Pillars of Machine Programming](https://mlsanity.com/paper/1803.07244/) (2018)
- [Revisiting Bellman Errors for Offline Model Selection](https://mlsanity.com/paper/2302.00141/) (2023)
- [WiSeDB: A Learning-based Workload Management Advisor for Cloud Databases](https://mlsanity.com/paper/1601.08221/) (2016)
- [Cuttlefish: A Lightweight Primitive for Adaptive Query Processing](https://mlsanity.com/paper/1802.09180/) (2018)
- [SEFRQO: A Self-Evolving Fine-Tuned RAG-Based Query Optimizer](https://mlsanity.com/paper/2508.17556/) (2025)
- [Buffer Pool Aware Query Scheduling via Deep Reinforcement Learning](https://mlsanity.com/paper/2007.10568/) (2020)
- [HERO: Hint-Based Efficient and Reliable Query Optimizer](https://mlsanity.com/paper/2412.02372/) (2024)
- [Generating Custom Code for Efficient Query Execution on Heterogeneous Processors](https://mlsanity.com/paper/1709.00700/) (2017)
- [Database-Agnostic Workload Management](https://mlsanity.com/paper/1808.08355/) (2018)
- [How I Learned to Stop Worrying and Love Re-optimization](https://mlsanity.com/paper/1902.08291/) (2019)
- [Debunking the Myth of Join Ordering: Toward Robust SQL Analytics](https://mlsanity.com/paper/2502.15181/) (2025)
- [Enabling Incremental Query Re-Optimization](https://mlsanity.com/paper/1409.6288/) (2014)

## Abstract (arXiv)

Low-level database operators often admit multiple physical implementations ("kernels") that are semantically equivalent but have vastly different performance characteristics depending on the input data distribution. Existing database systems typically rely on static heuristics or worst-case optimal defaults to select these kernels, often missing significant performance opportunities. In this work, we propose CAKE (Counterfactual Adaptive Kernel Execution), a system that learns to select the optimal kernel for each data "morsel" using a microsecond-scale contextual multi-armed bandit. CAKE circumvents the high latency of traditional reinforcement learning by exploiting the cheapness of counterfactuals -- selectively running multiple kernels to obtain full feedback -- and compiling policies into low-latency regret trees. Experimentally, we show that CAKE can reduce end-to-end workload latency by up to 2x compared to state-of-the-art static heuristics.
