Symptoms
When you query a view in Microsoft SQL Server 2014 or 2016, it might take much longer time to complete if you compare it to the execution in SQL Server 2008 R2.
When you execute a query that uses UNION ALL and a row goal (such as TOP N clause, FAST N, or EXISTS predicate), you may notice that the query runs slower in SQL Server 2014 or later versions if you compare it to SQL Server 2008 R2.
Cause
In SQL Server 2008 R2, the Query Optimizer changes the order of different parts under UNION ALL if a row goal is present, so that the cheapest part goes first. This allows the query to finish execution earlier if the cheaper parts produce required number of rows, without continuing to execute more expensive parts. Such reordering does not occur in later versions of SQL Server.
Resolution
This issue is fixed in the following cumulative update for SQL Server:
Cumulative Update 7 for SQL Server 2016 RTM
Cumulative Update 4 for SQL Server 2016 SP1
Cumulative Update 6 for SQL Server 2014 SP2
Note The Query Optimiser must be enabled for this issue.
For more information about query optimizer and trace flags, refer to the following links:
Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server:
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
References
Learn about the terminologythat Microsoft uses to describe software updates.