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. 2016 China-Final-F题 ——(SA+二分)

    其实是一个很经典的字符串问题,但是我们比赛的时候没出. 先看一下UVA11107这题,题意是,找出最长的一个字符串,在至少一半的字符串中出现过.只要把所有的字符串用不同的分隔符分开,然后SA一下,最后 ...

  2. 2013xlsm格式文件处理

    2013xlsm格式文件处理 2013格式的xlsm文件在低版本打开为空白的处理 1.关闭2013的宏2.打开文件,另存(去打开密码)3.2007打开另存(格式已变为2007)4.仅破解VBA密码5. ...

  3. Endless Sky源码学习笔记-5

    游戏启动后的UI划分为三个区域,左侧滚动显示credits等信息以及偏好设置和退出按钮,中间显示载入动画,右侧显示玩家信息以及载入存档按钮,调用void MenuPanel::Draw()实现.首先画 ...

  4. linux grep -I 属性

    忽略大小写的查找: grep -i 'address' test.log --> address ADDRESS

  5. iOS 根据字符串内容动态计算行高

    + (CGFloat)textHeightFromTextString:(NSString *)text width:(CGFloat)textWidth fontSize:(CGFloat)size ...

  6. 自定义ViewGroup

    ViewGroup --->A ViewGroup is a special view that can contain other views (called children.) The v ...

  7. 解决Linux系统下程序找不到动态库的方法

    思路:一般来说,通过make命令已经将程序依赖的动态库编译出来了,通过make install命令已经将动态库安装到系统的某个路径下.找没找到动态库就看这个路径是否包含在系统默认搜索动态库的路径中,如 ...

  8. python 协程

    协程 协程就是一种用户态内的上下文切换技术. 1.使用gevent实现协程, gevent.spawn()调用函数,  gevent.sleep(1) 模拟阻塞,实现切换. import gevent ...

  9. Appium移动自动化测试之获取appPackage和appActivity

    方法一:直接打开Appium,点击左上角机器人图标 选择apk所在位置,如图所示,这里以ContactManager.apk为例 方法二:利用dex2jar和jd-gui这两个工具反编译apk文件 这 ...

  10. WCF通过SVCUtil.exe生成客户端代理类和配置文件(转)

    WCF服务调用通过两种常用的方式: 1:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式. 2:一种是通过ChannelFactory直接创建服务代理对象进行服务调用. 本文只针对通 ...