DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > InnoDB Locks and Transaction Isolation Level

InnoDB Locks and Transaction Isolation Level

What is the difference between InnoDB locks and transaction isolation level? We’ll discuss it in this post.

Sveta Smirnova user avatar by
Sveta Smirnova
·
Jun. 22, 16 · Database Zone · Tutorial
Like (1)
Save
Tweet
2.21K Views

Join the DZone community and get the full member experience.

Join For Free

InnoDB locks and transaction isolation

Recently, I received a question from a user about one of my earlier blog posts. Because it wasn't sent as a comment, I will answer it here. The question:

> I am reading your article:
> https://www.percona.com/resources/technical-presentations/troubleshooting-locking-issues-percona-mysql-webinar

> Full table scan locks whole table.

> Some bad select (read) query can do full table scan on InnoDB, does it lock whole table please?

> My understanding was that SELECT (read) blocks another DML only in MyISAM.

To answer this question, we need to understand two different concepts: locking and transaction isolation level.

In the default transaction isolation mode for InnoDB,  REPEATABLE READ and the lower TRANSACTION ISOLATION levels, SELECT  doesn't block any DML unless it uses  SELECT...FOR UPDATE or SELECT...LOCK IN SHARE MODE. On slide 20 (31) of my presentation, I use the  SELECT...FOR UPDATE statement (this is why a lock is seen).

However, if transaction isolation mode is SERIALIZABLE, then  SELECT can block updates. You can see this in the example below:


mysql1> set transaction isolation level serializable;

Query OK, 0 rows affected (0,00sec)

mysql1> begin;

Query OK, 0 rows affected (0,00sec)

mysql1> select * from employees join titles using (emp_no);

c936e6fc4c6cbaf77679ba5013339dff -

443308 rows in set(29,69sec)

mysql2> begin;

Query OK, 0 rows affected (0,00sec)

mysql2> update titles set title = 'Engineer' where emp_no = 15504;

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction


Regarding the different level locks set by InnoDB, I recommend that you follow the links on slide 37 (67) of the presentation, especially "InnoDB Locking Explained With Stick Figures" by Bill Karwin. InnoDB table locks are also explained very well in this blog post by Peter Zaitsev.

Threading Isolation (database systems) Database InnoDB

Published at DZone with permission of Sveta Smirnova, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Instancio: Random Test Data Generator for Java (Part 1)
  • What Is Lean Software Development?
  • Why I'm Choosing Pulumi Over Terraform
  • Servlets Listeners Introduction and Examples

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo