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.
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.
This issue is fixed in the following cumulative update for SQL Server:
Note The Query Optimiser must be enabled for this issue.
For more information about query optimizer and trace flags, refer to the following links:
Article ID: 4023419 - Last Review: 2017, ഓഗ 8 - Revision: 8