Mysql – How to optimize information schema table in thesql

MySQLoptimization

When I checked slow running queries log, I found out that

select count(*) into @discard from information_schema.PARTITIONS;

This query is taking 6 seconds to execute (a bit higher for this execution). I am not really sure about usage of this query and would look advise on optimizing it.

Best Answer

Information Schema is not like other databases:

They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.

source - https://dev.mysql.com/doc/refman/5.7/en/information-schema.html

and not a lot of ways for optimise queries over it there are few recommendations (very standard for any queries)

https://dev.mysql.com/doc/refman/5.7/en/information-schema-optimization.html

recommendations is really standard and in Your case - with count(*) not help.