I have a very simple query that I'm trying to optimize. issues_notes is a simple table, and meta_users is a table on a remote database server that I view with a view.
when I run a query without an order, it returns immediately, but when I add ORDER BY date , it takes about 4 seconds to return. I have SQL Server showing the execution plan, and it seems that slowness is introduced in the Table Spool operation, which occurs only when connected. Is there a way to prevent this βoptimizationβ?
Query:
SELECT [issues_notes].[date], [meta_users].[firstname], [meta_users].[lastname], [issues_notes].[note] FROM [issues_notes] LEFT JOIN [issues_issue] ON ([issues_notes].[issue_id] = [issues_issue].[id]) LEFT OUTER JOIN [meta_users] ON ([issues_notes].[author_id] = [meta_users].[userid]) WHERE ([issues_issue].[issue_hash] = '%s' )
Execution plan without order By:

Execution plan with order:

source share