Mysql中的合并表可以把多个表合并成一个虚表,就像类似使用union视图一样;可以使用合并引擎创建合并表。合并表可以做到;
1.分离静态的和变化的数据;
2.使用相关数据的物理相邻性来优化查询,
3.设计表查询较少的数据;
4.容易维护大容量的数据的管理;
以下为案例;
mysql> show tables;
Empty set (0.00 sec)
mysql> create table t1(a int not null primary key)engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t2(a int not null primary key)engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t1(a) values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into t2(a)values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> create table mrg(a int not null primary key)
-> engine=merge union=(t1,t2)insert_method=last;
Query OK, 0 rows affected (0.00 sec)
mysql> select a from mrg;
+---+
| a |
+---+
| 1 |
| 1 |
| 2 |
| 2 |
+---+
4 rows in set (0.00 sec)
mysql>
mysql>
mysql>