mdnghtblue Posted July 9, 2008 Share Posted July 9, 2008 (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) Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2008 Share Posted July 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-585792 Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 Two things can't happen at the exact same instantaneous moment in time. Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-585804 Share on other sites More sharing options...
fenway Posted July 10, 2008 Share Posted July 10, 2008 Why have 2 fields if they're always going to be the same? I'm confused. Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-586887 Share on other sites More sharing options...
Barand Posted July 10, 2008 Share Posted July 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-587065 Share on other sites More sharing options...
mdnghtblue Posted August 19, 2008 Author Share Posted August 19, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-619714 Share on other sites More sharing options...
cooldude832 Posted August 19, 2008 Share Posted August 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/113977-query-theory/#findComment-619797 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.