Stage: Query Execution Time Prediction in Amazon Redshift

Ziniu Wu, Ryan Marcus, Zhengchun Liu, Parimarjan Negi, Vikram Nathan, Pascal Pfeil, Gaurav Saxena, Mohammad Rahman, Balakrishnan Narayanaswamy, Tim Kraska

Abstract

Accurate query execution time prediction is critical for workload management, resource scaling, and query optimization in cloud data warehouses. However, existing approaches often face a trade-off between prediction accuracy and inference overhead. This paper presents Stage, a three-tiered hierarchical system developed for Amazon Redshift. By combining an execution time cache, a local Bayesian ensemble of XGBoost models, and a global Graph Convolutional Network (GCN), Stage achieves high accuracy while maintaining sub-millisecond average inference latency. Evaluation on 30 million real-world queries demonstrates a 20% improvement in average query latency and a 2x increase in prediction accuracy compared to previous production systems.

Introduction

In cloud data warehouses like Amazon Redshift, predicting how long a query will take to run is fundamental to maintaining system performance. Accurate predictions allow the system to intelligently route queries to appropriate queues (Workload Management), determine when to scale compute resources, and decide whether to automate the creation of materialized views.

Despite its importance, query prediction is notoriously difficult. Advanced machine learning models can be highly accurate but often introduce significant inference overhead—sometimes exceeding the execution time of the query itself. Conversely, simpler models are fast but struggle with "cold starts" on new database instances or shifting workloads. In their SIGMOD '24 paper, researchers from MIT, UPenn, and Amazon Web Services introduce Stage, a novel hierarchical system designed to navigate these trade-offs by routing queries through a multi-tiered prediction pipeline.

The Stage Architecture

The core innovation of Stage is its hierarchical structure, which acts as a series of filters to balance speed and complexity. The system consists of three distinct layers:

1. Execution-Time Cache

Approximately 60% of queries in Amazon Redshift are exact repeats. Stage first checks a high-speed cache for the query's signature. If the query has been executed recently, the system returns the previous execution time. This layer provides near-zero overhead for a majority of the workload.

2. Local Model (The "Fuzzy Cache")

When a query misses the cache, it is passed to a local model trained specifically on that database instance. This layer utilizes a Bayesian ensemble of 10 lightweight XGBoost models. Beyond providing a prediction, the ensemble generates an uncertainty measurement. If the local model is confident in its prediction, the result is used immediately. This layer effectively acts as a "fuzzy cache," capturing slight variations in queries that a standard hash-based cache would miss.

3. Global Model (The Expert)

If the local model reports high uncertainty—common during "cold starts" of new instances or for entirely new query types—Stage invokes a heavy-duty Graph Convolutional Network (GCN). The GCN treats the query's physical execution plan as a tree structure, allowing it to perform "zero-shot" predictions. By leveraging patterns learned from the broader Redshift fleet, the GCN can accurately predict execution times for instances it has never encountered before.

Methodology and Datasets

The Stage system was evaluated using massive, real-world datasets consisting of roughly 30 million queries. These logs were collected from the top 100 most-billed Redshift instances across three major AWS regions: us-east-1, us-west-2, and eu-west-1.

The global model was trained on a diverse subset of hundreds of instances, each containing over 10,000 queries. This ensured the model was exposed to a wide variety of schemas, data distributions, and complex workloads, enabling its robust zero-shot capabilities.

Key Insights

  • Uncertainty as a Router: The use of Bayesian uncertainty is the "glue" of the system. It allows Stage to safely delegate difficult queries to the expensive global model without penalizing the latency of simpler, more common queries.
  • Local vs. Global Data: A significant finding was that local models (trained only on a specific customer's data) often outperformed the global model for that specific instance. This suggests that instance-specific nuances—such as specific schema designs and data distributions—are often more predictive than sheer global data volume.
  • Efficiency at Scale: By triggering the expensive GCN for only approximately 3% of queries, Stage maintains a sub-millisecond average inference latency across the entire fleet.

Results

In production simulations, Stage demonstrated significant improvements over the previous AutoWLM (Automated Workload Management) predictor:

  • Latency: Average query execution latency improved by 20%.
  • Accuracy: Stage achieved a median absolute error of 0.67 seconds, making it more than 2x as accurate as the prior XGBoost-only approach.
  • Overhead: The hierarchical routing ensured that the high accuracy of deep learning did not come at the cost of system responsiveness.

Limitations and Future Work

While Stage represents a significant leap forward, the researchers identified several areas for improvement. Currently, the model primarily analyzes the query plan and does not fully account for real-time environmental noise, such as CPU or memory contention caused by concurrent workloads. Additionally, predicting "long-running" queries (those exceeding 60 seconds) remains a challenge due to data sparsity, as these queries represent only 1% of the total dataset.

Future iterations of Stage aim to integrate real-time system telemetry—such as buffer pool states and concurrent query counts—to further refine predictions in high-variance environments.

Summary updated

BibTeX
@inproceedings{wu2024stage,
  author = {Ziniu Wu and Ryan Marcus and Zhengchun Liu and Parimarjan Negi and Vikram Nathan and Pascal Pfeil and Gaurav Saxena and Mohammad Rahman and Balakrishnan Narayanaswamy and Tim Kraska},
  title = {{Stage: Query Execution Time Prediction in Amazon Redshift}},
  booktitle = {SIGMOD Conference Companion},
  year = {2024},
  doi = {10.1145/3626246.3653391},
}
Figure