TL;DR
This paper introduces a modular, pretrained deep learning representation for database query plans that splits query encoding into two distinct parts: query tree structure and operator computational performance. By decoupling these facets and pretraining on large, diverse workloads, the resulting representations transfer effectively to downstream database optimization tasks—such as query latency prediction and query template classification—requiring minimal fine-tuning data.
What Problem Does This Paper Address?
Modern smart database components (e.g., automated knob tuning, learned index recommendation, query optimizers) need a deep understanding of database workloads to achieve instance optimality. However, characterizing workloads is difficult because queries are largely independent, have diverse and variable-depth tree structures, and interact intricately with underlying data distributions and hardware configuration knobs. Prior machine learning approaches typically train end-to-end models on fixed features for a single specific task, requiring extensive data collection from scratch whenever the workload or database configuration changes.
Methods
The authors propose a bidirectional, transferrable query-plan encoder framework inspired by modern natural language processing models:
- Modular Representation: The query plan representation decouples structural topology from runtime execution features into two distinct encoders:
- Structure Encoder: Encodes the query plan tree. The plan is serialized using a depth-first traversal augmented with hierarchical brackets (
DFS-Bracket) to preserve tree topology, then embedded with tree-positional encodings. A multi-head self-attentive Transformer encoder maps this sequence into a plan-level structural vector $S(p_i)$. - Computational Performance Encoder: A collection of specialized operator-level encoders (for
Scan,Join,Sort, andAggregate). Each utilizes a multi-column Deep Neural Network (DNN) that takes three separate inputs: plan node features, database meta-features (cardinalities, distinct values, selectivity), and DBMS configuration knobs. Keeping these feature categories separate in the initial layers allows the model to learn within-feature correlations before fusing them. - Pretraining and Joint Learning:
- The structure encoder is pretrained on a plan-pair similarity regression task, predicting the structural graph overlap score (
Smatch). - The performance encoders are jointly trained on multiple database configurations to predict execution metrics (
Total Time,Total Cost,Startup Time), helping the model learn general performance characteristics and prevent overfitting. - Downstream Integration: Embeddings from both encoders, alongside database configuration knobs, feed into lightweight task-specific networks for downstream tasks.
Datasets
- Crowdsourced Plan Dataset: Over 63,000 plan pairs extracted from PostgreSQL explain-plan repositories (
explain.depesz.com), used for pretraining the structure encoder on the Smatch similarity task. - Industry Standard Benchmarks: Standard TPC-H and TPC-DS (at multiple scale factors, e.g., SF-1 to SF-100) run across diverse database configurations generated via Latin Hypercube Sampling.
- Spatial Benchmarks: Real-world geospatial workloads evaluated with PostGIS:
- Jackpine: Spatial queries involving polygon, line, and point joins.
- OpenStreetMap (OSM): Overlap, distance, and routing queries across New York and Los Angeles county datasets.
- Join Order Benchmark (JOB): 113 query templates clustered into 33 groups across ~16,200 plan executions under different configurations, used for query classification.
Key Insights and Ideas
- Decoupling Structure from Performance: Separate representation learning prevents topological features from being drowned out by high-magnitude numerical execution features (and vice-versa).
- Multi-Column Neural Networks Outperform Monolithic DNNs: For operator performance modeling, processing plan features, data distributions, and configuration knobs in separate columns before fusing them yields significantly lower errors than a single concatenated input vector.
- Rapid Domain Adaptation: Pretrained encoders capture general execution and structural behaviors such that fine-tuning on as little as 30% of a target workload's data matches or beats training a model from scratch on 100% of the target data.
- Operator Latency vs. Structure Importance: Latency prediction is heavily dominated by the computational performance encoder (yielding $5\times$ lower latency error than structure alone), whereas query classification relies predominantly on the structure encoder.
Key Results
- Query Latency Prediction:
- On the TPC-DS (SF-100) benchmark, the proposed plan encoder outperformed state-of-the-art predictors (including QPP Net, SVM, RBF, and TAM). Over 91% of query predictions fell within a $1.5\times$ relative error factor ($R \le 1.5$) of the ground truth, with 74% within a $1.25\times$ factor.
- On complex spatial workloads (Jackpine, OSM), 68% of query templates had a Mean Absolute Error (MAE) under 10% of the query's natural latency variance across configurations.
- Query Classification:
- On the Join Order Benchmark, combining the structure and performance encoders improved test F1-scores by 29% (to 0.2518) on template prediction and 21% (to 0.4647) on cluster prediction compared to using the structure encoder alone.
- Few-Shot Transferability: Pretrained operator encoders achieved convergence on unseen scale factors (e.g., TPC-DS SF-8) using only a 0.3 fraction of fine-tuning data, substantially outperforming scratch models trained on equal data.
Limitations and Future Work
- Outlier Templates: A small percentage of complex query templates suffered from higher prediction errors due to sensitive interactions with database metadata (such as partial indexing) and buffer configurations that were difficult to align cleanly across baselines.
- Plan Size Constraints: The structure encoder pruned queries containing more than 200 operator nodes during pretraining, leaving very large enterprise execution plans unaddressed.
- Operator Scope: Dedicated performance encoders were built only for the most frequent operators (
Scan,Join,Sort,Aggregate), lumping less common operators into a generic group. - Future Work: Integrating the learned plan encoders directly inside core DBMS engines for online tasks such as automated index selection, run-time query re-optimization, and automated knob recommendation.
Summary updated