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). 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.
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.
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.
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%.