最近RDS FOR MYSQL5.6的统计信息有问题,一些表明明的数据,但统计信息里去显示为空表,导致执行计划出错,查询效率很低,所以查看下相关的信息。

-- 查看服务器系统变量,实际上使用的变量的值
show variables like '%innodb_stats_auto_recalc%';
-- 查看服务器状态变量,运行服务器的统计和状态指标
show status like '%Uptime%'; -- MySQL服务器已经运行的秒数
-- 刷新参数
flush status; -- 查看当前和打开过的表
show global status like 'open%_tables'; -- 清空表缓存
flush tables; -- 重启innodb_stats_auto_recalc
set @innodb_stats_auto_recalc=OFF;
set @innodb_stats_auto_recalc=ON;
MySQL [database_name]> select count(1) as cnt from database_name.dw_std_yf_roomtype_position;
+---------+
| cnt |
+---------+
| 1247196 |
+---------+
1 row in set (0.20 sec) MySQL [database_name]> select * from mysql.innodb_table_stats where table_name='dw_std_yf_roomtype_position';
+---------------------+-----------------------------+---------------------+--------+----------------------+--------------------------+
| database_name | table_name | last_update | n_rows | clustered_index_size | sum_of_other_index_sizes |
+---------------------+-----------------------------+---------------------+--------+----------------------+--------------------------+
| database_name | dw_std_yf_roomtype_position | 2019-08-01 02:07:24 | 0 | 1 | 3 |
+---------------------+-----------------------------+---------------------+--------+----------------------+--------------------------+
1 row in set (0.09 sec) MySQL [database_name]> select * from information_schema.tables where table_schema = 'database_name' and table_name = 'dw_std_yf_roomtype_position';
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | BLOCK_FORMAT |
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
| def | database_name | dw_std_yf_roomtype_position | BASE TABLE | InnoDB | 10 | Compact | 0 | 0 | 16384 | 0 | 49152 | 4194304 | NULL | 2018-01-25 16:55:06 | NULL | NULL | utf8_general_ci | NULL | | 801002002017_户型的检查部位 | Original |
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
1 row in set (0.00 sec) MySQL [database_name]> ANALYZE table database_name.dw_std_yf_roomtype_position;
+-------------------------------------------------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+-------------------------------------------------+---------+----------+----------+
| database_name.dw_std_yf_roomtype_position | analyze | status | OK |
+-------------------------------------------------+---------+----------+----------+
1 row in set (0.07 sec) MySQL [database_name]> select * from mysql.innodb_table_stats where table_name='dw_std_yf_roomtype_position';
+---------------------+-----------------------------+---------------------+---------+----------------------+--------------------------+
| database_name | table_name | last_update | n_rows | clustered_index_size | sum_of_other_index_sizes |
+---------------------+-----------------------------+---------------------+---------+----------------------+--------------------------+
| database_name | dw_std_yf_roomtype_position | 2019-08-01 10:56:02 | 1157429 | 32640 | 40192 |
+---------------------+-----------------------------+---------------------+---------+----------------------+--------------------------+
1 row in set (0.10 sec) MySQL [database_name]> select * from information_schema.tables where table_schema = 'database_name' and table_name = 'dw_std_yf_roomtype_position';
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | BLOCK_FORMAT |
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
| def | database_name | dw_std_yf_roomtype_position | BASE TABLE | InnoDB | 10 | Compact | 1157429 | 462 | 534773760 | 0 | 658505728 | 4194304 | NULL | 2018-01-25 16:55:06 | NULL | NULL | utf8_general_ci | NULL | | 801002002017_户型的检查部位 | Original |
+---------------+---------------------+-----------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+------------------------------------+--------------+
1 row in set (0.00 sec) MySQL [database_name]> show index from database_name.dw_std_yf_roomtype_position;
+-----------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible |
+-----------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| dw_std_yf_roomtype_position | 0 | PRIMARY | 1 | id | A | 1157429 | NULL | NULL | | BTREE | | | YES |
| dw_std_yf_roomtype_position | 0 | PRIMARY | 2 | db_name | A | 1157429 | NULL | NULL | | BTREE | | | YES |
| dw_std_yf_roomtype_position | 1 | ix_position_id | 1 | position_id | A | 52610 | NULL | NULL | YES | BTREE | | | YES |
| dw_std_yf_roomtype_position | 1 | ix_tenant_roomtype | 1 | roomtype_id | A | 289357 | NULL | NULL | YES | BTREE | | | YES |
| dw_std_yf_roomtype_position | 1 | ix_tenant_roomtype | 2 | db_name | A | 289357 | NULL | NULL | | BTREE | | | YES |
| dw_std_yf_roomtype_position | 1 | ix_tenant_position | 1 | db_name | A | 12580 | NULL | NULL | | BTREE | | | YES |
| dw_std_yf_roomtype_position | 1 | ix_tenant_position | 2 | position_id | A | 44516 | NULL | NULL | YES | BTREE | | | YES |
+-----------------------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ MySQL [database_name]> select * from mysql.innodb_index_stats where database_name='database_name' and table_name='dw_std_yf_roomtype_position';
+---------------------+-----------------------------+--------------------+---------------------+--------------+------------+-------------+-----------------------------------+
| database_name | table_name | index_name | last_update | stat_name | stat_value | sample_size | stat_description |
+---------------------+-----------------------------+--------------------+---------------------+--------------+------------+-------------+-----------------------------------+
| database_name | dw_std_yf_roomtype_position | PRIMARY | 2019-08-01 10:56:02 | n_diff_pfx01 | 1095171 | 20 | id |
| database_name | dw_std_yf_roomtype_position | PRIMARY | 2019-08-01 10:56:02 | n_diff_pfx02 | 1157429 | 20 | id,db_name |
| database_name | dw_std_yf_roomtype_position | PRIMARY | 2019-08-01 10:56:02 | n_leaf_pages | 28299 | NULL | Number of leaf pages in the index |
| database_name | dw_std_yf_roomtype_position | PRIMARY | 2019-08-01 10:56:02 | size | 32640 | NULL | Number of pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_position_id | 2019-08-01 10:56:02 | n_diff_pfx01 | 25448 | 20 | position_id |
| database_name | dw_std_yf_roomtype_position | ix_position_id | 2019-08-01 10:56:02 | n_diff_pfx02 | 1345353 | 20 | position_id,id |
| database_name | dw_std_yf_roomtype_position | ix_position_id | 2019-08-01 10:56:02 | n_diff_pfx03 | 1239445 | 20 | position_id,id,db_name |
| database_name | dw_std_yf_roomtype_position | ix_position_id | 2019-08-01 10:56:02 | n_leaf_pages | 10486 | NULL | Number of leaf pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_position_id | 2019-08-01 10:56:02 | size | 12160 | NULL | Number of pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_tenant_position | 2019-08-01 10:56:02 | n_diff_pfx01 | 6263 | 20 | db_name |
| database_name | dw_std_yf_roomtype_position | ix_tenant_position | 2019-08-01 10:56:02 | n_diff_pfx02 | 21960 | 20 | db_name,position_id |
| database_name | dw_std_yf_roomtype_position | ix_tenant_position | 2019-08-01 10:56:02 | n_diff_pfx03 | 1369816 | 20 | db_name,position_id,id |
| database_name | dw_std_yf_roomtype_position | ix_tenant_position | 2019-08-01 10:56:02 | n_leaf_pages | 10311 | NULL | Number of leaf pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_tenant_position | 2019-08-01 10:56:02 | size | 11968 | NULL | Number of pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_tenant_roomtype | 2019-08-01 10:56:02 | n_diff_pfx01 | 131679 | 20 | roomtype_id |
| database_name | dw_std_yf_roomtype_position | ix_tenant_roomtype | 2019-08-01 10:56:02 | n_diff_pfx02 | 125442 | 20 | roomtype_id,db_name |
| database_name | dw_std_yf_roomtype_position | ix_tenant_roomtype | 2019-08-01 10:56:02 | n_diff_pfx03 | 1591935 | 20 | roomtype_id,db_name,id |
| database_name | dw_std_yf_roomtype_position | ix_tenant_roomtype | 2019-08-01 10:56:02 | n_leaf_pages | 13861 | NULL | Number of leaf pages in the index |
| database_name | dw_std_yf_roomtype_position | ix_tenant_roomtype | 2019-08-01 10:56:02 | size | 16064 | NULL | Number of pages in the index |
+---------------------+-----------------------------+--------------------+---------------------+--------------+------------+-------------+-----------------------------------+

ref: https://www.cnblogs.com/zengkefu/p/5634858.html
ref: https://www.cnblogs.com/justfortaste/p/3276363.html

mysql统计信息相关的更多相关文章

  1. MySQL统计信息简介

    作者:王小龙@网易乐得DBA 原文地址: http://mp.weixin.qq.com/s/698g5lm9CWqbU0B_p0nLMw MySQL执行SQL会经过SQL解析和查询优化的过程,解析器 ...

  2. MySQL统计信息以及执行计划预估方式初探

    数据库中的统计信息在不同(精确)程度上描述了表中数据的分布情况,执行计划通过统计信息获取符合查询条件的数据大小(行数),来指导执行计划的生成.在以Oracle和SQLServer为代表的商业数据库,和 ...

  3. MySQL 统计信息

    200 ? "200px" : this.width)!important;} --> 介绍 数据库维护统计信息的目的主要是为了优化器进行更好的执行优化,首先统计信息是建立在 ...

  4. MySQL索引统计信息更新相关的参数

    MySQL统计信息相关的参数: 1. innodb_stats_on_metadata(是否自动更新统计信息),MySQL 5.7中默认为关闭状态 仅在统计信息配置为非持久化的时候生效. 也就是说在i ...

  5. MySQL 8.0 中统计信息直方图的尝试

    直方图是表上某个字段在按照一定百分比和规律采样后的数据分布的一种描述,最重要的作用之一就是根据查询条件,预估符合条件的数据量,为sql执行计划的生成提供重要的依据在MySQL 8.0之前的版本中,My ...

  6. MySQL InnoDB配置统计信息

    MySQL InnoDB配置统计信息 1. 配置持久化(Persistent)统计信息参数 1.1 配置自动触发更新统计信息参数 1.2 配置每张表的统计参数 1.3 配置InnoDB优化器统计信息的 ...

  7. MySQL的统计信息学习总结

    统计信息概念 MySQL统计信息是指数据库通过采样.统计出来的表.索引的相关信息,例如,表的记录数.聚集索引page个数.字段的Cardinality.....MySQL在生成执行计划时,需要根据索引 ...

  8. innodb索引统计信息

    以下分析基于mysql5.6.10 统计信息相关字典表 information_schema.statistics mysql.innodb_table_stats mysql.innodb_inde ...

  9. mysql-5.7 持久化统计信息详解

    一.持久化统计信息的意义: 统计信息用于指导mysql生成执行计划,执行计划的准确与否直接影响到SQL的执行效率:如果mysql一重启 之前的统计信息就没有了,那么当SQL语句来临时,那么mysql就 ...

随机推荐

  1. day38 09-Spring类的完整生命周期及后处理Bean

    可以配置Bean的这个类的初始化和销毁的方法. 如何销毁这个bean?销毁必须得手动地关闭掉容器才行.而且销毁必须是在scope="singleton"下才有效.因为如果你scop ...

  2. mybatis添加数据返回主键

    程序结构图: 表结构: 创表sql: Create Table CREATE TABLE `users` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `us ...

  3. Django项目:CRM(客户关系管理系统)--04--02PerfectCRM创建ADMIN页面02

    十.CRM项目创建模板页面 {#king_base.html#} {## ————————02PerfectCRM创建ADMIN页面————————#} {#模板文件 king_base.html#} ...

  4. ORACLE 使用笔记

    ORACLE TRUNC()函数 TRUNC():类似截取函数,按指定的格式截取输入的数据. 1.[trunc(for dates)]TRUNC()函数处理日期 语法格式:TRUNC(date[,fm ...

  5. C++ 之手写strcpy

    char *strcpy(char* strDest, const char*strSrc){ assert(strDest != NULL&&strSrc != NULL); cha ...

  6. NFS实现(双httpd + php-fpm + nfs + mysql 搭建discuz论坛)的方法

    NFS相关介绍 一.NFS简介 1. NFS(Network File System):NFS是一个文件共享协议, 也是是在类Unix系统中在内核中实现的文件系统. 2. 起源:最早是由SUN公司研发 ...

  7. thrift python安装

    http://thrift.apache.org/download/ tar -zxvf thrift-0.11.0.tar.gz cd thrift-0.11.0 ./configure --pre ...

  8. es安装遇到的问题

    问题1: es一闪即逝的问题?java的jdk环境变量没有配置好, JAVA_HOME没有配置好 必须在系统变量里面添加JAVA_HOME: C:\Program Files\Java\jre1.8. ...

  9. idea 项目热部署设置

    1.引入pom.xml() <!-- 热部署(必须) --> <dependency> <groupId>org.springframework.boot</ ...

  10. JasperStudio 输出pdf 出错。

    发表于 2008-09-23 09:35:15 楼主net.sf.jasperreports.engine.JRException: Error retrieving field value from ...