Jump to content
MakeWebGames

What would be better to use?


Recommended Posts

When i ask better, mainly speed concern as both queries should do the exact same thing.

 

UPDATE users u LEFT JOIN userstats us ON u.userid = us.userid
SET u.money = u.money + 1, u.crystals = u.crystals + 1, us.IQ = us.IQ + 1
WHERE u.userid = $userid

 

or this one...

 

UPDATE users, userstats
SET users.money = users.money + 1, users.crystals = users.crystals +1, userstats.IQ = userstats.IQ + 1
WHERE users.userid = $userid AND userstats.userid = $userid
Link to comment
Share on other sites

Re: What would be better to use?

I ran a test on those.

My one:

UPDATE `users` `u`,`userstats` `us` SET `money` = (`money` + 1),`crystals` = (`crystals` + 1), `IQ` = (`IQ` + 1) WHERE `u`.`userid` = 3 AND `us`.`userid` = 3

Result: Rows Affected: 2 (Took 0.0009 seconds)

Your first one:

UPDATE users u LEFT JOIN userstats us ON u.userid = us.userid
SET u.money = u.money + 1, u.crystals = u.crystals + 1, us.IQ = us.IQ + 1
WHERE u.userid = 3

Result: Rows Affected: 2 (Took 0.0011 seconds)

Your Second One:

UPDATE users, userstats
SET users.money = users.money + 1, users.crystals = users.crystals +1, userstats.IQ = userstats.IQ + 1
WHERE users.userid = 3 AND userstats.userid = 3

Result: Rows Affected: 2 (Took 0.0010 seconds)

Seems like each one has got different speeds to them.

Then again ran a test on all 3 again and results ended up as follows:

1st => Mine. 5 Seconds

2nd => Yours First. 7 Seconds

3rd => Yours Second. 9 Seconds

Link to comment
Share on other sites

Re: What would be better to use?

The queries are just an example, though i will need to run similar queries on tables with a few thousand entries. I made a few tests, and even second query is faster for lower amount of queries, as they grow... second one becomes painfully slow!

Link to comment
Share on other sites

Re: What would be better to use?

How would

 

UPDATE `users` u LEFT OUTER JOIN `userstats` us ON u.`userid`=us.`userid`
SET u.`money`=u.`money`+'1', u.`crystals`=u.`crystals`+'1', us.`IQ`=us.`IQ`+'1'
WHERE u.`userid`='1'

or even

UPDATE `users` u INNER JOIN `userstats` us ON u.`userid`=us.`userid`
SET u.`money`=u.`money`+'1', u.`crystals`=u.`crystals`+'1', us.`IQ`=us.`IQ`+'1'
WHERE u.`userid`='1'

 

perform?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...