I have a T-SQL stored procedure in SQL Server 2014 SP2 that takes 3x as long on the server as it does from my local environment.
I restored my local database to what was on the server, so schema and data are the same.
I'm a programmer, not really a DBA, so bear with me on this.
The execution plans seem the same until you look at the XML. On my local environment, a Stream Aggregate is used for one of the queries to make a distinct select, while on the server, it looks like a Sort is used with a hash.
It appears that the fact that the server has less processors than my (beast) local machine is contributing to the problem. Every query takes a little longer on the server. Could this be the reason that the sort/hash is chosen on the server instead of the Stream Aggregate?
Is there a way to force the Stream Aggregate?
Here is the SQL for the stored proc: http://pastebin.com/kkXM3Bsf
Here is the execution plan for my local environment: http://pastebin.com/0u7SHxnM
Here is the execution plan for the server: http://pastebin.com/9sE9DfM0