This question already has an answer here:

I support a system called "dynamics ax" and sometimes my optimizer picks a good plan, drops it and then picks a bad plan (where the same code is been ran). users who usually wait for 10 seconds start waiting for 30 sec. sometimes i update statistics and it goes back to it's normal time and then in a couple of minutes it starts running slow. does anyone has idea on how i can resolve this??

marked as duplicate by Erik Darling, mustaccio, Michael Green, hot2use, Paul White Feb 11 at 12:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.