分区案例:

在数据量非常大的情况下,MySQL自身提供一种分区的机制,可以按照一定的分区算法(list、Range、hash、key)将一种表里面的数据保存在不同的分区(磁盘上的空间)里面。

创建分区表

create table emp(

    id int,

    name varchar(32),

    store_id int

)partition by list (store_id)(

    partition p_north values in (1,4,5,6,17,18),

    partition p_east values in(2,7,9,10,11,13),

    partition p_south values in(3,12,19,20),

    partition p_west values in(8,14,15,16)

);

insert into emp values(1,’asion’,4),(2,’bill’,15);

explain partitions select * from emp where store_id = 15

注意:where后面的字段信息,需要在分区里面出现。

range分区

create table user(

    id int,

    name varchar(32),

    birthday date

)partition by range (month(birthday))(

    partition p_1 values less than (3),

    partition p_2 values less than(6),

    partition p_3 values less than(9),

    partition p_4 values less than MAXVALUE

);

#该分析不需要数据库一定有数据,数据存放位置和有无数据毫无关系

explain partitions select * from user where birthday = '2018-9-16'

MAXVALUE: month 最大的值 12

MySql数据库的分区

分区:如果在一个非常大的表结构里面查找指定数据,可以使用分区(mysql内部实现)后,将数据分成多个小块(按照一定的算法list、range),然后在小块中查找,效率肯定要比从非常大的数据里面查找快一些。

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-08-12
  • 2021-07-29
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案