On Microsoft SQL Server 2019, there is a lot of long temp tables TRUNCATE operations with time over 5..10 seconds. Easy query like "TRUNCATE TABLE #tt22" can take over 15 seconds. It's an intermittent problem, sometimes it disappears for a day after restarting the server . What could be the reason?
UPD: According to the latest performance measurements, long TRUNCATE operations are observed not only in temporary tables, but also in physical ones.
sp_WhoIsActive
in case there are other clues. Also, next time you notice the problem, you should runsp_WhoIsActive
multiple times in a row (10+) to see if you catch any other wait types for theTRUNCATE
query, or if every time it's the same wait type ofSOS_SCHEDULER_YIELD
. (Some queries have multiple things they're waiting on.)