MySQL query: What is faster?
#1

Well, I was scripting, and suddently something came to my mind, what would be faster:
Calling 2 query's
pawn Code:
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?
Reply
#2

Only one query, with more cells.
Reply
#3

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.
Reply
#4

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.
Reply
#5

Quote:

[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
Reply
#6

Quote:
Originally Posted by Y_Less
View Post
Two queries are half the speed of one - funny that...
It makes sense...
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
Two queries are half the speed of one - funny that...
What?
Code:
[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.
Reply
#8

Quote:
Originally Posted by VincentDunn
View Post
What?
Code:
[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... -_-
Reply
#9

Quote:
Originally Posted by VincentDunn
View Post
What?
Code:
[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...
Quote:
Originally Posted by FireCat
View Post
I tested it with 300 queries
4char.
Reply
#10

Quote:
Originally Posted by SuperViper
View Post
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)