A recent line of works apply machine learning techniques to assist or rebuild cost-based query optimizers in DBMS. While exhibiting superiority in some benchmarks, their deficiencies, e.g., unstable performance, high training cost, and slow model updating, stem from the inherent hardness of predicting the cost or latency of execution plans using machine learning models. In this paper, we introduce a learning-to-rank query optimizer, called Lero, which builds on top of a native query optimizer and continuously learns to improve the optimization performance. The key observation is that the relative order or rank of plans, rather than the exact cost or latency, is sufficient for query optimization. Lero employs a pairwise approach to train a classifier to compare any two plans and tell which one is better. Such a binary classification task is much easier than the regression task to predict the cost or latency, in terms of model efficiency and accuracy. Rather than building a learned optimizer from scratch, Lero is designed to leverage decades of wisdom of databases and improve the native query optimizer. With its non-intrusive design, Lero can be implemented on top of any existing DBMS with minimal integration efforts. We implement Lero and demonstrate its outstanding performance using PostgreSQL. In our experiments, Lero achieves near optimal performance on several benchmarks. It reduces the plan execution time of the native optimizer in PostgreSQL by up to 70% and other learned query optimizers by up to 37%. Meanwhile, Lero continuously learns and automatically adapts to query workloads and changes in data.
翻译:近期一系列工作将机器学习技术应用于数据库管理系统的代价查询优化器,以辅助或重建其优化能力。尽管这些方法在某些基准测试中展现出优越性,但其存在的性能不稳定、训练成本高、模型更新缓慢等缺陷,根源在于使用机器学习模型预测执行计划的代价或延迟存在固有难度。本文提出一种基于学习排序的查询优化器Lero,该优化器构建于原生查询优化器之上,通过持续学习提升优化性能。核心观察在于:对于查询优化而言,计划的相对顺序或排名(而非精确代价或延迟)已足够。Lero采用成对方法训练分类器,比较任意两个计划并判断孰优孰劣。这种二分类任务在模型效率与准确性上,远优于预测代价或延迟的回归任务。Lero并非从零构建学习型优化器,而是旨在利用数据库领域数十年的智慧来增强原生优化器。其非侵入式设计使得Lero能够以最小集成代价部署于任意现有数据库管理系统之上。我们实现了Lero,并在PostgreSQL上验证了其卓越性能。实验表明,Lero在多个基准测试中接近最优性能:较之PostgreSQL原生优化器,计划执行时间最高降低70%;较之其他学习型查询优化器,最高降低37%。同时,Lero能持续学习并自动适应查询负载与数据变化。