MySQL中hash和key分区值的计算方法

mysql中有一种叫作key作为partition key的类型.来看看记录是怎么分布的

对于hash 分区,使用%操作符,每个partition key只能是int类型,通过

partition key%3(比如定义了三个分区)来把记录分布三个不同的artition里面

mysql> create table t13 ( a int,b int) partition by hash(a) partitions 3

mysql>insert into t14 values(10,1);

mysql>insert into t14 values(11,1);

mysql>insert into t14 values(12,1);

10%3=1 所以第一条记录是在p1里面,11%3=2在第二个分区p2里面,以此类推.

mysql> explain partitions select * from t13 where a=10;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t13   | p1         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t13 where a=11;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t13   | p2         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t13 where a=12;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t13   | p0         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

对于使用key partition 的方法,官方文档说是使用了一种password的方法.

mysql>create table t14 (a int,b int) partition by key(a) partitions 3

insert into t14 values(10,1);

insert into t14 values(11,1);

insert into t14 values(12,1);

insert into t14 values(13,1);

insert into t14 values(14,1);

insert into t14 values(15,1);

insert into t14 values(16,1);

mysql> explain partitions select * from t14 where a=10;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p0         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=11;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p0         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=12;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p1         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=13;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p1         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=14;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p2         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=15;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra       |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|  1 | SIMPLE      | t14   | p2         | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

我发现对于key partition的规律是每两个值落在同一步分区里面,其他没有什么规律字,只是为什么样这样分配到不同的

分区里面,没有很好的解释。如果使用password函数,这些值的结果根本就不一样.有知道的朋友可以和我交流一下.

mysql的hash分区_MySQL中hash和key分区值的计算方法相关推荐

  1. mysql获取当月最后一天_mysql中获取本月第一天、本月最后一天、上月第一天、上月最后一天

    mysql获取当月最后一天_mysql中获取本月第一天.本月最后一天.上月第一天.上月最后一天等等 转自: https://blog.csdn.net/min996358312/article/det ...

  2. mysql的hash分区_MySQL中的分区(五)HASH分区

    HASH分区主要用来分散热点读,取保数据在预先确定个数的分区中尽可能的平均分布.对一个表执行HASH分区时,MySQL会对分区键应用一个散列函数,一次确定数据应该放在哪一个分区中. MySQL分区支持 ...

  3. mysql 基于时间分区_MySQL基于时间字段进行分区的方案总结

    MySQL支持的分区类型一共有四种:RANGE,LIST,HASH,KEY.其中,RANGE又可分为原生RANGE和RANGE COLUMNS,LIST分为原生LIST和LIST COLUMNS,HA ...

  4. 一致性hash和redis中hash槽的区别

    一致性hash主要用于分布式系统中,用于解决数据选择节点存储.选择节点访问.增删节点后数据的迁移和重分布问题.redis集群并没有使用一致性hash,而是使用了hash槽来解决数据分配的问题. 一致性 ...

  5. mysql查看执行计划_MySql中如何使用 explain 查询 SQL 的执行计划

    explain命令是查看查询优化器如何决定执行查询的主要方法. 这个功能有局限性,并不总会说出真相,但它的输出是可以获取的最好信息,值得花时间去了解,因为可以学习到查询是如何执行的. 1.什么是MyS ...

  6. mysql my.cnf 日志_mysql中my.cnf配置项记录

    [mysqld] # 一般配置选项 port = @MYSQL_TCP_PORT@ socket = @MYSQL_UNIX_ADDR@ # back_log 是操作系统在监听队列中所能保持的连接数, ...

  7. mysql replace报错_Mysql中replace与replace into的用法讲解

    Mysql replace与replace into都是经常会用到的功能:replace其实是做了一次update操作,而不是先delete再insert:而replace into其实与insert ...

  8. mysql 字符串 空格函数_mysql中的去除空格函数

    (1)mysql replace 函数 语法:replace(object,search,replace) 意思:把object中出现search的全部替换为replace 案例:update `ne ...

  9. mysql 数值类型 长度_mysql中的数据类型的长度

    位,字节,字 --------------------------------------------------------------- 8位(bit)=1字节(Byte),1024字节=1KB: ...

最新文章

  1. 继续昨日计划: 2022-2-16
  2. python编程if语法-讲解Python中if语句的嵌套用法
  3. Blend学习资料总结
  4. 动态样式计算 动态样计算 <span :style=“{‘left‘:`${(l+1)*16 - 6}`+‘px‘}“></span>
  5. springboot html压缩,springboot 请求响应压缩
  6. 触发器及其应用实验报告总结_双面喷绘材料的分类及其应用,超全总结!(建议收藏)...
  7. python加密字符串小写字母循环后错两位_Python简单加密程序:如何将Z循环回
  8. Python day16(JavaScript)
  9. 完全二分图生成树计数
  10. Android线程创建aop,【android安卓】一个注解搞定线程切换,基于AOP的线程转换框架...
  11. 在线下单系统php源码,PIMS在线订单管理系统v4.2.9
  12. D5渲染器 2.0 全新升级|天气系统、路径动画、草地材质,内置海量正版素材库
  13. 逆向Mac版WPS2019解除版本过期限制
  14. 热敏打印机排版—了解打印机的基础知识
  15. win11连接共享打印机错误0x00000709
  16. matlab 直接逆滤波,图像复原之直接逆滤波
  17. 仿酒仙网品牌活动动画效果 (鼠标移上 图片平移)
  18. java 虚函数表_虚函数表(vtable/virtual table/virtual method table)
  19. 以OPC PowerTool 连接iFix与KEPWARE
  20. c# chart缩放,局部放大

热门文章

  1. 【Java】6.3 类成员
  2. 蓝桥杯java第五届决赛第三题--格子放鸡蛋
  3. 蓝桥杯-数字三角形 (java)
  4. 浅谈Java反射(Reflect)技术--常用方法
  5. Java之反射--练习
  6. (Mybatis)增删改查实现
  7. Android JNI的第一步——从HelloWorld开始
  8. 常见的排序算法(1)
  9. mapinfo制作地图_Mapinfo操作不太会?看这篇就够了
  10. 正则 不能有中文逗号_Python爬虫教程-19-数据提取-正则表达式(re)