10.了解MySql中的分区概念

1.什么是分区?

分区其实是一个过程,它将一个表或索引分解为多个更小,更容易管理的部分。
MySQL支持的分区类型为水平分区:将同一张表中不同行的记录分配到不同的物理文件中。
这样就可以根据分区对一些有规律的数据进行高效操作。MySQL数据库中的分区时局部分区,即一个分区中既存放数据也存放索引。

2.MySql中支持的分区类型

1)RANGE分区:行数据基于属于一个给定连续区间的列值放入分区。
2)LIST分区:它和RANGE分区类型一样,只是LIST分区面向的是离散的值,而不是连续的列值。
3)HASH分区:根据用户自定义表达式的返回值来进行分区(特定算法分区),返回值不能是负数。
4)KEY分区:根据MySql数据库提供的散列函数来进行分区。

在创建分区时必须注意的一点:如果表中存在主键或唯一索引时,分区列必须是唯一索引的一个组成部分。当建表时没有指定主键和唯一索引时,可以指定任何一个列为分区列。

下面请判断下面sql语句是否顺利执行:

CREATE TABLE T1(
    col1 int not null,
    col2 date not null,
    col3 int not null,
    col4 int not null,
    unique key(col1,col2)
)
partition by hash(col3)
partition 4;
CREATE TABLE T1(
    col1 int not null,
    col2 date not null,
    col3 int not null,
    col4 int not null,
    unique key(col1,col2,col3)
)
partition by hash(col3)
partition 4;
CREATE TABLE T1(
    col1 int not null,
    col2 date not null,
    col3 int not null,
    col4 int not null,
)
partition by hash(col3)
partition 4;
CREATE TABLE T1(
    col1 int  null,
    col2 date null,
    col3 int  null,
    col4 int  null,
    key(col4)
)
partition by hash(col3)
partition 4;

猜你喜欢

转载自blog.csdn.net/c1776167012/article/details/120935351
10.