Search the MySQL manual:

1.8.4.3 Transactions and Atomic Operations

MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the InnoDB and BDB Transactional storage engines. InnoDB provides full ACID compliance. See section 7 MySQL Table Types.

The other non-transactional table types (such as MyISAM) in MySQL Server follow a different paradigm for data integrity called ``Atomic Operations.'' In transactional terms, MyISAM tables effectively always operate in AUTOCOMMIT=1 mode. Atomic operations often offer comparable integrity with higher performance.

With MySQL Server supporting both paradigms, the user is able to decide if he needs the speed of atomic operations or if he needs to use transactional features in his applications. This choice can be made on a per-table basis.

As noted, the trade off for transactional vs. non-transactional table types lies mostly in performance. Transactional tables have significantly higher memory and diskspace requirements, and more CPU overhead. That said, transactional table types such as InnoDB do of course offer many unique features. MySQL Server's modular design allows the concurrent use of all these different storage engines to suit different requirements and deliver optimum performance in all situations.

But how does one use the features of MySQL Server to maintain rigorous integrity even with the non-transactional MyISAM tables, and how do these features compare with the transactional table types?

  1. In the transactional paradigm, if your applications are written in a way that is dependent on the calling of ROLLBACK instead of COMMIT in critical situations, transactions are more convenient. Transactions also ensure that unfinished updates or corrupting activities are not committed to the database; the server is given the opportunity to do an automatic rollback and your database is saved. MySQL Server, in almost all cases, allows you to resolve potential problems by including simple checks before updates and by running simple scripts that check the databases for inconsistencies and automatically repair or warn if such an inconsistency occurs. Note that just by using the MySQL log or even adding one extra log, one can normally fix tables perfectly with no data integrity loss.
  2. More often than not, critical transactional updates can be rewritten to be atomic. Generally speaking, all integrity problems that transactions solve can be done with LOCK TABLES or atomic updates, ensuring that you never will get an automatic abort from the server, which is a common problem with transactional database systems.
  3. Even a transactional system can lose data if the server goes down. The difference between different systems lies in just how small the time-lap is where they could lose data. No system is 100% secure, only ``secure enough.'' Even Oracle, reputed to be the safest of transactional database systems, is reported to sometimes lose data in such situations. To be safe with MySQL Server, whether using transactional tables or not, you only need to have backups and have the binary logging turned on. With this you can recover from any situation that you could with any other transactional database system. It is, of course, always good to have backups, independent of which database system you use.

The transactional paradigm has its benefits and its drawbacks. Many users and application developers depend on the ease with which they can code around problems where an abort appears to be, or is necessary. However, even if you are new to the atomic operations paradigm, or more familiar with transactions, do consider the speed benefit that non-transactional tables can offer on the order of three to five times the speed of the fastest and most optimally tuned transactional tables.

In situations where integrity is of highest importance, MySQL Server offers transaction-level reliability and integrity even for non-transactional tables. If you lock tables with LOCK TABLES, all updates will stall until any integrity checks are made. If you only obtain a read lock (as opposed to a write lock), reads and inserts are still allowed to happen. The new inserted records will not be seen by any of the clients that have a read lock until they release their read locks. With INSERT DELAYED you can queue inserts into a local queue, until the locks are released, without having the client wait for the insert to complete. See section 6.4.4 INSERT DELAYED Syntax.

``Atomic,'' in the sense that we mean it, is nothing magical. It only means that you can be sure that while each specific update is running, no other user can interfere with it, and there will never be an automatic rollback (which can happen with transactional tables if you are not very careful). MySQL Server also guarantees that there will not be any dirty reads.

Following are some techniques for working with non-transactional tables:

User Comments

Posted by Yudy Patrianto on Monday May 5 2003, @8:27pm[Delete] [Edit]

Saya Pemakai Baru MySQL, sebelumnya selama bertahun-tahun
saya menggunakan SQL Server sebagai Database.
Ketika Saya Mencoba MySQL pertama kali, dibenak saya
"Inilah Database Server yang saya cari ? "

Saya telah mencoba untuk connect dengan program visual
basic saya, dan berencana untuk menggunakannya pada
proyek-proyek koputerisasi saya.

MySQL....Hebat !

Posted by Scott Marlowe on Wednesday May 14 2003, @11:45pm[Delete] [Edit]

I'm not sure about the claim of innodb providing full ACID transactions. The C in ACID stands for consistency. Which means you can't insert a NULL and get a default value inserted. Even if the insert checking is turned on at compile time, I'm pretty sure you have to support check constraints to qualify for the C part of ACID, and currently MySQL simply ignores check constraints.

Is there a plan to implement check constraints and turn on insert value checking by default?

Without write-ahead logging of some kind it is also hard to believe you can fulfill the D part, durability. But I'm not familiar enough with innodb tables to say one way or the other. Do they employ some form of write ahead logging that survives sudden power down safely and all that?

Add your own comment.