MENU
MERGE
The MERGE storage engine, also known as MRG_MyISAM, presents a collection of identical MyISAM tables as a single virtual table. "Identical" means every underlying table has the same column and index definitions. See Storage Engines for how it compares to the others.| 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; |
| Two identically-structured MyISAM tables combined into a single queryable MERGE table. INSERT_METHOD=LAST directs new rows inserted through total into t2, the last table in the UNION list. |
| Feature | MERGE |
| Storage limits | Sum of the underlying MyISAM tables (each up to 256TB) |
| Transactions | No |
| Locking granularity | Table |
| MVCC | No |
| Geospatial data type support | No |
| Geospatial indexing support | No |
| B-tree indexes | Yes |
| T-tree indexes | No |
| Hash indexes | No |
| Full-text search indexes | No |
| Clustered indexes | No |
| Data caches | No |
| Index caches | Yes |
| Compressed data | No |
| Encrypted data | No |
| Cluster database support | No |
| Replication support | Yes |
| Foreign key support | No |
| Backup / point-in-time recovery | No (back up the underlying MyISAM tables instead) |
| Query cache support | Yes |
| Update statistics for data dictionary | No |
CREATE TABLE sales_2023 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
amount DECIMAL(10,2)
) ENGINE = MyISAM;
CREATE TABLE sales_2024 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
amount DECIMAL(10,2)
) ENGINE = MyISAM;
CREATE TABLE sales_all (
id INT NOT NULL AUTO_INCREMENT,
amount DECIMAL(10,2),
INDEX(id)
) ENGINE = MERGE UNION = (sales_2023, sales_2024) INSERT_METHOD = LAST;
INSERT INTO sales_all (amount) VALUES (150.00); -- lands in sales_2024
SELECT SUM(amount) FROM sales_all; -- queries both years at onceQuery OK, 1 row affected
| SUM(amount) |
|---|
| 150.00 |