29.3. The MERGE EngineThe MERGE storage engine manages tables that have the following characteristics:
MERGE tables do have some disadvantages:
The following example demonstrates how to create a MERGE table. It creates MyISAM tables that have the same structure, and populates them with information about countries in North America and South America, respectively. From these tables, a MERGE table is created that can be used to access the combined information: mysql> CREATE TABLE NACountry SELECT Code, Name -> FROM Country WHERE Continent = 'North America'; Query OK, 37 rows affected (0.01 sec) Records: 37 Duplicates: 0 Warnings: 0 mysql> CREATE TABLE SACountry SELECT Code, Name -> FROM Country WHERE Continent = 'South America'; Query OK, 14 rows affected (0.01 sec) Records: 14 Duplicates: 0 Warnings: 0 mysql> DESCRIBE NACountry; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | Code | char(3) | NO | | | | | Name | char(52) | NO | | | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> CREATE TABLE NorthAndSouth -> (Code CHAR(3) NOT NULL, Name CHAR(52) NOT NULL) -> ENGINE = MERGE UNION = (NACountry, SACountry); Query OK, 0 rows affected (0.01 sec) mysql> SELECT COUNT(*) FROM NACountry; +----------+ | COUNT(*) | +----------+ | 37 | +----------+ 1 row in set (0.00 sec) mysql> SELECT COUNT(*) FROM SACountry; +----------+ | COUNT(*) | +----------+ | 14 | +----------+ 1 row in set (0.00 sec) mysql> SELECT COUNT(*) FROM NorthAndSouth; +----------+ | COUNT(*) | +----------+ | 51 | +----------+ 1 row in set (0.00 sec) 29.3.1. MERGE Locking CharacteristicsThe MERGE storage engine uses table-level locking. However, because a MERGE table is defined in terms of other tables, MERGE locking involves locks on those tables as well:
|