
In the literature, there exists very little work on eliminating the
performance regression, especially on learned query optimizer [
46
].
[
21
] and [
18
] propose methods to enhance the robustness in dy-
namic settings by updating models in the proper time. They are
post-processing methods but do not detect and eliminate regression
before query execution. [
42
] tries to reduce the regression using
the ensemble methods [
4
,
13
,
19
,
36
,
39
], but it is time-consuming
and often falsely lters some truly good plans. As far as we know,
until now, this problem has not been well solved.
Our Contributions.
In this paper, we try to tackle this problem in
a novel way. Notably, the benets and risks of the learned models
always come together. Our goal is not to eliminate any possible
regression (which degenerates to the traditional query optimizer),
but to eliminate it to a low level while still attaining considerable
performance improvement. To this end, we design a system called
Eraser
, which can be deployed as an external plugin on top of any
existing learned query optimizer.
Eraser
can be tuned to eliminate
its performance regression while bringing minimal impact on its
performance benet.
The key to eliminate the performance regression is to identify
whether the predicted cost is accurate for each candidate plan. Based
on this, we can lter out all highly risky candidate plans but reserve
those with high prediction accuracy for plan selection. However,
learning the exact prediction accuracy is very challenging, which
is as dicult as learning the accurate cost of each plan [
11
,
14
,
20
,
26, 35]. In Eraser, we try to simplify the learning tasks while still
preserving enough knowledge for plan identication.
Specically,
Eraser
adopts a two-stage strategy for plan identi-
cation. The rst stage serves as a coarse-grained lter that qualita-
tively removes all highly risky plans. We observe that the prediction
models are very likely to perform worse on plans with feature values
not occurring in the training data, due to their low generalization
ability. These plans are called unexpected plans. To detect how the
model behaves w.r.t. each feature value, we design an unexpecte d
plan explorer to divide the unexpected plan space into a number of
subspaces, each with one or more unseen feature values. Then, we
generate plans in a small number of representative subspaces. Based
on the model evaluation results on these plans, we can classify all
subspaces into precise and imprecise. All candidate plans fall into
the imprecise subspace would be ltered.
In the second stage, we learn a segment model to process the
remaining plans in a more ne-grained manner. We observe that
the performance of the prediction model is highly skewed, since it is
under-tting for some plans. To this end, the segment model groups
plans into a number of clusters and associates each cluster with a
reliability interval reecting the quality of the estimation results.
Based on the reliability interval, we design a plan selection method
to balance the risk of regressions and the loss of benets. Both the
unexpected plan explorer and the segment model are lightweight.
Through comprehensive evaluations, we nd that when the
learned query optimizer performs worse, i.e., even 1
.
1
×
to 2
.
9
×
than the traditional query optimizer,
Eraser
can help to improve
its performance to be comparable with the traditional query op-
timizer. When the learned query optimizer performs better than
the traditional query optimizer,
Eraser
makes little inuence on
its performance.
Eraser
is adaptive to balance regression risks
and improvement impacts to attain the best overall performance
in both static and dynamic settings. Meanwhile,
Eraser
exhibits
good generality to dierent underlying learned query optimizers
in [
5
,
42
,
45
] and dierent DBMSes, i.e., PostgreSQL and Spark [
43
].
Our main contributions are summarized as follows:
1) We propose a general framework subsuming existing learned
query optimizers. Based on this, we rigorously dene the perfor-
mance regression elimination problem on the learned query opti-
mizer.
2) We design
Eraser
, a system that can be deployed on top of any
learned query optimizer to eliminate its performance regression
while preserving its performance benet.
3) We conduct extensive experiments to evaluate the perfor-
mance of Eraser in dierent settings.
2 PRELIMINARIES
In the traditional query optimizer, such as the one in PostgreSQL,
for any input SQL query
𝑄
, all candidate plans are often enumerated
using dynamic programming. Then, a basic cost model is applied for
plan selection. It relies on estimated cardinality, which is often gen-
erated by simple statistical methods such as histogram or sampling,
and experience-driven rules to predict the cost of each candidate
plan. Let
𝐶 (𝑃 )
and
b
𝐶 (𝑃 )
denote the exact and estimated cost of
query plan
𝑃
, respectively. The cost
𝐶 (𝑃 )
is a user-specied metric,
e.g., execution time or I/O throughput, regarding the eciency of
executing
𝑃
. Finally, the plan
𝑃
𝑏
with the minimum estimated cost
is returned for execution.
Recently, a number of learned query optimizers [
5
,
24
,
25
,
41
,
42
,
45
] are proposed to provide instance-level query optimization.
Their procedures can be generalized into a unied framework with
two main steps. For the input query
𝑄
, a learned query optimizer
rst generates a set of candidate plans
P
𝑄
= {𝑃
0
, 𝑃
1
, . . . , 𝑃
𝑘
}
using
some plan exploration strategies. Then, a learned risk model
𝑀
𝑟
,
i.e., a complex ML-based model, is applied for plan selection.
𝑀
𝑟
can predict the goodness of each plan in
P
𝑄
in terms of
𝐶 (𝑃 )
. The
best plan
𝑃
𝑟
∈ P
𝑄
minimizing
b
𝐶 (𝑃 )
is selected for execution. We
note that dierent learned query optimizers, including Neo [
25
],
Balsa [
41
], Bao [
24
], HyperQO [
42
], Lero [
45
], PerfGuard [
5
] and
some other works [
12
,
16
,
26
,
28
,
33
,
47
], apply dierent plan ex-
ploration strategies and risk models, but they can all be subsumed
under this framework. Due to space limits, we defer the details to
Appendix A in the full version [40].
Problem Statement.
The plan
𝑃
𝑟
selected by the above learned
query optimizer is often shown to have a better performance than
𝑃
𝑏
. However, it may suer a heavy performance regression on some
queries due to numerous reasons: 1) the candidate set
P
𝑄
does not
contain plans better than
𝑃
𝑏
; 2) the risk model can not generalize
well on new data/workload, especially in dynamic settings; and
3) the risk model is under-tting on the training data owing to
loss of features, noisy labels, insucient training data, bad hyper-
parameters or inappropriate training optimizers.
Let
Pr
𝑄
be the distribution of all SQL queries occurring for a data-
base. Let
Q
be a workload where each query
𝑄 ∈ Q
occurs with the
probability
Pr
𝑄
. Formally, a learned query optimizer learned
_
opt in
our framework generates an execution plan 𝑃
𝑟
for a query 𝑄 ∈ Q
𝑃
𝑟
← learned_opt(P
𝑄
, 𝑀
𝑟
)
927
评论