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 8646801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:54:23+00:00 2026-06-12T12:54:23+00:00

UPDATE: There is now SKIP LOCKED and NOWAIT for Mysql and Postgres. Old question

  • 0

UPDATE: There is now SKIP LOCKED and NOWAIT for Mysql and Postgres.

Old question follows.


I want concurrent transactions to select a row from the table, marking it as “dirty” so that other transactions cannot select it, then performing the rest of the transaction.

I had trouble using select... for update for this purpose as the second transaction contends for the same. Please provide a minimal example for different transactions to select distinct rows.

My data is:

mysql> select * from SolrCoresPreallocated;
+----+-------------+-----+-----+
| id | used_status | sid | cid |
+----+-------------+-----+-----+
|  1 |           0 |   0 | 400 |
|  2 |           0 |   0 | 401 |
|  3 |           0 |   0 | 402 |
|  4 |           0 |   0 | 403 |
|  5 |           0 |   0 | 404 |
|  6 |           0 |   0 | 405 |
+----+-------------+-----+-----+
6 rows in set (0.00 sec)

And this stuff is not working as expected:

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

mysql> select * from SolrCoresPreallocated order by id limit 1 for update;
+----+-------------+-----+-----+
| id | used_status | sid | cid |
+----+-------------+-----+-----+
|  1 |           0 |   0 | 400 |
+----+-------------+-----+-----+
1 row in set (0.00 sec)

...set the used_status to 1
...perform the rest of the operations

…as the second transaction onward

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

mysql> select * from SolrCoresPreallocated order by id limit 1 for update;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql>  rollback;
Query OK, 0 rows affected (0.00 sec)
  • 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-12T12:54:24+00:00Added an answer on June 12, 2026 at 12:54 pm

    SELECT ... FOR UPDATE locks the row(s) in exclusive mode, which means the second select cannot proceed until the first one has completed or rolled back. This is since the second select’s result could be affected by the content of the row you’ve locked, so it needs to get a read lock to the row to check.

    If you create a UNIQUE INDEX on for example id, you could do;

    select * from SolrCoresPreallocated where id=1 for update;
    

    in the first transaction and;

    select * from SolrCoresPreallocated where id=2 for update;
    

    in the second one independently, since the unique index lets the second select find the correct row without read-locking the first one.

    EDIT: To get a “free” row as quickly as possible, the only way really is to do two transactions;

    • BEGIN/SELECT FOR UPDATE/UPDATE to busy/COMMIT to get the row.
    • BEGIN/<process row>/UPDATE to free/COMMIT to process the row and release it.

    This means that you may need compensating actions in case a process fails and rolls back the transaction that would UPDATE the row to free, but since MySQL (or standard SQL for that matter) doesn’t have a notion of “get the next unlocked row”, you don’t have many options.

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

Sidebar

Related Questions

Update 2022 There is cloud sql proxy now: https://cloud.google.com/sql/docs/mysql/sql-proxy#how-works Old Question I am currently
My requirement is that I want an object (tee) to update if there have
I want to interrupt some specific grails domain class events(read,write,delete,update).Is there any hibernate eventlistner
UPDATE - There are a lot of posts regarding the Child actions are not
Update: Is there a way to achieve what I'm trying to do in an
UPDATE Guid.TryParse is available in .NET 4.0 END UPDATE Obviously there is no public
Is there any way to update nested documents by id or some other field?
Is there any way to update my beta testing application on windows phone marketplace?
Is there is any way to update shared OR(Object Repository) in QTP without having
If you came here from Google looking for model to dict, skip my question,

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.