MySQL Code implementation of locking and transactions

innodblockingMySQLtransaction

I am trying to understand the internals of how MySql (using InnoDB) implements locking and transactions in code. I understand the different types and concepts of locks and transactions, but I really want to deep dive into understanding how MySQL internally implements in code. I tried going through the documentation and MySQL open source code, but could not find a good starting point. Google was no help either. All search results were talking about the different types of locks, but not how they are implemented actually. Any help here?

Best Answer

InnoDB uses MVCC as concurrency control mechanism. Yo can get some more details about it here.

Since you mentioned you want to take a look at the code, I'd suggest downloading the current source code and browsing a bit in the InnoDB directory (storage/innobase). Transactions are implemented in the trx and locking in the lock subfolder. The easiest way is probably to use an IDE and do some kind of keyword search or even build MySQL from source code and debug the execution of a query. Therefore you probably need some kind of knowledge about the interface between the MySQL core and the InnoDB storage engine. You can find these details here: https://dev.mysql.com/doc/internals/en/custom-engine.html