Welcome to Trac @Blogizma,
Although you haven't posted the full SQL, the SQL you've posed is generated by wp_count_attachments()
, which did have some caching added in 6.1 via #55227. The part of the SQL query which hasn't been included is possibly the most relevant part, as it determines what about the query is expensive.
You can view the full SQL query by using SHOW FULL PROCESSLIST;
as a query or using the process manager and ensuring it has the "full query" option checked.
Some more details are needed to know what the problem is here though, does the site have a lot of posts? or uploads? How many are we talking? (10,000? 100,000?)
At first, it sounds like this might be caused by a plugin, and may be better resolved through the WordPress support forums unless a bug can be determined.