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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:41+00:00 2026-05-16T23:27:41+00:00

I’m using transactions for managing data across several MySQL InnoDB tables in a reasonably

  • 0

I’m using transactions for managing data across several MySQL InnoDB tables in a reasonably complex web application. Briefly, a given transaction works as follows:

  1. Data is read from a row in a “user_point_totals” table
  2. Various machinations calculate what the user’s new point total should be
  3. A new entry is created in the “user_point_totals” table reflecting the updated total

Let’s say that user A performs some action that has point-related ramifications, step 1 is executed, that thread of execution reads the user’s point total into memory, and the application begins calculating the new total. Meanwhile, user B performs an action that has implications for user A’s point total, and another transaction begins; however, the first transaction has not yet completed, so the second thread gets the same point total value as a starting point as the first transaction (from the same table row). Subsequently, transaction 1 completes and creates a new user point total with its perception of what the new value should be, and shortly thereafter, transaction 2 completes and creates a new row for the user’s point total as well. However, the second transaction’s point total is now incorrect, as it fails to account for the new total created by transaction 1.

My questions are:

  • Is this scenario impossible due to the atomic nature of transactions, which I apparently don’t understand as well as I should?
  • If not, how does one ensure that data integrity exists in these sorts of situations?

Thanks for your consideration!

  • 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-05-16T23:27:42+00:00Added an answer on May 16, 2026 at 11:27 pm

    On the technical level, you could use the table-locking (or row-locking) abilities of MySQL. That would allow you to detect if someone is actually computing something using the table. On the other hand, this technique would require many considerations like what happens if a process crash, etc.

    On the practical level, though, I doubt you would want to do something like this.
    Operators like sum() or avg() in MySQL are already optimised for this need. If what you need to do is a sum over some columns of a table and get the answer in a table, you could use a view or create a temporary table (possible but slower). You should not have a column that contains a value that could be computed from other columns. This situation leads to incongruities since it is unclear which field is true if the relation doesn’t balance. (Is it an input script error or a deliberate re-use of the field by some programmer?)

    On a second note, be sure to use InnoDB tables on your MySQL instance, otherwise your system won’t be fully ACID-compilant, meaning you won’t get the atomicity nature you need.

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

Sidebar

Related Questions

No related questions found

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.