Pquery & Tquery
#1

Hi guys!

What's the difference between Pquery and Tquery ?

I read the wiki, but I still don't understand quite well. Can you give me some examples?

* EXTRA QUESTION

I saw Vince doing this in his tutorial for relations between Weapons and User ID

pawn Код:
mysql_format(userDB, mysqlquery, sizeof(mysqlquery), "INSERT INTO player_weapons VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE ammo = %d;", PlayerInfo[playerid][pSQLID], weaponid, ammo, ammo);
    mysql_pquery(userDB, mysqlquery); // parallel queries
Notice the semicolon ; at the end!
pawn Код:
ammo = %d;
I've never used the semicolon in SELECT querys or anywhere inside " "
Why he used that?

Regards!
Reply
#2

Your question is pretty interesting. I'll tell you what I think, but maybe it's wrong. I'm sure somebody else will correct me if needed.

mysql_tquery processes the query on another thread, different than Pawn's main thread. Although, if one tquery is still processing, another tquery will have to wait for the first one to complete. On the other hand, mysql_pquery will send parallel queries, so if a query is keeping a thread busy, pquery will look for another free thread to do its job. The maximum number of threads that pquery will try to find is specified by that pool_size parameter of mysql_connect.

This is how I see it, maybe someone else will have another opinion.
Reply
#3

Thank you for your answer!

Okay, now I am getting the hang of it!
So, that pool_size is defined by the scripter?
I can put the value like 140?

EDIT: Are there any downsides by increasing the pool size?
Reply
#4

Never mind, I got it!
I can only use default pool size. 2 cores...

So in which situations should I use Parallel queries?

Also, can I get an anwser on EXTRA QUESTION?

Thank you!
Reply
#5

Mostly tqueries should do fine.
pqueries could be used when you're doing a MASSIVE query, which would take at least a few seconds to complete and you don't want other little queries to wait for the massive query to complete.

tqueries are put in a queue and are processed in the exact order you sent the queries.
So if your massive query would use a tquery, later queries will have to wait until that massive query has finished executing.

pqueries are processed at the same time and the first query could take more time than the second query, so the second query will be finished earlier.
There might be situations where this isn't wanted.
Sometimes you need one query to be finished first before the other so you send them right after eachother using tqueries.

Suppose you would use pqueries all the time and a new player logs in.
You ask for his password and you use a pquery to INSERT a new account into your database.
At the same time, you want new players to have a little starting cash, so you add another pquery to UPDATE his account with the given money.
Since an INSERT query takes more time, the UPDATE query will be finished earlier, but his account hasn't been created yet, so you will experience bugs.
The UPDATE query will fail as it can't find the account, then after this query failed, the account is added by the first query.

In such situations, you NEED to use tqueries as you need them to be executed in the exact order you sent the queries.


pqueries should only be used when you're doing a massive query which takes AT LEAST several seconds to complete.
Note that MySQL is pretty fast and such a query would need to gather ALOT of data, like 10.000+ rows.

I can't imagine any samp script would do such huge queries while the server is running.

Loading alot of data should be done before the server is online, and you can use mysql_query for those as well, so that you're certain your data is loaded before the server is opened up to the players, as mysql_query lets your script wait until the query is completed.
Reply
#6

Thank you PPC for your long and very educating answer!

Everything is now clear to me, except this
Код:
mysql_format(userDB, mysqlquery, sizeof(mysqlquery), "INSERT INTO player_weapons VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE ammo = %d;", PlayerInfo[playerid][pSQLID], weaponid, ammo, ammo);
Why did Vince use a semicolon in his format?
I think it's not a typo
Reply
#7

It's there to indicate the end of the query, nothing more.
It's not really required, unless you want to send multiple queries in one line.
Reply
#8

Can't thank you more!

May your wishes come true!!!

Regards!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)