简体   繁体   English

Azure SQL传统基数估计无法像SQL Server 2016一样工作

[英]Azure SQL Legacy Cardinality Estimation Not Working Like SQL Server 2016

We have two identical databases (exact same data, structure etc.) one in Azure Sql (Premium 500 DTU) and the other on a VM on Azure running SQL Server 2016 SP1 (8 vcore, 64 GB RAM). 我们在Azure Sql(Premium 500 DTU)中有两个完全相同的数据库(完全相同的数据,结构等),另一个在运行SQL Server 2016 SP1(8 vcore,64 GB RAM)的Azure上的VM上。 We have a query that when run with "Legacy Cardinality Estimation" at the database level set to OFF results in a query execution time of about 4 minutes on both databases. 我们有一个查询,当在数据库级别上将“传统基数估计”设置为OFF时,这两个数据库的查询执行时间约为4分钟。

If we change the "Legacy Cardinality Estimation" to ON in both databases the VM running SQL Server 2016 SP1 will run the same query in 30 seconds while the Azure SQL database ends up with even worse performance and takes almost 7 minutes to execute. 如果我们将两个数据库中的“传统基数估计”都更改为“开”,则运行SQL Server 2016 SP1的VM将在30秒内运行相同的查询,而Azure SQL数据库的性能甚至会更差,并且将花费近7分钟的时间执行。

Re-writing the query at this point is not an option. 此时无法重新编写查询。 I am hoping someone can tell me how I can get Azure SQL to honor the "Legacy Cardinality Estimation" setting and give me similar performance to my SQL Server 2016 SP1 VM. 我希望有人可以告诉我如何获得Azure SQL以兑现“传统基数估计”设置,并为我提供与SQL Server 2016 SP1 VM类似的性能。

I did notice that on the SQL Server 2016 SP1 box the CPU's will spike high (90%+) when "Legacy Cardinality Estimation" is ON while in Azure SQL the DTU percentage never climbs higher then 25%. 我确实注意到,在“传统基数估计”为ON的情况下,在SQL Server 2016 SP1框中,CPU的峰值将达到高(90%+),而在Azure SQL中,DTU的百分比从未攀升到25%以上。

On Azure SQL Database set compatibility level to 110 to enable the old cardinality estimator. 在Azure SQL数据库上,将兼容性级别设置为110以启用旧的基数估计器。

ALTER DATABASE [YourDatabase] SET COMPATIBILITY_LEVEL = 110

At the query level, use below hint. 在查询级别,使用以下提示。

USE HINT ( 'FORCE_LEGACY_CARDINALITY_ESTIMATION')

For more information, please read here . 有关更多信息,请在此处阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM