arXiv:2610.28270cs.DBOct 2026

Manuscript Offprint

arXiv:2610.28270

SWatcher+: A Holistic Approach to Deploying Learned Cardinality Estimators in a Dynamic Setting

Yuxi Liu, Vincent Capol, Xiao Hu, Pankaj K. Agarwal, Jun Yang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Yuxi Liu

yuxi.liu@duke.edu

Duke University

Durham, NC, USA

Vincent Capol

vincent.capol@duke.edu

Duke University

Durham, NC, USA

Xiao Hu

xiaohu@uwaterloo.ca

University of Waterloo

Waterloo, Ontario, Canada

Pankaj K. Agarwal

pankaj@cs.duke.edu

Duke University

Durham, NC, USA

Abstract

Cardinality estimation (CE) is crucial in database query optimization. Although recent advances have improved accuracy, deploying machine-learned CE models in dynamic databases remains challenging due to data updates and workload shifts. Retraining can be costly, but existing practices offer little guidance on when and how to update models, resulting in simple periodic retaining strategies that are suboptimal. We propose SWatcher+, a framework that adapts learned CE to dynamic workloads by monitoring data updates and query feedback. SWatcher+ selectively monitors high-impact subqueries for which wrong estimates lead to poor plan performance, and it proactively applies corrections to estimates during query optimization. This strategy enables immediate adaptation to data and workload shifts without waiting for full model retraining, and carefully balances the cost and benefit of monitoring and adaptation versus retraining. Our experiments show that SWatcher+ offers a better trade-off between query performance and overhead compared with existing approaches, making it a more practical solution for deploying learned CE in dynamic settings.

ACM Reference Format:

Yuxi Liu, Vincent Capol, Xiao Hu, Pankaj K. Agarwal, and Jun Yang. 2018. SWatcher+: A Holistic Approach to Deploying Learned Cardinality Estimators in a Dynamic Setting. In Proceedings of Make sure to enter the correct conference title from your rights confirmation email (Conference acronym 'XX). ACM, New York, NY, USA, 15 pages. https://doi.org/XXXXXXX.XXXXXXX

1 Introduction

Most database query optimizers rely heavily on cardinality estimation (CE) to generate query plans. Recent advances in learned CE [9, 28–30, 35–37, 41, 42, 54, 56], where a machine learning model is trained on the database instance and/or query execution feedback, show promise in improving CE accuracy. However, deploying learned CE remains challenging, because dynamic database

Jun Yang

junyang@cs.duke.edu

Duke University

Durham, NC, USA

changes can render models inadequate. Since fine-grained incremental model updates can be expensive, most learned models try to stay up to date by retraining or, if applicable, fine-tuning (e.g., for deep learning [48, 56]). When to schedule costly refreshes, however, is unclear. A popular approach is periodic refresh [6, 23, 24, 27, 56]. The period can be defined in terms of time or the number of data updates since the last refresh, but guidance on how to set such periods is often lacking. There is a need to develop a smarter framework for deploying learned CE in a dynamic setting.

This paper explores several ideas to address this challenge. The first idea is monitoring. We would like to monitor both data updates and query feedback for clues to refresh the model. Ignoring data updates makes us too reactive—we will miss cases when data has changed significantly but not enough queries have witnessed the effect. On the other hand, ignoring the query workload may cause unnecessary refreshes—often, parts of the database are rarely queried, so refreshing the model in response to changes to these parts will not improve query performance. The second idea is estimation correction. Instead of using information collected from data updates and query feedback to refresh the CE model, which can be costly, we can use it to correct estimates by an outdated model. This idea has been tried by LEO [45] years before the advent of modern learned CE models: LEO remembers any estimation errors in excess of 5% and uses them to correct future estimates. There is no need to wait until the next refresh to benefit from the corrections.

However, combining these ideas into an effective solution that delivers practical, end-to-end gains is not trivial. We approach the problem of deploying learned CE in a dynamic setting holistically. Instead of focusing narrowly on improving CE accuracy, we look at the ultimate impact of model estimates on query performance, as well as the overall operational cost, including the overhead of monitoring, refresh, and correction. First, monitoring incurs overhead, but its benefit is not always clear. Many CE errors may not actually impact plan quality [20]. Second, correcting CE errors for some subqueries (e.g., only single-table selections) may sometimes lead to worse plans. This counterintuitive effect has been noted in [20] and confirmed in our experiments. Finally, retraining the CE model does not guarantee more accurate estimates where accuracy actually matters. Overall, deploying learned CE in a dynamic setting requires a delicate balancing act between benefit and cost.

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.

Conference acronym 'XX, Woodstock, NY

© 2018 Copyright held by the owner/author(s). Publication rights licensed to ACM. ACM ISBN 978-1-4503-XXXX-X/2018/06 https://doi.org/XXXXXXX.XXXXXXX

Liu et al.

Contributions. Going beyond the basic ideas of monitoring and correction, we propose SWatcher+. “+” represents the idea of increasing the benefit of monitoring by using monitored information proactively, to correct model estimates during optimization, without waiting for model refresh. “S” in SWatcher+ is the idea of making monitoring and correction selective based on their benefit, to reduce overhead. We only monitor the cardinalities of subqueries for which correction is expected to tangibly affect plan performance.

Importantly, noting that correcting selection cardinalities alone may have little (or even negative) impact, we also monitor information about joins. We show that while exact single-table selection cardinalities can be maintained efficiently, maintaining exact cardinalities of join subqueries is not cost-effective. Instead, we only cache recent compensating correction factors for join subqueries. Though less accurate, such information is cheaply available even for joins involving more than two tables, and it helps avoid the pitfall of applying only selection corrections.

Lastly, SWatcher+ triggers a model refresh by detecting when it is watching too many “correction-worthy” cardinalities, rather than detecting a high aggregate CE error. This policy allows SWatcher+ to cap data update processing time and realize when the model is making too many consequential mistakes.

SWatcher+ is also designed to be generally applicable, without being tied to any particular learned CE model or database system. We have experimented with using to SWatcher+ to deploy three different CE models—MSCN [18], JGMP [41], and Naru [56]—with PostgreSQL, and holistically compared its benefits and costs against competing deployment strategies. The results demonstrate that SWatcher+, with a fixed configuration and minimal parameter tuning, delivers superior end-to-end performance.

• Comparing SWatcher+ with the popular practice of periodic refresh, with MSCN as the model, SWatcher+ achieves 44.3–101.4% of the end-to-end running time of periodic refresh, outperforming it in 14 out of the 16 query templates, even when the refresh period is configured optimally post hoc. With JGMP and Naru, SWatcher+ achieves 56.1–99.5% and 87.84–98.84% (resp.) of periodic refresh's end-to-end running time, beating it consistently.

• SWatcher+’s selective monitoring and correction strategy readily beats simpler monitoring and correction strategies, including our best-effort implementation of LEO’s strategy [45].

• SWatcher+’s method of maintaining compensating correction factors for join subqueries instead of exact cardinalities is effective in taming the overhead while delivering query performance gains, even for complex queries involving multi-table joins.

• SWatcher+ naturally adapts its behavior to the workload: for complex OLAP-style queries, it monitors and corrects more for bigger improvements in query performance; for simple OLTP-style queries with little room for improvement, it automatically scales back on monitoring and correction to avoid overhead.

References (19)