Is there any good guides on queries that run on multiple servers but sometimes performance tanks i.e. the query plan joins big tables and then filter rather than filter & then join/expand. If I recompile the stored procedure it starts working again i.e. selects 900 rows & expand them rather than expanding 91 million rows from index in cluster & then filter based on index. Could always expand query with tons of hints & force order or subqueries to attempt to force it but feels wrong & cannot do every time I write a query.
A query can go from less than a second or seconds to hours based on query plans suddenly switching order & recompile usually fixes it temporarily, guide to troubleshoot such issues anywhere?
In this case the parameters should be the same since it's a night job - before partially blamed parameter sniffing.