PDA

View Full Version : MySQL query: What is faster?


FireCat
19/07/2012, 03:11 PM
Well, I was scripting, and suddently something came to my mind, what would be faster:
Calling 2 query's

function SaveStats(playerid)
{
static Query[180];
format(Query,sizeof Query,"UPDATE `Accounts` SET `Money` = '%i', `Score` = '%i', `Kills` = '%i', `Deaths` = '%i', `Arrests` = '%i', `Robs` = '%i', `Wantedlevel` = '%i' WHERE `Username` = '%s' LIMIT 1",
GetPlayerMoney(playerid),
GetPlayerScore(playerid),
PInfo[playerid][Kills],
PInfo[playerid][Deaths],
PInfo[playerid][Arrests],
PInfo[playerid][Robs],
GetPlayerWantedLevel(playerid),
GetPName(playerid));
mysql_query(Query);

format(Query,sizeof Query,"UPDATE `Accounts` SET `Jailed` = '1', `Jailtime` = '%i' WHERE `Username` = '%s' LIMIT 1",
PInfo[playerid][Jailtime],
GetPName(playerid));
mysql_query(Query);
return 1;
}


Or Making it all in 1 query but creating more cells?
IE, instead of static Query[180];, putting static Query[280];
What would be faster?

IstuntmanI
19/07/2012, 03:20 PM
Only one query, with more cells.

Mauzen
19/07/2012, 05:43 PM
The process to receive, respond to and handle a query already takes a lot of time, processing it is just a relatively short job. MySQL is designed to be able to take a lot of queries, but I guess because of all those things "around" the query a single one will be faster.

Y_Less
19/07/2012, 05:50 PM
TIME IT! This is NOT hard to find out!

Kiets
19/07/2012, 06:09 PM
I don't think there should be a big difference. Just guessing, in my server there are a lot queries sent and it doesn't lag at all.

FireCat
19/07/2012, 06:29 PM
[19:37:36] [join] Firecat has joined the server (0:*.*.*.*)
[19:38:10] 2 Queries took 30352 ms
[19:38:25] 1 Query with more cells took 15019 ms
[19:38:25] [part] Firecat has left the server (0:1)
I guess I have my answer :P
Edit: I tested it with 300 queries

Y_Less
19/07/2012, 07:23 PM
Two queries are half the speed of one - funny that...

FireCat
19/07/2012, 07:26 PM
Two queries are half the speed of one - funny that...

It makes sense...

ReneG
19/07/2012, 08:10 PM
Two queries are half the speed of one - funny that...
What?
[19:38:10] 2 Queries took 30352 ms
[19:38:25] 1 Query with more cells took 15019 ms
I'm guessing that was a mistake.

EDIT didn't see firecat's updated post.

FireCat
19/07/2012, 08:24 PM
What?
[19:38:10] 2 Queries took 30352 ms
[19:38:25] 1 Query with more cells took 15019 ms
I'm guessing that was a mistake.

EDIT @FireCat - you should post the code you used. 30352ms is about 30.5 seconds...

I know... -_-

SuperViper
19/07/2012, 10:08 PM
What?
[19:38:10] 2 Queries took 30352 ms
[19:38:25] 1 Query with more cells took 15019 ms
I'm guessing that was a mistake.

EDIT @FireCat - you should post the code you used. 30352ms is about 30.5 seconds...

I tested it with 300 queries

4char.

TheArcher
25/07/2012, 09:24 AM
4char.

He has print 2 Queries took 30352 ms and 1 Query with more cells took 15019 ms looks like the first query and the second took around 45000 ms of 300 queries.