流量损失:学习重要的基数估计
Flow-Loss: Learning Cardinality Estimates That Matter
摘要:
以前的学习基数估计方法集中在改善平均估计误差,但并非所有估计都同样重要。由于学习的模型不可避免地会出错,因此目标应该是改进对优化器产生最大影响的估计。我们引入了一个新的损失函数,流量损失,明确优化更好的查询计划,近似优化器的成本模型和动态规划搜索算法与分析功能。Flow-Loss的核心是将查询优化简化为特定计划图上的流路由问题,其中路径对应于不同的查询计划。为了评估我们的方法,我们引入了基数估计基准,其中包含来自21个模板的超过16 K查询的子计划的真实基数,最多有15个连接。我们表明,在不同的架构和数据库中,使用Flow-Loss训练的模型提高了计划的成本(使用PostgreSQL成本模型)和查询运行时,尽管估计准确性比使用Q-Error训练的模型差。当测试集查询与训练查询紧密匹配时,两个模型都比PostgreSQL显著提高了性能,并且接近最佳性能(使用真基数)。然而,当对稍微不同的查询(例如,相似但不相同的查询模板),而流损失训练模型更好地概括了这种情况。例如,与Q-Error模型相比,Flow-Loss模型在不可见模板上的运行时间提高了1.5倍,尽管利用了相同的模型架构和训练数据。
英文摘要:
Previous approaches to learned cardinality estimation have focused on improving average estimation error, but not all estimates matter equally. Since learned models inevitably make mistakes, the goal should be to improve the estimates that make the biggest difference to an optimizer. We introduce a new loss function, Flow-Loss, that explicitly optimizes for better query plans by approximating the optimizer's cost model and dynamic programming search algorithm with analytical functions. At the heart of Flow-Loss is a reduction of query optimization to a flow routing problem on a certain plan graph in which paths correspond to different query plans. To evaluate our approach, we introduce the Cardinality Estimation Benchmark, which contains the ground truth cardinalities for sub-plans of over 16K queries from 21 templates with up to 15 joins. We show that across different architectures and databases, a model trained with Flow-Loss improves the cost of plans (using the PostgreSQL cost model) and query runtimes despite having worse estimation accuracy than a model trained with Q-Error. When the test set queries closely match the training queries, both models improve performance significantly over PostgreSQL and are close to the optimal performance (using true cardinalities). However, the Q-Error trained model degrades significantly when evaluated on queries that are slightly different (e.g., similar but not identical query templates), while the Flow-Loss trained model generalizes better to such situations. For example, the Flow-Loss model achieves up to 1.5x better runtimes on unseen templates compared to the Q-Error model, despite leveraging the same model architecture and training data.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。