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
9
votes
1 answer

MySQL JDBC: Is there an option for automatic retry after InnoDB deadlock?

I am Working around MySQL error “Deadlock found when trying to get lock; try restarting transaction” I found out that the transaction can be safely reattempted Deadlocks are not dangerous. Just try…
700 Software
  • 85,281
  • 83
  • 234
  • 341
9
votes
3 answers

InnoDB SELECT ... FOR UPDATE statement locking all rows in a table

MySQL Server version 5.1.41 with InnoDB plugin enabled. I have the following three tables for invoices: invoices, invoice_components and invoice_expenses. Table invoices has invoice_id primary key. Both invoice_components and invoice_expenses are…
Miloš Rašić
  • 2,229
  • 5
  • 24
  • 43
9
votes
3 answers

error in your SQL syntax creating MySQL trigger

I try create trigger CREATE TRIGGER `aster_users2` after update ON `aster_users` FOR EACH ROW BEGIN update event set flag=1 where id=1; END; but got next error ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that…
Alexandr
  • 95
  • 1
  • 1
  • 3
9
votes
4 answers

How to lock table with Laravel?

I want to lock a table inside a transaction. Something like this: DB::transaction(function (){ DB::statement('LOCK TABLES important_table WRITE'); //.... }); However, the line DB::statement('LOCK TABLES important_table WRITE'); always…
Adam
  • 25,960
  • 22
  • 158
  • 247
9
votes
2 answers

At what point does MySQL INNODB fine tuning become a requirement?

I had a look at this: http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/ and: http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ These answer a lot of my questions regarding…
Barak Gall
  • 1,422
  • 12
  • 24
9
votes
4 answers

Two foreign keys, one of them not NULL: How to solve this in SQL?

I have got a table time. A time entry (1:n relationship) either belongs to a project entry or to a special_work entry. Either the project id or the special_work id must be set, neither both (exclusive or). CREATE TABLE `time` ( `id` int(20) NOT…
Blackbam
  • 17,496
  • 26
  • 97
  • 150
9
votes
1 answer

Which MySQL database engine is better for storing sessions and session data: MyISAM or InnoDB?

Pretty straightforward question. I use InnoDB for everything else, for a couple of reasons. Is it a performance hit over MyISAM for a 'high-traffic' table?
Greg
  • 7,782
  • 7
  • 43
  • 69
9
votes
1 answer

Is there any way to use MySQL Temp Tables in Go?

I have stored procedures that create temp tables. I would like to then execute a query that joins with these temp tables. The problem is that with Golang's database/sql design, the only way to ensure you get the same connection for subsequent…
william
  • 459
  • 7
  • 18
9
votes
2 answers

Rebalancing a table shard, with MySQL/InnoDB

I have a huge InnoDB table (>1TB, >1B rows) that I would like to shard: I would like to make multiple smaller independent tables from that big table. How to do that ? What I've already tried: Moving rows to partitions by SELECTing them from the…
Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
9
votes
1 answer

MYSQL innoDB SELECT FOR UPDATE with LEFT JOIN

Can somebody please tell me what happens when you LEFT JOIN tables for a SELECT FOR UPDATE using an innoDB storage engine. Do all the rows from all the joined tables get locked, or is only the primary table rows? For example, if I do.. SELECT…
Latchy
  • 309
  • 3
  • 10
9
votes
4 answers

Why is InnoDB table size much larger than expected?

I'm trying to figure out storage requirements for different storage engines. I have this table: CREATE TABLE `mytest` ( `num1` int(10) unsigned NOT NULL, KEY `key1` (`num1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; When I insert some values and…
alessandro ferrucci
  • 1,261
  • 2
  • 24
  • 48
9
votes
1 answer

innodb_lock_wait_timeout increase timeout

I am using MySQL database and trying to update records just after insert so I am getting following error ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction. So I decrease timeout by following query:- set GLOBAL…
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
9
votes
2 answers

Why is an IX-lock compatible with another IX-lock in InnoDB?

According to innodb lock mode lock type compatibility matrix X IX S IS X Conflict Conflict Conflict Conflict IX Conflict Compatible Conflict Compatible S Conflict Conflict Compatible …
http8086
  • 1,306
  • 16
  • 37
9
votes
2 answers

Load a MySQL innodb database into memory

I have a MySQL innodb database at 1.9GB, showed by following command. SELECT table_schema "Data Base Name" , sum( data_length + index_length ) / 1 048 576 as "Data Base Size in MB" , sum( data_free )/ 1 048 576 as "Free…
jack
  • 17,261
  • 37
  • 100
  • 125
9
votes
1 answer

I cannot convert myISAM to innodb

I did a wipe and restore. I backedup my current innodb tables. (mysqldump) I loaded it into the database. For some reason...the tables are now all myisam instead of innodb...weird! I try to do: ALTER TABLE xxx ENGINE=innodb; And it doesn't do…
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080