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
11
votes
6 answers

When MyISAM is better than InnoDB?

Sometimes I got asked on some interviews: what benefits does InnoDB have against MyISAM and when MyISAM is better than InnoDB? It's all clear about the first part of question: InnoDB is transaction compliant, row-level blocking instead of…
Vadim Samokhin
  • 3,378
  • 4
  • 40
  • 68
11
votes
6 answers

Suggest Plan to Query Optimiser

There are times I can use force index option to use particular index on a query to make the query faster. Then after some times the data in that table may change. And the force index which I used may not be the right index search for that query. My…
vinieth
  • 1,204
  • 3
  • 16
  • 34
11
votes
1 answer

insufficient history for index

In MySQL log, there is one error 'InnoDB: insufficient history for index 0' I don't know why it occurs. I have googled and found this: InnoDB: If a transaction was started with a consistent snapshot, then new indexes were added to the table while…
Vipin Jain
  • 3,686
  • 16
  • 35
11
votes
2 answers

Row Level Locking in Mysql

I have 5 rows in a table (1 to 5). I want row 2 lock for some update and in the meanwhile if someone tries to update row 4, then he should able to update. I am trying this with code below, but I feel its placing lock on table level rather than row…
Irfan Ahmad
  • 119
  • 1
  • 2
  • 9
11
votes
5 answers

MySQL InnoDB "SELECT FOR UPDATE" - SKIP LOCKED equivalent

Is there any way to skip "locked rows" when we make "SELECT FOR UPDATE" in MySQL with an InnoDB table? E.g.: terminal t1 mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> select id from mytable ORDER BY id ASC limit 5 for…
Bast
  • 661
  • 2
  • 7
  • 23
11
votes
2 answers

MySQL transaction and trigger

I quickly browsed MySQL manual but didn't find the exact information about my question. Here is my question: if I have a InnoDB table A with two triggers triggered by 'AFTER INSERT ON A' and 'AFTER UPDATE ON A'. More specifically, For example: one…
WilliamLou
  • 1,914
  • 6
  • 27
  • 38
11
votes
1 answer

Keeping data plus index-data in memory - InnoDB vs. MyISAM

Assume a database consisting of 1 GB of data and 1 GB of index data. To minimize disk IO and hence maximize performance I want to allocate memory to MySQL so that the entire dataset including indexes can be kept in RAM (assume that the machine has…
knorv
  • 49,059
  • 74
  • 210
  • 294
11
votes
2 answers

SELECT FOR UPDATE with INSERT INTO

I have some kind of game lottery up in the making, and I've got advice to switch from MyISAM to the InnoDB and start using FOR UPDATE so a lottery ticket (ranging from 1 - 16) could not be sold more than once. Now I'm wondering, how this FOR UPDATE…
lt.kraken
  • 1,287
  • 3
  • 10
  • 27
11
votes
0 answers

How does MySQL store rows on disk?

I'm looking for documentation on how MySQL stores data on disk, in particular InnoDB and MyISAM. I took a database course back in college (and wrote a primitive database) so I have a general idea. I could ask a bunch of questions here about how…
Ken
  • 1,066
  • 1
  • 10
  • 17
11
votes
2 answers

MySQL query randomly hangs on 'sending data' status?

I am using a MySQL 5.5.25 server, and InnoDB for my databases. Quite often the CPU of the server is working at 100% due to a mysqld process for roughly a minute. Using SHOW PROCESSLIST: Command | Time | State | Info Query | 100 | Sending…
Yeti
  • 2,647
  • 2
  • 33
  • 37
11
votes
3 answers

effective innodb_lock_wait_timeout value check

I have a table with lakhs of rows. Now, suddenly I need to create a varchar column index. Also, I need to perform some operations using that column. But its giving innodb_lock_wait_timeout exceeded error. I googled it and changed the value of…
Sourabh
  • 1,757
  • 6
  • 21
  • 43
11
votes
1 answer

How to properly handle InnoDB deadlocks in Java/JDBC?

I am working on a theory basis here, I want to make sure all my bases are covered. I have read quite a bit into InnoDB with Java and how deadlocks can occur no matter what query you are running. Although I am pretty clued in with the theory and best…
xLite
  • 1,441
  • 3
  • 15
  • 28
11
votes
1 answer

Is it practical to store string columns in indexes?

Suppose we have this example structure/data: @see fiddle at http://sqlfiddle.com/#!8/1f85e/1 -- SET GLOBAL innodb_file_per_table=1; DROP TABLE IF EXISTS mysql_index_reading_myisam; CREATE TABLE IF NOT EXISTS mysql_index_reading_myisam ( id INT…
gaRex
  • 4,144
  • 25
  • 37
11
votes
3 answers

mysql "drop database" takes time -- why?

mysql5.0 with a pair of databases "A" and "B", both with large innodb tables. "drop database A;" freezes database "B" for a couple minutes. Nothing is using "A" at that point, so why is this such an intensive operation? Bonus points: Given that we…
JBB
  • 4,543
  • 3
  • 24
  • 25
11
votes
1 answer

difference between innodb_log_buffer_size and innodb_buffer_pool_size

Difference between innodb_log_buffer_size and innodb_buffer_pool_size in mysql? Is the innodb_log_buffer_size is given out of innodb_buffer_pool_size. What data do innodb_log_buffer_size and innodb_buffer_pool_size contains.
user2030415