Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:22:28+00:00 2026-06-08T00:22:28+00:00

As per the MySql documentation, MySql supports Multiple granularity locking(MGL). case-1 Opened terminal-1: //

  • 0

As per the MySql documentation, MySql supports Multiple granularity locking(MGL).

case-1

Opened terminal-1:

// connected to mysql

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

mysql> select id, status from tracking_number limit 5 for update;
+----+--------+
| id | status |
+----+--------+
|  1 |      0 |
|  2 |      0 |
|  3 |      0 |
|  4 |      0 |
|  5 |      0 |
+----+--------+
5 rows in set (0.00 sec)
mysql> 

left it opened and opened terminal-2:

// connected to mysql

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

mysql> select id, status from tracking_number limit 5 for update;

<!-- Hangs here. and after some time it says-->
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

Though there are plenty of rows to retrieve, T2 waits until t1 completes.

case-2

Left terminal-1 as is.Now in terminal-2:

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

<!-- case 2.1 -->
mysql> select id, status from tracking_number where id=1;
+----+--------+
| id | status |
+----+--------+
|  1 |      0 |
+----+--------+
1 row in set (0.00 sec)

mysql> select id, status from tracking_number where id=2;
+----+--------+
| id | status |
+----+--------+
|  2 |      0 |
+----+--------+
1 row in set (0.00 sec)

<!-- case 2.2 -->
mysql> select * from tracking_number where id=2 for update;
<!-- Hangs here. and after some time -->
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
  1. But why in case 1, T2 waits for the same set of rows that T1 has locked?

  2. Does it mean the unbounded select query (even with limint parameter. I have tried with different range also) blocks the entire table?

  3. Is there any way to let transactions to lock independently without specifying the field of the record(i.e., without using where field=value)?
  4. Generally (or as per Java concurrent locking), write lock is exclusive and read is not. In case 2.1, though the records are in write lock mode, how T2 can read the same records? Since this is allowed what is the point in locking it?
  5. Case 2.2 is understood.

Opened a terminal and a transaction:

mysql> update tracking_number set status=4 where status=0 limit 5;
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5  Changed: 5  Warnings: 0

Left it there and opened another terminal and transaction:

mysql> update tracking_number set status=5 where status=0 limit 5; 

T2 did not succeed until i committed (or rollback) T1.

  1. Why is this behavior?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:22:29+00:00Added an answer on June 8, 2026 at 12:22 am

    Let me go through your cases and explain how these locks work:

    1 case

    T1 wants to update some rows in your test table. This transaction puts IX lock on all table and X lock on the first 5 rows.

    T2 wants to update some rows in your test table. This transaction puts IX (because IX compatible with IX) lock on all table and tries to first 5 rows but it can’t do it because X is not compatible with X

    So we are fine.

    2.1 case

    T1 wants to update some rows in your test table. This transaction put IX lock on all table and X lock on the first 5 rows.

    T2 wants to select some rows from your test table. And it does not place any locks (because InnoDB provides non-locking reads)

    2.1 case

    T1 wants to update some rows in your test table. This transaction put IX lock on all table and X lock on the first 5 rows.

    T2 wants to update (select for update)some rows from your test table. Place IS on the whole table and tries to get S lock on the row and fails because X and S are uncompatible.


    Also always be aware of isolation level: different level cause different mechanism to free/acquire locks

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please note that this question is not about the mysql query per se, but
Please note that this question is not about the mysql query per se, but
If I have MySQL query like this, summing word frequencies per week: SELECT SUM(`city`),
As per PHP documentation, mysql needs to be enabled with PHP. http://www.php.net/manual/en/mysql.installation.php PHP 5.0.x,
The site I am developing in php makes many MySQL database requests per page
Per the documentation , String.Format will throw a FormatException if either (A) the format
As per $query = mysql_query(SELECT * FROM `pages` WHERE parent_id = '0' AND menu_location
In MySQL, I am converting a table from a single row per item type
I have a MySQL database with some URLs in it. One URL per row.
Hunting internationalization bugs here. Does mysql has a variable which can be set per

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.