简体   繁体   English

MySQL MERGE存储引擎

[英]MySQL MERGE Storage Engine

I am setting up a table in mysql of engine type merge in mysql and was wondering if i have to have all my tables created previously that i want to merge. 我在mysql中建立一个mysql引擎类型合并的表,并且想知道我是否必须先创建我想要合并的所有表。 For example: 例如:

CREATE TABLE t1 (
   a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   message CHAR(20)) ENGINE=MyISAM;

CREATE TABLE t2 (
   a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   message CHAR(20)) ENGINE=MyISAM;
INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');
INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');
CREATE TABLE total (
   a INT NOT NULL AUTO_INCREMENT,
   message CHAR(20), INDEX(a))
   ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;

Now if i have code that automatically created a t3 table i would have to modify the merge table to add this to the union? 现在,如果我有自动创建t3表的代码,我将不得不修改合并表以将其添加到联合? Would i use an ALTER query for that? 我会使用ALTER查询吗?

note: i am not using MySQL partitions because i have a mysql version 5.0. 注意:我没有使用MySQL分区,因为我有一个mysql版本5.0。

Now if i have code that automatically created a t3 table i would have to modify the merge table to add this to the union? 现在,如果我有自动创建t3表的代码,我将不得不修改合并表以将其添加到联合? Would i use an ALTER query for that? 我会使用ALTER查询吗?

From the documentation : 文档

To remap a MERGE table to a different collection of MyISAM tables, you can use one of the following methods: 要将MERGE表重新映射到不同的MyISAM表集合,可以使用以下方法之一:

  • DROP the MERGE table and re-create it. DROP MERGE表并重新创建它。
  • Use ALTER TABLE tbl_name UNION=(...) to change the list of underlying tables. 使用ALTER TABLE tbl_name UNION=(...)更改基础表的列表。

Beginning with MySQL 5.0.60, it is also possible to use A LTER TABLE ... UNION=() (that is, with an empty UNION clause) to remove all of the underlying tables. MySQL 5.0.60开始,也可以使用A LTER TABLE ... UNION=() (即使用空的UNION子句)来删除所有基础表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM