什么是水平分表?
将表中不同的数据行按照一定规律分布到不同的数据库表中(这些表保存在同一个数据库中),这样来降低单表数据量,优化查询性能。最常见的方式就是通过主键或者时间等字段进行Hash和取模后拆分。
如何进行查询?
- 利用merge存储引擎进行查询123456789101112131415create table test_1(id int primary key auto_increment,name varchar(36),type int(2) not null default 1) engine = MyISAM charset=UTF8;create table test_2(id int primary key auto_increment,name varchar(36),type int(2) not null default 2) engine = MyISAM charset=UTF8;create table test_3(id int primary key auto_increment,name varchar(36),type int(2) not null default 3) engine = MyISAM charset=UTF8;create table test(id int primary key auto_increment,name varchar(36),type int(2) not null default 0) engine = MRG_MyISAM union =(test_1,test_2,test_3) insert_method last charset UTF8;insert into test_1(name) values('孙悟空');insert into test_2(name) values('猪八戒');insert into test_3(name) values('沙悟净');insert into test(name) values('陈玄奘');select * from test_1;select * from test_2;select * from test_3;select * from test;
select * from test结果
注意:使用merge时子表的存储引擎必须使用MyISAM