在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

MYSQL5.6 5.7处理数据分布不均的问题分析

134次阅读
没有评论

共计 4943 个字符,预计需要花费 13 分钟才能阅读完成。

本篇内容主要讲解“MYSQL5.6 5.7 处理数据分布不均的问题分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“MYSQL5.6 5.7 处理数据分布不均的问题分析”吧!

处理数据分布不均,orace 数据库使用额外的统计数据直方图来完成,而 MYSQL
中统计数据只有索引的不同值这样一个统计数据,那么我们制出如下数据:
mysql select * from test.testf;
+——+———-+
| id   | name     |
+——+———-+
|    1 | gaopeng  |
|    2 | gaopeng1 |
|    3 | gaopeng1 |
|    4 | gaopeng1 |
|    5 | gaopeng1 |
|    6 | gaopeng1 |
|    7 | gaopeng1 |
|    8 | gaopeng1 |
|    9 | gaopeng1 |
|   10 | gaopeng1 |
+——+———-+
10 rows in set (0.00 sec)
name 上有一个普通二级索引
mysql analyze table test.testf;
+————+———+———-+———-+
| Table      | Op      | Msg_type | Msg_text |
+————+———+———-+———-+
| test.testf | analyze | status   | OK       |
+————+———+———-+———-+
1 row in set (0.21 sec)

分别作出如下执行计划:
mysql explain select * from test.testf where name= gaopeng
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
|  1 | SIMPLE      | testf | NULL       | ref  | name          | name | 63      | const |    1 |   100.00 | NULL  |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
1 row in set, 1 warning (0.00 sec)

mysql explain select * from test.testf where name= gaopeng1
+—-+————-+——-+————+——+—————+——+———+——+——+———-+————-+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+—-+————-+——-+————+——+—————+——+———+——+——+———-+————-+
|  1 | SIMPLE      | testf | NULL       | ALL  | name          | NULL | NULL    | NULL |   10 |    90.00 | Using where |
+—-+————-+——-+————+——+—————+——+———+——+——+———-+————-+
1 row in set, 1 warning (0.00 sec)

可以看到执行计划是正确的,name= gaopeng 的只有一行选择了索引,name= gaopeng1 的有 9 行走了全表。
按理说如果只是记录不同的那么这两个语句的选择均为 1 /2, 应该会造成执行计划错误,而 MYSQL 5.6 5.7 中
都做了正确的选择,那是为什么呢?
其实原因就在于 eq_range_index_dive_limit 这个参数,我们来看一下 trace
T@2: | | | | | | | | | | | opt: (null): gaopeng1 = name =  | T@3: | | | | | | | | | | | opt: (null): gaopeng = name = g
T@2: | | | | | | | | | | | opt: ranges: ending struct         | T@3: | | | | | | | | | | | opt: ranges: ending struct
T@2: | | | | | | | | | | | opt: index_dives_for_eq_ranges: 1  | T@3: | | | | | | | | | | | opt: index_dives_for_eq_ranges: 1
T@2: | | | | | | | | | | | opt: rowid_ordered: 1              | T@3: | | | | | | | | | | | opt: rowid_ordered: 1
T@2: | | | | | | | | | | | opt: using_mrr: 0                  | T@3: | | | | | | | | | | | opt: using_mrr: 0
T@2: | | | | | | | | | | | opt: index_only: 0                 | T@3: | | | | | | | | | | | opt: index_only: 0
T@2: | | | | | | | | | | | opt: rows: 9                       | T@3: | | | | | | | | | | | opt: rows: 1
T@2: | | | | | | | | | | | opt: cost: 11.81                   | T@3: | | | | | | | | | | | opt: cost: 2.21

我们可以看到 index_dives_for_eq_ranges 均为 1,rows: 9 rows: 1 都是正确的,那么可以确定是 index_dives_for_eq_ranges 的作用,实际上
这是一个参数 eq_range_index_dive_limit 来决定的(equality range optimization of many-valued comparisions),默认为
mysql show variables like %eq%
+————————————–+——-+
| Variable_name                        | Value |
+————————————–+——-+
| eq_range_index_dive_limit            | 200   |

在官方文档说这个取值是等值范围比较的时候有多少个需要比较的值
如:
id=1 or id=2 or id=3 那么他取值就是 3 +1=4
而这种方法会得到精确的数据,但是增加的是时间成本,如果将
eq_range_index_dive_limit 设置为 1:则禁用此功能
eq_range_index_dive_limit 设置为 0:则始终开启
eq_range_index_dive_limit 设置为 N:则满足 N - 1 个这样的域。
那么我们设置为 eq_range_index_dive_limit=1 后看看
mysql explain select * from test.testf where name= gaopeng1
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
|  1 | SIMPLE      | testf | NULL       | ref  | name          | name | 63      | const |    5 |   100.00 | NULL  |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
1 row in set, 1 warning (0.00 sec)

mysql explain select * from test.testf where name= gaopeng
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
|  1 | SIMPLE      | testf | NULL       | ref  | name          | name | 63      | const |    5 |   100.00 | NULL  |
+—-+————-+——-+————+——+—————+——+———+——-+——+———-+——-+
1 row in set, 1 warning (0.00 sec)

可以看到执行计划已经错误 name= gaopeng1 明显不应该使用索引,我们再来看看 trace
T@3: | | | | | | | | | | | opt: ranges: ending struct
T@3: | | | | | | | | | | | opt: index_dives_for_eq_ranges: 0
T@3: | | | | | | | | | | | opt: rowid_ordered: 1
T@3: | | | | | | | | | | | opt: using_mrr: 0
T@3: | | | | | | | | | | | opt: index_only: 0
T@3: | | | | | | | | | | | opt: rows: 5
T@3: | | | | | | | | | | | opt: cost: 7.01
index_dives_for_eq_ranges: 0 rows: 5 这个 5 就是 10*1/ 2 导致的, 而 index_dives_for_eq_ranges= 0 就是禁用了

到此,相信大家对“MYSQL5.6 5.7 处理数据分布不均的问题分析”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计4943字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 91成人在线免费视频 | 亚洲国产精品尤物yw在线观看 | 亚洲伊人一本大道中文字幕 | 双腿张开被9个黑人调教影片 | 色五月丁香五月综合五月4438 | 日韩经典欧美一区二区三区 | 亚洲av国产精品色午夜洪2 | 欧美人与禽2o2o性论交 | 免费伊人网 | 暖暖视频日本在线观看 | 亚洲欧美高清视频 | 亚洲毛片在线观看 | 久久综合伊人中文字幕 | 国产成人精品免费视频大全软件 | 777久久精品一区二区三区无码 | 在线一级黄色片 | 狠狠的操 | 18禁止进入1000部高潮网站 | 精品亚洲一区二区三区 | 色94色欧美sute亚洲线路一 | 国产免费网址 | 视频一区 中文字幕 | 亚洲第一中文字幕 | 普通话精彩对白一区 | 亚洲人成无码网站 | 亚洲色无码播放 | 狠狠久久综合伊人不卡 | 国产精品久久久久久久久久久搜索 | 色综合久久手机在线 | 亚洲熟妇久久精品 | 免费看特级片 | 18禁真人抽搐一进一出免费 | 国产精品白浆在线观看免费 | 精品人妻伦九区久久aaa片 | 黄色一级在线 | 欧美性高清另类videosex | 又黄又爽又色的免费网站 | 国产级a爱做片免费观看 | 久久福利国产 | 色老成人精品视频在线观看 | 国产精品欧美日韩精品 |