Sql-server – Problem with database migrated from SQL Server 2005 to SQL Server 2014

sql serverstored-procedurest-sql

First of all I want to apologize for my English, I hope you understand me correctly.

I have a database migrated from a SQL Server 2005 in a SQL Server 2014.
Well, in addition, I have a .NET process that uses ODBC connectors to execute stored procedures in the database.

My problem is that this process lasts 20 minutes against SQL Server 2005, and against the migrated database in SQL Server 2014 it takes 8 hours.
After many tests, if the level of compatibility of the database to SQL Server 2008, the process takes only 8 minutes.

Any idea of ​​the reason? What problems can I have when lowering the compatibility level?

Best Answer

Any idea of ​​the reason? What problems can I have when lowering the compatibility level?

SQL 2014 made substantial changes to the "Cardinality Estimator" in the query optimizer. For applications that were built and optimized using the older behavior, you may see a performance regression.

The workaround you selected of using the lower database compatibility level is fine. You can also use a Trace Flag 9481 to force the legacy cardinality estimator on newer database compatibility levels.

Eventually you should analyze and optimize the queries and indexes under the new cardinality estimator.

See, eg: SQL Server 2014’s new cardinality estimator (Part 1)