MySQL分区处理NULL值得方式

一般情况下,MySQL的分区把NULL当做零值,或者一个最小值进行处理

对于range分区

create table test_null(
    id int
)
partition by range(id)(
partition p0 values less than (-6),
partition p1 values less than (0),
partition p2 values less than (1),
partition p3 values less than MAXVALUE
);

mysql> insert into test_null values(null);
Query OK, 1 row affected (0.01 sec)

mysql> select
    ->   partition_name part,
    ->   partition_expression expr,
    ->   partition_description descr,
    ->   table_rows
    -> from information_schema.partitions  where
    ->   table_schema = schema()
    ->   and table_name='test_null';
+------+------+----------+------------+
| part | expr | descr    | table_rows |
+------+------+----------+------------+
| p0   | id   | -6       |          1 |
| p1   | id   | 0        |          0 |
| p2   | id   | 1        |          0 |
| p3   | id   | MAXVALUE |          0 |
+------+------+----------+------------+
4 rows in set (0.00 sec)

对于list分区
当分区定义不包含NULL值是,会报错

create table list_null(
    id int
)
partition by list(id)(
partition p1 values in (0),
partition p2 values in (1)
);

mysql> insert into list_null values(null);
ERROR 1526 (HY000): Table has no partition for value NULL

当分区定义包含NULL时

create table list_null_1(
    id int
)
partition by list(id)(
partition p1 values in (0),
partition p2 values in (1),
partition p3 values in (null)
);

mysql> insert into list_null_1 values(null);
Query OK, 1 row affected (0.01 sec)

mysql> select
    ->   partition_name part,
    ->   partition_expression expr,
    ->   partition_description descr,
    ->   table_rows
    -> from information_schema.partitions  where
    ->   table_schema = schema()
    ->   and table_name='list_null_1';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p1   | id   | 0     |          0 |
| p2   | id   | 1     |          0 |
| p3   | id   | NULL  |          1 |
+------+------+-------+------------+
3 rows in set (0.00 sec)

对于Hash分区和key分区

create table hash_null(
    id int
)
partition by hash(id)
partitions 2;

mysql> insert into hash_null values(null);
Query OK, 1 row affected (0.00 sec)

mysql> select
    ->   partition_name part,
    ->   partition_expression expr,
    ->   partition_description descr,
    ->   table_rows
    -> from information_schema.partitions  where
    ->   table_schema = schema()
    ->   and table_name='hash_null';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0   | id   | NULL  |          1 |
| p1   | id   | NULL  |          0 |
+------+------+-------+------------+
2 rows in set (0.00 sec)

对于Key分区

create table key_null(
    id int
)
partition by key(id)
partitions 2;

mysql> select
    ->   partition_name part,
    ->   partition_expression expr,
    ->   partition_description descr,
    ->   table_rows
    -> from information_schema.partitions  where
    ->   table_schema = schema()
    ->   and table_name='key_null';
+------+------+-------+------------+
| part | expr | descr | table_rows |
+------+------+-------+------------+
| p0   | `id` | NULL  |          1 |
| p1   | `id` | NULL  |          0 |
+------+------+-------+------------+

Mysql 分区处理NULL的得方式的更多相关文章

  1. mysql分区

    <?php /* 分区 目录 18.1. MySQL中的分区概述 18.2. 分区类型 18.2.1. RANGE分区 18.2.2. LIST分区 18.2.3. HASH分区 18.2.4. ...

  2. 17.Mysql分区

    17.Mysql分区分区是指根据一定的规则把一个表分解成多个部分,逻辑上仍是一张表,实际上由多个物理分区对象组成.分区对于应用是完全透明的,不影响业务逻辑和SQL编写.分区的优点: 可以存储更多的数据 ...

  3. mysql分区 详解

    第18章:分区 目录 18.1. MySQL中的分区概述 18.2. 分区类型 18.2.1. RANGE分区 18.2.2. LIST分区 18.2.3. HASH分区 18.2.4. KEY分区 ...

  4. 第18章:MYSQL分区

    第18章:分区 目录 18.1. MySQL中的分区概述 18.2. 分区类型 18.2.1. RANGE分区 18.2.2. LIST分区 18.2.3. HASH分区 18.2.4. KEY分区 ...

  5. MySQL分区 (分区介绍与实际使用)

    分区介绍: 一.什么是分区? 所谓分区,就是将一个表分成多个区块进行操作和保存,从而降低每次操作的数据,提高性能.而对于应用来说则是透明的,从逻辑上看只有一张表,但在物理上这个表可能是由多个物理分区组 ...

  6. 十五、mysql 分区之 分区管理

    1.mysql分区处理分区字段NULL值的方式 1.range分区null被当作最小值处理 2.list分区null值必须被枚举出来,否则将出错 3.hash/key分区 null值当作0处理 2.R ...

  7. mysql分区功能(三个文件储存一张表)(分区作用)(分区方式)

    mysql分区功能(三个文件储存一张表)(分区作用)(分区方式) 一.总结 1.mysql数据表的存储方式(三个文件储存一张表): 一张表主要对应着三个文件,一个是frm存放表结构的,一个是myd存放 ...

  8. MySQL分区总结

    MySQL支持RANGE,LIST,HASH和KEY四种分区.其中,每个分区又都有一种特殊的类型.对于RANGE分区,有RANGE COLUMNS分区.对于LIST分区,有LIST COLUMNS分区 ...

  9. mysql分区研究

    表分区学习 1. 概述 1.1. 优点: l 将表分区比一个表在单个磁盘或者文件系统存储能够存储更多数据 l 可以通过drop分区删除无用数据,也可以通过增加分区添加数据 l 查询可以通过分区裁剪进行 ...

随机推荐

  1. a标签中href的触发

    采用.trigger('click')没有效果,是用的$('xx')[0].click()来触发的.不知道为什么trigger不行,望指导.

  2. UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用

    UIButton内有两个控件titleLabel和imageView,可以用来显示一个文本和图片,这里的图片区别于背景图片.给UIButton设 置了title和image后,它们会图片在左边,文本在 ...

  3. arguments 对象

    在函数体内,标识符arguments是指向实参对象的引用,实参对象是一个类数组对象 arguments[0],arguments.length arguments是什么? 答:1:arguments是 ...

  4. Elasticsearch mapping

    //设置mapping Put: http://192.168.1.102:9200/indexName { "settings": { , }, "mappings&q ...

  5. npm -v 一直闪

    一直闪一般是配置搞错了 参考: windows安装完nodejs后做了相关环境变量配置后,cmd输入npm没反应啊 就光标一直闪 node是正常的 或者 https://segmentfault.co ...

  6. -[UIKeyboardLayoutStar release]: message sent to deallocated instance 0x7fbe49120000

    __NSArrayM objectAtIndex: 取消swizzle 只有debug的时候会报错,发布的时候是好的,所以可以不用改

  7. 如何把apdu[decode_len]打印出来

    memcpy(data, &apdu[decode_len], apdu_len - decode_len);    int i = 0;    for(i=0;i<apdu_len;i ...

  8. C语言fgetpos()函数:获得当前文件的读写指针(转)

    头文件:#include<stdio.h>fgetpos()函数获得当前文件的指针所指的位置,并把该指针所指的位置信息存放到pos所指的对象中.pos以内部格式存储,仅由fgetpos() ...

  9. linux 软件的安装与Tarball

    Linux 系统上真正认识的可执行文件其实是二进制文件 ( binary program ) shell scripts 只是利用 shell (例如 bash) 这支程序的功能进行一些判断式,而最终 ...

  10. Android之RecyclerView(一)

    概述 RecyclerView 是一个 ViewGroup,它用于渲染任何基于适配器的 View.它被官方定义为 ListView 和 GridView 的取代者,是在 Support V7 包中引入 ...