Show Processlist state "Statistics" Please note that it's not a duplicate thread because I already set variable optimizer_search_depth and didn't have any impact.

Sometimes, our database/application services crashed due to max connection limit. When we see show processlist output we found lot of sessions in the "statistics" state. Our system immediately get normal if we kill these connections. We are not running any DDL/optimize/stats-update related commands during that period. We are using 5.7.12 on Linux Centos 7.5 

How can I find the source of these sessions?
This can be related to Bug 83912. If you run SHOW ENGINE INNODB STATUS you may see transactions like this:


  ---TRANSACTION 4216198446592, not started sleeping before entering InnoDB


In order to fix it:

SET GLOBAL innodb_thread_concurrency=0;