Questions tagged [innodb]

InnoDB is an ACID-compliant transactional storage engine for MySQL that uses MultiVersion Concurrency Control (MVCC). It has been the default storage engine for MySQL since version 5.5.5

InnoDB is an ACID-compliant transactional storage engine for MySQL that uses MultiVersion Concurrency Control (MVCC) to achieve nonblocking SELECTs and very high concurrency. It has been the default storage engine for MySQL since version 5.5.5

InnoDB's MVCC supports four levels of Transaction Isolation

  • READ-UNCOMMITTED : allows a transaction to see uncommitted changes made by other transactions. This isolation level allows dirty reads, non-repeatable reads, and phantoms to occur.
  • READ-COMMITTED : allows a transaction to see changes made by other transactions only if they've been committed. Uncommitted changes remains invisible. This isolation level allows non-repeatable reads, and phantoms to occur.
  • REPEATABLE READ (default) : ensure that is a transaction issues the same SELECT twice, it gets the same result both times, regardless of committed or uncommitted changesmade by other transactions. In other words, it gets a consistent result from different executions of the same query. In some database systems, REPEATABLE READ isolation level allows phantoms, such that if another transaction inserts new rows,in the inerbal between the SELECT statements, the second SELECT will see them. This is not true for InnoDB; phantoms do not occur for the REPEATABLE READ level.
  • SERIALIZABLE : completely isolates the effects of one transaction from others. It is similar to REPEATABLE READ with the additional restriction that rows selected by one transaction cannot be changed by another until the first transaction finishes.

You can set the Transaction Isolation Level Globally, Session-Wide, or just for one Transaction:

SET GLOBAL TRANSACTION ISOLATION LEVEL isolation_level;
SET SESSION TRANSACTION ISOLATION LEVEL isolation_level;
SET TRANSACTION ISOLATION LEVEL isolation_level;

InnoDB Architecture

InnoDB Architecture

The basic infrastructure of InnoDB centers around three major files

  • ibdata1, or System Tablespace (See InnoDB Architecture)
  • ib_logfile0 (See InnoDB Architecture)
  • ib_logfile1 (See InnoDB Architecture)

In conjunction with memory structures, ibdata1 processes info for 6 basic data structures

  • Table Data Pages
  • Table Index Pages
  • Table MetaData (List of Tablespace IDs + Misc Info)
  • MVCC Records
    • Rollback Segments
    • Undo Space
  • Double Write Buffer (Allows Background Page Writes)
  • Insert Buffer (For Collecting/Processing Changes to Secondary Indexes)

InnoDB Configurations can accommodate the following

  • Separating Table Data and Index Pages from the System Tablespace
  • Storing the System Tablespace in a Raw Disk Partition
  • Creating Multiple System Tablespace Files
  • Creating Multiple Log Files
  • and more...

There is important cache known as the InnoDB Buffer Pool. As of MySQL 5.5, you can configure multiple buffer pool instances. Prior to MySQL 5.5, there is only one buffer pool instance.

4413 questions
37
votes
5 answers

Renaming an InnoDB table without updating foreign key references to it?

I am trying to replace an InnoDB table with a new table, and I want all foreign key references that point to the old table to point to the new table. So I tried this: SET foreign_key_checks = 0; ALTER TABLE foo RENAME foo_old; ALTER TABLE foo_new…
Bart van Wissen
  • 391
  • 1
  • 3
  • 4
36
votes
3 answers

How to clean or resize the ibtmp1 file in MySQL?

MySQL 5.7 introduces a new file ibtmp1 for storing temporary data in InnoDB to increase the performance. But I have noted that its size increases continuously. On my db server its sizes increases to 92GB. Is there any way of reducing size or…
Aman Aggarwal
  • 17,619
  • 9
  • 53
  • 81
36
votes
9 answers

Database corruption with MariaDB : Table doesn't exist in engine

I'm in an environement setup, running OSX with MariaDB 10.0.12-MariaDB Homebrew I've screwed up the installation so I did completely removed MySQL and MariaDB from my setup and started again. After finishing installing MariaDB, I've reimported my…
sf_tristanb
  • 8,725
  • 17
  • 74
  • 118
35
votes
4 answers

How do I deal with this race condition in django?

This code is supposed to get or create an object and update it if necessary. The code is in production use on a website. In some cases - when the database is busy - it will throw the exception "DoesNotExist: MyObj matching query does not exist". #…
Hobhouse
  • 15,463
  • 12
  • 35
  • 43
35
votes
5 answers

How do I lock on an InnoDB row that doesn't exist yet?

How can I guarantee that I can search if a username exists in my database, then insert that username into the database as a new row without any intercept between the SELECT and INSERT statements? Almost as if I am locking on a row that doesn't…
xLite
  • 1,441
  • 3
  • 15
  • 28
34
votes
1 answer

MySQL - How to ORDER BY RELEVANCE? INNODB Table

I've got about 20,000 rows in an INNODB table called 'cards', so FULLTEXT is not an option. Please consider this table: id | name | description ---------------------------------------------------------- 1 John Smith Just…
k00k
  • 17,314
  • 13
  • 59
  • 86
33
votes
14 answers

Mysql won't start - ibdata1 corrupt? - operating system error number 13 - permissions issue

Server shutdown from power failure. Mysql will not start now. Disk is not full. Syslog is below Oct 11 15:03:31 joe mysqld_safe[24757]: started Oct 11 15:03:31 joe mysqld[24760]: 101011 15:03:31 InnoDB: Operating system error number 13 in a file…
eat_a_lemon
  • 3,158
  • 11
  • 34
  • 50
33
votes
6 answers

MySQL query caching: limited to a maximum cache size of 128 MB?

My application is very database intensive so I've tried really hard to make sure the application and the MySQL database are working as efficiently as possible together. Currently I'm tuning the MySQL query cache to get it in line with the…
knorv
  • 49,059
  • 74
  • 210
  • 294
32
votes
13 answers

Getting error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed" when starting MySQL

I found many similar question on Stackoverflow but didn't get the exact error solution. My issue is when starting MySQL service on one of the Dedicated Centos 6.5 machine, I am getting error : 141018 05:13:46 mysqld_safe Starting mysqld daemon with…
Ritesh Kumar
  • 2,183
  • 2
  • 20
  • 32
31
votes
3 answers

How to optimize COUNT(*) performance on InnoDB by using index

I have a largish but narrow InnoDB table with ~9m records. Doing count(*) or count(id) on the table is extremely slow (6+ seconds): DROP TABLE IF EXISTS `perf2`; CREATE TABLE `perf2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `channel_id` int(11)…
andig
  • 13,378
  • 13
  • 61
  • 98
31
votes
12 answers

"Unknown column in 'field list'", but column does exist

DROP TABLE IF EXISTS `transactions`; CREATE TABLE `transactions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `purchase_date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `transactions`…
Rits
  • 5,105
  • 4
  • 42
  • 53
30
votes
7 answers

Defining Composite Key with Auto Increment in MySQL

Scenario: I have a table which references two foreign keys, and for each unique combination of these foreign keys, has its own auto_increment column. I need to implement a Composite Key that will help identify the row as unique using combination of…
Nirav Zaveri
  • 687
  • 1
  • 9
  • 28
29
votes
2 answers

Why to use foreign keys with no action on delete or update

I have a question of interest: I have 2 tables in mysql with InnoDb. table tbl_a has a primary key, named a_id; table tbl_b has a primary b_id and a foreign key on tbl_a.a_id with "ON DELETE NO…
Preexo
  • 2,102
  • 5
  • 29
  • 37
28
votes
6 answers

Mysql 'Got error -1 from storage engine' error

I have a myism table 'test' which holds some out-dated data, now I want to recreate the table, all columns the same except that I changed the storage from myism to innodb. The dumped sql I used to recreate the table is like: drop table test; create…
Shawn
  • 32,509
  • 17
  • 45
  • 74
28
votes
2 answers

Why use SELECT FOR UPDATE? (MySQL)

I have a question regarding what purpose we are using SELECT FOR UDPATE? What does it do exactly? I have 2 tables, from that I need to select rows from table and update the same rows. For example: Select Query SELECT * from t1 WHERE city_id=2 for…
Duke
  • 35,420
  • 13
  • 53
  • 70