Hi, everybody!We are ratifying a new server with SQL 2014 cluster. During the performance tests, something very strange happened. I have a routine made up of several SELECT, TABLE variables and CTE. Basically, what I'm running is:USE MASTERGOALTER DATABASE SET QVDSM3 COMPATIBILITY_LEVEL = 100 - on the second run, I trade for 120GOUSE QVDSM3goDECLARE nPeriodo = 201501 ...And I register the elapsed time. Then I change the compatibility and rerun the query.When I'm using a database with SQL 2008 compatibility at SQL 2014, the query takes zero seconds. But if I change the compatibility to 2014, the same routine takes about one minute to run. I thought it could be something in the structure of indexes or statistics, so I recreated all indexes and statistics on compatibility 2014. Even so, the query continues taking one minute to run.Among some modifications, by trial and error, I changed all TABLE variables for temporary tables. Thus, the routine time dropped to zero !!!In short, what I have in relation to time is:SQL 2008 compatibility: the routine takes zero seconds using TABLE variables or temporary tables.SQL 2014 compatibility: the routine takes 60 seconds using variables TABLE and zero seconds using temporary tables.The routine consists of:1.Vários SELECTS and CTE to load data into the TABLE variable or temporary tables.2.Cinco INSERT / SELECT using the BD tables and objects created in item 1.3.Três UPDATE / SELECT using the BD tables and objects created in item 1.Then passed to the maintenance plan, which is composed of 17 segments. I validei each of them, modifying the routine and using:1) Variable table in SQL 2008 and SQL 2014.2) Temporary table in SQL 2008 and SQL 2014.3) Variable table in a window and temporary table in another window, both in SQL 2008.4) Variable table in a window and temporary table in another window, both in SQL 2014.In all cases, the maintenance plan is always the same. The cost variance is minimal for each command, the maximum difference appeared between the cost was 5%, which would not justify a routine in SQL 2014 take 60 times more than itself in SQL 2008.I do not know whether it is appropriate to consider this case as a query bottleneck. As I mentioned, the wheel routine at zero seconds in SQL 2008. The problem is when I run the same routine in SQL 2014 where it takes more than a minute to bring the same result.My question is, because the use of TABLE variables in routine can leave it so long, when the use of temporary tables makes instant routine?
↧