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
19
votes
2 answers

MySQL InnoDB locks on joined rows

Does "SELECT ... FOR UPDATE" lock joined rows in MySQL? If so, is it possible to disable this behaviour? There is nothing about this in the documentation. I've seen that Oracle supports "SELECT ... FOR UPDATE OF table_name" where table_name is the…
Miloš Rašić
  • 2,229
  • 5
  • 24
  • 43
19
votes
3 answers

What are the max rows for MySQL table

Note: I've searched for other similar Qs here, and none of the other answered questions are even remotely similar.. With that... I have a question about MySql tables (more precisely, on specific fields from a table- i.e. tweets or updates ). So the…
avon_verma
  • 1,229
  • 3
  • 12
  • 17
19
votes
3 answers

Manage 7 billion records in a table - MYSQL

I need to save around 7.8 billion records in a Mysql table. The Table is both read and write intensive. I have to maintain at least 0.02 billion records per hour of insertion rate. While search on the table should not take more than 10 seconds. We…
Mudit bhaintwal
  • 528
  • 1
  • 7
  • 21
19
votes
1 answer

LIMIT 1 is very slow, for specific records, using different keys

I am diagnosing an intermittent slow query, and have found a strange behaviour in MySQL I cannot explain. It's choosing a different, non-optimal key strategy for one specific case, only when doing a LIMIT 1. Table (some unreferenced data columns…
scipilot
  • 6,681
  • 1
  • 46
  • 65
18
votes
5 answers

MySQL Index is bigger than the data stored

I have a database with the following stats Tables Data Index Total 11 579,6 MB 0,9 GB 1,5 GB So as you can see the Index is close to 2x bigger. And there is one table with ~7 million rows that takes up at least 99% of this. I also…
Peter Lindqvist
  • 10,122
  • 3
  • 41
  • 60
18
votes
4 answers

Speeding up conversion from MyISAM to InnoDB

I have a MySQL 1.5 GB MyISAM-table (1.0 GB data, 0.5 GB indexes) in production which I'm about to convert into InnoDB. Since the table is used in production I'd like to make the downtime as short as possible. My questions: What MySQL configuration…
knorv
  • 49,059
  • 74
  • 210
  • 294
18
votes
4 answers

MySQL: Creating table with FK error (errno 150)

I've created a model with MySQL Workbench and am now attempting to install it to a mysql server. Using File > Export > Forward Engineer SQL CREATE Script... it outputs a nice big file for me, with all the settings I ask for. I switch over to MySQL…
Peter Bailey
  • 105,256
  • 31
  • 182
  • 206
17
votes
3 answers

InnoDB table optimization w/o locking table

I've noticed a significant amount of performance gain if I repack a table (ALTER TABLE foo ENGINE = INNODB) after some period of time, or after heavy volume of INSERT/UPDATE/DELETEs. I don't know if this is because indicies etc are rebuilt, or…
Jeremy
  • 2,870
  • 3
  • 23
  • 31
17
votes
1 answer

Why am I getting deadlock in MySQL

I'm getting deadlock in my MySQL table. Only a single table is involved, and I can consistently reproduce it. It only happens when I have multiple threads running the code. Here is the table: CREATE TABLE `users_roles` ( `role_id` bigint(20) NOT…
mbarlocker
  • 1,310
  • 10
  • 16
16
votes
2 answers

When exactly MySQL locks a row on updating InnoDB table?

If I have this multiupdate query UPDATE user u INNER JOIN user_profile up ON up.user_id = u.id SET u.name = 'same_name_i_already_had', up.profile.age = 25 WHERE u.id = 10 Let's suppose the row 10 in user table already has the name…
Emilio Nicolás
  • 2,554
  • 5
  • 22
  • 29
16
votes
7 answers

How to detect deadlocks in Mysql / innodb?

I know that deadlocks occur inevitably when using transactions in Innodb and that they are harmless if they are treated properly by the application code - "just try it again", as the manual says. So I was wondering - how do you detect deadlocks?…
user1411272
16
votes
3 answers

Create innodb database in mysql

I tried to create a database type of innodb.I tried this query but its not exectuted. CREATE DATABASE "mydd" ENGINE = InnoDB I checked the configuration and it says innodb enabled. I also searched in web but only ended up with creatin innodb…
vkGunasekaran
  • 6,668
  • 7
  • 50
  • 59
16
votes
2 answers

Mysqldump --single-transaction option

Can somebody explain how mysqldump --single-transaction actually works for transactional tables, like InnoDB? I've read official documentation but still haven't glue. Does it perform per table lock instead of global lock as --lock-tables do? Also,…
Artem Dolobanko
  • 2,089
  • 2
  • 19
  • 21
16
votes
5 answers

Is it safe to use LIMIT without ORDER BY

I'm using InnoDB. I need to query to get 10 records from a table is any order. Is it safe to use LIMIT without ORDER BY? Would it be faster?
Code
  • 6,041
  • 4
  • 35
  • 75
16
votes
3 answers

How to choose optimized datatypes for columns [innodb specific]?

I'm learning about the usage of datatypes for databases. For example: Which is better for email? varchar[100], char[100], or tinyint (joking) Which is better for username? should I use int, bigint, or varchar? Explain. Some of my friends say that…
Adam Ramadhan
  • 22,712
  • 28
  • 84
  • 124