1,合并表:把多个结果相同的的表合并为一个容器。
容器的类型:Myisam,存储引擎:merge
存在的问题:有重复的行
<pre class="hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">create table packtable(
id ....
)engine=merge unique=(table1,table2);
2,表的分区:
更多技术知识请关注我的V-X-公-众hao:编程经验共享
2.1,水平分区:根据某个字段进行分区(RANGE分区)
<pre class="prettyprint hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">create table test1(
id int(10) primary key auto_increment,
score int(3)
)engine=innodb default charset=utf8 partition by range(score)(
//根据score字段分区,score小于60的在p1分区
partition p1 values less than(60),
//根据score字段分区,score小于70的在p2 分区
partition p2 values less than(70),
//根据score字段分区,score大于70的在p3 分区
partition p3 values lessthan maxvalue
);
2.2 list分区:第一选择基于某 列的值是否属于某个 集合
<pre class="prettyprint hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">create table test1(
id int(10) primary key auto_increment,
branch_id int(3)
)engine=innodb default charset=utf8 partition by list(branch_id )(
//根据branch_id 字段分区,branch_id 在1,2,3之中的为p1分区
partition p1 values less in(1,2,3),
//根据branch_id 字段分区,branch_id 在7,8,9 之中的为p2分区
partition p2 values less in(7,8,9)
);
2.3 hash分区:支持数值类型
<pre class="prettyprint hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">--
-- 根据birthda字段获取月份,再根据月份进行分区储存,一共分12个区;
--
create table test1(
id int(10) primary key auto_increment,
birthday date
)engine=innodb default charset=utf8 partition by hash(month(birthday)) partitions 12;
2.4 线性分区(linear hash):大数据是增加,合并,拆分速度更快
<pre class="prettyprint hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">--
-- 根据branch_id字段进行分区储存,一共分5个区;
--
create table test1(
id int(10) primary key auto_increment,
branch_id int(3)
)engine=innodb default charset=utf8 partition by linear hash (branch_id ) partitions 5;
2.5 key分区:可以计算一列或者多列进行分区
<pre class="prettyprint hljs sql" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">--
-- 根据branch_id字段进行分区储存,一共分5个区;
--
create table test1(
id int(10) primary key auto_increment,
branch_id int(3)
)engine=innodb default charset=utf8 partition by key (branch_id ) partitions 5;