Table of Contents
With MySQL 5.1, MySQL AB has introduced a new pluggable storage engine architecture that allows storage engines to be loaded into a running MySQL server.
This chapter describes the pluggable storage engine architecture and provides an overview of the various storage engines provided with MySQL along with instructions on how to assign storage engines to tables and plug and unplug storage engines.
The MySQL pluggable storage engine architecture allows a database professional to select a specialized storage engine for a particular application need while being completely shielded from the need to manage any specific application coding requirements. The MySQL server architecture isolates the application programmer and DBA from all of the low-level implementation details at the storage level providing a consistent and easy application model and API. So while there are different capabilities across different storage engines, the application is shielded from these.
Graphically depicted, the MySQL pluggable storage engine architecture looks like the following:
The pluggable storage engine architecture provides a standard set of management and support services that are common among all underlying storage engines. The storage engines themselves are the components of the database server that actually perform actions on the underlying data that is maintained at the physical server level.
This efficient and modular architecture provides huge benefits for those wishing to specifically target a particular application need – such as data warehousing, transaction processing, high availability situations, etc. – while enjoying the advantage of utilizing a set of interfaces and services that are independent of any one storage engine.
The application programmer and DBA interact with the MySQL database through Connector APIs and service layers that are above the storage engines. If application changes bring about requirements that demand the underlying storage engine change, or that one or more additional storage engines be added to support new needs, no significant coding or process changes are required to make things work. The MySQL server architecture shields the application from the underlying complexity of the storage engine by presenting a consistent and easy to use API that applies across storage engines.
A MySQL pluggable storage engine is the component in the MySQL database server that is responsible for performing the actual data I/O operations for a database as well as enabling and enforcing certain feature sets that target a specific application need. A major benefit of using specific storage engines is that you are only delivered the features needed for a particular application, and therefore you have less system overhead in the database, with the end result being more efficient and higher database performance. This is one of the reasons that MySQL has always been known to have such high performance, matching or beating proprietary monolithic databases in industry standard benchmarks.
From a technical perspective, what are some of the unique supporting infrastructure components that are in a storage engine? Some of the key differentiations include:
Concurrency – some applications have more
granular lock requirements (such as row-level locks) than
others. Choosing the right locking strategy can reduce
overhead and therefore help with overall performance. This
area also includes support for capabilities like multi-version
concurrency control or “snapshot” read.
Transaction Support – not every
application needs transactions, but for those that do, there
are very well defined requirements like ACID compliance and
more.
Referential Integrity – the need to have
the server enforce relational database referential integrity
through DDL defined foreign keys.
Physical Storage – this involves
everything from the overall page size for tables and indexes
as well as the format used for storing data to physical disk.
Index Support – different application
scenarios tend to benefit from different index strategies, and
so each storage engine generally has its own indexing methods,
although some (like B-tree indexes) are common to nearly all
engines.
Memory Caches – different applications
respond better to some memory caching strategies than others,
so while some memory caches are common to all storage engines
(like those used for user connections, MySQL’s high-speed
Query Cache, etc.), others are uniquely defined only when a
particular storage engine is put in play.
Performance Aids – includes things like
multiple I/O threads for parallel operations, thread
concurrency, database checkpointing, bulk insert handling, and
more.
Miscellaneous Target Features – this may
include things like support for geospatial operations,
security restrictions for certain data manipulation
operations, and other like items.
Each set of the pluggable storage engine infrastructure components are designed to offer a selective set of benefits for a particular application. Conversely, avoiding a set of component features helps steer clear of unnecessary overhead. So it stands to reason that understanding a particular application’s set of requirements and selecting the proper MySQL storage engine can have a dramatic impact on overall system efficiency and performance.
The various storage engines provided with MySQL are designed with different use-cases in mind. In order to use the pluggable storage architecture effectively, it is good to have an idea of the benefits and drawbacks of the various storage engines.
The following table provides an overview of the storage engines provided with MySQL:
The following storage engines are the most commonly used:
MyISAM - the default MySQL pluggable
storage engine and the one that is used the most in Web, data
warehousing, and other application environments. Note that a
MySQL server's default storage engine can easily be changed by
altering the STORAGE_ENGINE configuration variable.
InnoDB - used for transaction processing
applications, and sports a number of features including ACID
transaction support.
BDB - an alternative transaction engine to
InnoDB that supports COMMIT, ROLLBACK, and other transactional
features.
Memory - stores all data in RAM for
extremely fast access in environments that require quick look
ups of reference and other like data.
Merge - allows a MySQL DBA or developer to
logically group together a series of identical MyISAM tables
and reference them as one object. Good for VLDB environments
like data warehousing.
Archive - provides the perfect solution for
storing and retrieving large amounts of seldom-referenced
historical, archived, or security audit information.
Federated - offers the ability to link
together separate MySQL servers to create one logical database
from many physical servers. Very good for distributed or data
mart environments.
Cluster/NDB - the Clustered database engine
of MySQL that is particularly suited for applications with
high performance lookup needs that also require the highest
possible degree of uptime and availability.
Other - other storage engines include CSV
(references comma-separated files as database tables),
Blackhole (for temporarily disabling application input to the
database) and an Example engine that helps jump start the
process of creating custom pluggable storage engines.
It is important to remember that you are not restricted to using the same storage engine for an entire server or schema: you can use a different storage engine for each table in your schema.
For detailed information on the storage engines included with MySQL, see Section 14.4, “Choosing a Storage Engine”.
Storage engines can be designated either when creating new tables
or through the use of an ALTER TABLE statement.
To specify a storage engine when creating a table, use the
ENGINE parameter:
CREATE TABLE engineTest( id INT ) ENGINE = MyISAM;
To change the storage engine of an existing table, use the
ALTER TABLE statement:
ALTER TABLEengineTestENGINE =ARCHIVE;
Transactions are supported by the following storage engines:
InnoDB - Supports transactions through
MVCC, allows for COMMIT,
ROLLBACK, and savepoints.
NDB - Supports transactions through MVCC,
allows for COMMIT and
ROLLBACK.
BDB - Supports transactions, allows for
COMMIT and ROLLBACK.
Before a storage engine can be used, the storage engine plugin
must be loaded into mysql using the INSTALL
PLUGIN statement. For example, to load the example
engine you would first load the ha_example.so module:
INSTALL PLUGINha_exampleSONAME 'ha_example.so';
The .so file must be located in the MySQL
server library directory (typically
installdir/lib).
To unplug a storage engine, use the UNINSTALL
PLUGIN statement:
UNINSTALL PLUGIN ha_example;
If you unplug a storage engine that is being used by existing tables, those tables will not be accessible. Ensure that there are no tables using a storage engine before you unplug the storage engine.