I am all with you with "this fixes rather symptom than the root cause". But this "fix" through index rebuild has plethora of drawbacks. What drawbacks? I am glad you ask:
- index rebuild is fully logged operation - your T-LOG and its backups (provided recovery model = full) grow
- if you have query plans in your execution plan cache on your SQL server and these plans touch the rebuilt indexes, they're marked for recompilation - hence new plan gets created
- while rebuild runs, you put additional I/O & CPU load on your server
- in case you aren't on SQL enterprise edition, you cannot rebuild WITH ONLINE, hence you can cause additional blocking
ad. 2) - this is where it might seem you "solved" the problem with index rebuild, but index rebuild could rather be consequence for better, more tailored execution plan for the problematic query/queries.
In case you run into slow server next time and you wanna confirmation that index fragmentation is not your root cause problem, you can choose plan B instead of index rebuild next time.
Plan B
If you have this emergency and wanna launch index rebuild, please, try DBCC FREEPROCCACHE instead, but use it scarcely (preferably just once to prove case). DBCC FREEPROCCACHE evicts every plan from your plan cache and you can have chance to get plans better tailored for the workload you currently have. If your emergency stops after giving SQL freeing the plan cache, then you proved index rebuild is not helping per-se, but rather causing similar effect as DBCC FREEPROCCACHE, but with DBCC FREEPROCCACHE, unlike index rebuild, you are not experiencing drawbacks 1-4 described above.
I, however, strongly advise against running DBCC FREEPROCCACHE often to "help" server. That is bad practice.
How to solve the problem in more sustainable fashion is rather out of scope of this post, but let me know should you be interested in more links covering this topic, please (or google search will do).
EDIT:In case you confirm, after all, that DBCC FREEPROCCACHE has the same effect as index rebuild (things suddenly start to go faster), then I dare to say you suffer from parameter sniffing. Erland Sommarskog has great article about that: Erland's page
Another supporting argument why not to launch index rebuild is to check how fragmented the indexes are in the first place. Great article with T-SQL to check the fragmentation: sqlshack
Also, for the sake of completeness, DBCC FREEPROCCACHE is not the only option how to evict execution plan(s) from cache and you can evict only 1 plan from cache if you have SQL plan handle. You also wipe part or whole plan cache by:
- failing over to another node if you are using clustering or always on availability groups
- running UPDATE STATISTICS (queries using the updated stats are also marked for recompilation after you update them)
- executing sp_recompile Microsoft docs
... to scrutinize execution plan cache, find the troublemaking queries and lots of details about them and get e.g. said plan handle, I would kindly direct you to first responder kit github repo link, namely its sp_blitzcache stored procedure.