Jump to content

query theory!


mdnghtblue

Recommended Posts

(using mysql 5.0) If two queries are sent to the database at the same time, trying to update the same field, what would happen? I think this is what my problem is, because I keep having discrepancies in certain fields.

 

Say I have three fields:

land

freeland

buildings

 

freeland must always equal land-buildings. And most of the time, it does. But every so often differences happen, and I think it's because two queries are trying to update the same fields at the same time. Is it possible that that's even the problem? Is there a way to fix it? (besides periodically recalculating)

Link to comment
Share on other sites

If you are doing a SELECT query to get a value, then doing a separate UPDATE query, then yes, you can have concurrent accesses change the value incorrectly.

 

You should do this in a single UPDATE query. Post your code to get specific help with it.

 

Also. you should not have a column that is based on values in other columns. This results in duplicated data. Any time you want to know freeland, just SELECT land - buildings

Link to comment
Share on other sites

  • 1 month later...

If you are doing a SELECT query to get a value, then doing a separate UPDATE query, then yes, you can have concurrent accesses change the value incorrectly.

 

You should do this in a single UPDATE query. Post your code to get specific help with it.

 

Also. you should not have a column that is based on values in other columns. This results in duplicated data. Any time you want to know freeland, just SELECT land - buildings

 

I have to do two UPDATES because there are two users in different places, doing different things.

 

I think I want to just scratch the freeland field and do the calculations, but I want to make sure it's worth it. Will doing the subtractions necessary to get the value take much (noticeably) longer than just accessing a database field?

Link to comment
Share on other sites

Two things can't happen at the exact same instantaneous moment in time.

I wasn't aware that the universe had a queueing system. Tell us more.

 

here is some literature for you:

http://en.wikipedia.org/wiki/Queueing_theory

 

If you like I can send you of my airplane boarding model using it that was top 2% in comap's competition 2 years ago.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.