[MySQL]ANALYZE TABLE 更新索引基数
MySQL使用存储的键分布基数来确定表连接顺序
在决定对查询中的特定表使用哪些索引时,也会使用使用键分布基数
ANALYZE TABLE 表名 可以更新表的索引基数,使其更接近非重复的记录数,记录数可以使用show index from 表 来查询cardinality字段
mysql> show index from index_test;
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| index_test | 0 | PRIMARY | 1 | id | A | 5 | NULL | NULL | | BTREE | | |
| index_test | 1 | score_index | 1 | score | A | 2 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 1 | name | A | 3 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 2 | gid | A | 3 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 3 | age | A | 6 | NULL | NULL | | BTREE | | |
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
5 rows in set (0.00 sec) mysql> select * from index_test;
+----+------------+-----+-----+-------+
| id | name | gid | age | score |
+----+------------+-----+-----+-------+
| 1 | taoshihan | 2 | 0 | 0 |
| 2 | taoshihan1 | 2 | 0 | 0 |
| 3 | taoshihan2 | 3 | 10 | 10 |
| 4 | taoshihan | 2 | 1 | 0 |
| 5 | taoshihan | 2 | 2 | 0 |
| 6 | taoshihan | 2 | 3 | 0 |
+----+------------+-----+-----+-------+
6 rows in set (0.03 sec) mysql> ANALYZE TABLE index_test;
+--------------------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+--------------------+---------+----------+----------+
| my_test.index_test | analyze | status | OK |
+--------------------+---------+----------+----------+
1 row in set (0.13 sec) mysql> show index from index_test;
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| index_test | 0 | PRIMARY | 1 | id | A | 6这里变了 | NULL | NULL | | BTREE | | |
| index_test | 1 | score_index | 1 | score | A | 2 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 1 | name | A | 3 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 2 | gid | A | 3 | NULL | NULL | | BTREE | | |
| index_test | 1 | name_gid_age_index | 3 | age | A | 6 | NULL | NULL | | BTREE | | |
+------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
5 rows in set (0.07 sec)
[MySQL]ANALYZE TABLE 更新索引基数的更多相关文章
- MySQL ANALYZE TABLE
Analyze Table MySQL 的Optimizer(优化元件)在优化SQL语句时,首先需要收集一些相关信息,其中就包括表的cardinality(可以翻译为“散列程度”),它表示某个索引对应 ...
- mysql 优化analyze table
Analyze Table MySQL 的Optimizer(优化元件)在优化SQL语句时,首先需要收集一些相关信息,其中就包括表的cardinality(可以翻译为“散列程度”),它表示某个索引对应 ...
- MySQL check table/optimize table/analyze table/REPAIR TABLE
MySQL check table/optimize table/analyze table/REPAIR TABLE 转自:https://www.cnblogs.com/datastack/p/3 ...
- MySQL: OPTIMIZE TABLE: Table does not support optimize, doing recreate + analyze instead
show create table history;-------------------------- CREATE TABLE `foo` ( `itemid` bigint(20) unsig ...
- mysql optimize table
mysql 数据文件的使用是只扩展,不回收.对表执行delete之后,磁盘上数据文件是不会缩小的. 通常的做法,是先逻辑导出,然后truncate 原表(或者删除重建),再导入. 另外还有一种方法是o ...
- mysql analyze和optimize
Analyze Table MySQL 的Optimizer(优化元件)在优化SQL语句时,首先需要收集一些相关信息,其中就包括表的cardinality(可以翻译为“散列程度”),它表示某个索引对应 ...
- Oracle索引梳理系列(十)- 直方图使用技巧及analyze table操作对直方图统计的影响(谨慎使用)
版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...
- [转] Oracle analyze table 使用总结
转自:http://www.cnblogs.com/einyboy/archive/2012/08/09/2630321.html analyze table 一般可以指定分析: 表,所有字段,所有索 ...
- MySQL Create Table创建表
表的创建命令需要: 表的名称 字段名称 定义每个字段(类型.长度等) 语法 下面是通用的SQL语法用来创建MySQL表: CREATE TABLE table_name (column_name co ...
随机推荐
- 团队第一次作业(软工C#造梦厂)
一.团队简介 a.团队名称:软工C#造梦厂 b.队员列表 姓名 学号 张旭(组长) 201731024123 周成杰 201731024136 邹扬锋 201731024134 赵俊安 2017310 ...
- jmeter使用—响应断言
断言的作用:一个HTTP请求发出去,怎么判断执行的任务是否成功呢?通过检查服务器响应数据,是否返回预期想要的数据,如果是,判断任务成功,反之任务失败. 1.添加断言:选中一个取样器,右键->添加 ...
- Java多线程:实现API接口创建线程方式详解
先看例子: /**实现Runnable接口创建线程步骤: * 1.创建一个实现Runnable接口的类 * 2.重写Runnable类中抽象的run()方法 * 3.创建实现类的对象 * 4.声明Th ...
- C语言创建文件
问题需求:使用程序创建一个文件(当该文件不存在时则创建). 代码如下: // 创建文件 void CreateFile() { //文件指针 FILE *fileP; char fileName[] ...
- 码云(gitee)配置ssh密钥
创建公钥的目的: 使用SSH公钥可以让你在你的电脑和码云通讯的时候使用安全连接(git的remote要使用SSH地址) git中粘贴右击鼠标选择Paste 步骤: 打开终端(git)进入.ssh目录 ...
- ros之参数的使用与编程方法
参数模型 ROS Master (Parameter Server) /robot_name: "my_robot" ----{Node A Node B} /r ...
- FPGA VGA+PLL+IP核笔记
1.实现了预定功能!整个工程,没有使用例程的25MHZ,全部统一使用50MHZ.2.分辨率使用了800*600@72HZ.3.实现了只显示白色部分,黑色部分RGB == 0,要显示背景色.VGA图形基 ...
- HDU_5230_DP
http://acm.hdu.edu.cn/showproblem.php?pid=5230 有初始值c,给你1~n的数,输入c+一些数,使得结果在l~r的范围内,输出方案数,注意每种方案中每个数只能 ...
- 关于SQL Server 2012 手动安装帮助文档
大家以为安装帮助文档很简单,但是其实不然,这其中还有那么一点点道道.今天我就来给大家演示一下! 首先到microsoft官网上下载Microsoft SQL Server 2012 产品文档,然后将. ...
- 一个新实验:使用gRPC-Web从浏览器调用.NET gRPC服务
今天给大家翻译一篇由ASP.NET首席开发工程师James Newton-King前几天发表的一篇博客,文中带来了一个实验性的产品gRPC-Web.大家可以点击文末的讨论帖进行相关反馈.我会在文章末尾 ...