You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT COUNT(1) FROM sys_notice
SELECT COUNT(1) FROM sys_operation_log WHERE 1 = 1
SELECT COUNT(1) FROM sys_dept WHERE 1 = 1
SELECT COUNT(1) FROM sys_login_log WHERE 1 = 1
SELECT COUNT(1) FROM sys_dict_type
SELECT COUNT(1) FROM sys_role
问题
从数据库查询日志中我们可以看到有很多统计全表行数的代码(多为执行分页查询前做的准备查询),如下所示
在InnoDB中不会缓存表的元数据,因此执行这样的语句会造成比较大的时间开销,而MyISAM则缓存有表的元数据,统计行数可以在很短的时间内完成。如果没有其它必须使用InnoDB的原因,建议修改表的存储引擎从而优化这类语句。
参考:https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_count
解决方法
修改表的存储引擎为MyISAM
The text was updated successfully, but these errors were encountered: