MySQL 40 - (p/t)query.
#1

Can I have a brief simple enough explanation to what the p stands for in pquery? As I fully understand that tquery stands for threaded queries and I'm currently looking into the MySQL's all functions to gather a better experience with the plugin.

Instead of telling me
Quote:

If you are not sure which query native to use, use mysql_tquery().

(stated int the Wiki)

I'd rather have a full answer and actually learn what the difference is other than "don't know it since you were born, then don't use it and never learn it". So please, only relative answers please.


Thanks.
Reply
#2

From me: ( https://github.com/pBlueG/SA-MP-MySQL/issues/83 )
Quote:

mysql_tquery is better because it won't block your server's thread (noticeable at huge/bad queries). It will send the query to the MySQL server and will receive the result, then the MySQL Plugin will automatically call the callback for you to manipulate the result, and after the callback was finished, the MySQL Plugin automatically deletes it for you (so your problem from 1 will be gone). The disadvantage of tquery is that, unlike pquery, it will execute only on one connection, so if another big dirty ugly query is slowly executed, it will block that new query from being executed, but still not your main server's thread ! You will receive the result when it has it. If you use pquery you can send more than one unoptimised query and you will receive the results when they are received from each query. (I don't recommend you to use it just because you don't know how to make some queries optimised, you still have to optimise them)

pquery = parallel query, the queries can be executed in parallel, think of it like multiple tquery connections, it won't have just one queue for it, but it will have more, the value you can specify in mysql_set_option with the POOL_SIZE parameter.

Doing something like
Код:
mysql_pquery( ..., "SELECT * FROM `accounts`", "Callback1" );
mysql_pquery( ..., "SELECT 1", "Callback2" );
won't guarantee that the first query's callback will be executed first, they can be executed in any order. tquery keeps the order to call the callback (because they wait in the same queue, so they get executed one after one, in the order you sent them in your script), while pqueries can be executed in any order, as they have different queues.
Reply
#3

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
From me: ( https://github.com/pBlueG/SA-MP-MySQL/issues/83 )


pquery = parallel query, the queries can be executed in parallel, think of it like multiple tquery connections, it won't have just one queue for it, but it will have more, the value you can specify in mysql_set_option with the POOL_SIZE parameter.

Doing something like
Код:
mysql_pquery( ..., "SELECT * FROM `accounts`", "Callback1" );
mysql_pquery( ..., "SELECT 1", "Callback2" );
won't guarantee that the first query's callback will be executed first, they can be executed in any order. tquery keeps the order to call the callback (because they wait in the same queue, so they get executed one after one, in the order you sent them in your script), while pqueries can be executed in any order, as they have different queues.
So basically, threaded queries stack up on eachother and wait for eachother to run as in order as they were ran in code, and parallel queries will go at possibly different orders?
Reply
#4

Yes, but mysql_tquery itself runs on another thread, so if you send a huge query it won't block server's thread like mysql_query does, it will still have one queue (well, mysql_query has no queue at all, it is "instant"), so if you send a huge query then a small query, the small query will be executed really late because the huge query is still being executed, but at least the main server thread won't be locked for a while (like mysql_query does). For multiple threads/queues you need to use parallel query.

I'd suggest to use mysql_pquery as much as possible, with at least a pool size of 4 (4 queues/connections for the mysql_pquery function). It will be fine as long as you don't think that it gets executed in order. Keep in mind that.
Reply
#5

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
Yes, but mysql_tquery itself runs on another thread, so if you send a huge query it won't block server's thread like mysql_query does, it will still have one queue (well, mysql_query has no queue at all, it is "instant"), so if you send a huge query then a small query, the small query will be executed really late because the huge query is still being executed, but at least the main server thread won't be locked for a while (like mysql_query does). For multiple threads/queues you need to use parallel query.

I'd suggest to use mysql_pquery as much as possible, with at least a pool size of 4 (4 queues/connections for the mysql_pquery function). It will be fine as long as you don't think that it gets executed in order. Keep in mind that.
Alright, thank you.
Reply
#6

I was also curious about this but never asked. The last time i was reading about "pquery" i remember somebody said something like:

"it can seriously mess up your server if you don't know what you're doing"

They didn't provide an example so if one could be provided that would be great. :P
Reply
#7

Quote:
Originally Posted by Meller
Посмотреть сообщение
Alright, thank you.
You are welcome.

-------------

Quote:
Originally Posted by wallee
Посмотреть сообщение
I was also curious about this but never asked. The last time i was reading about "pquery" i remember somebody said something like:

"it can seriously mess up your server if you don't know what you're doing"

They didn't provide an example so if one could be provided that would be great. :P
Well, it can mess up some things if you expect the results to come in order. You may need to use mysql_tquery instead of mysql_pquery if you really need the results in order. For example, something like:
PHP код:
RegisterPlayerplayerid )
{
    
mysql_pquery1"INSERT INTO `users` VALUES( MY_KEY_ID, ... )""RegisteredPlayerInsert"playerid );
    
mysql_pquery1"SELECT * FROM `users` WHERE `id` = MY_KEY_ID""SelectInsertedValues"playerid );
}
function 
RegisteredPlayerInsertplayerid )
{
    
// blahblahblah
}
function 
SelectInsertedValuesplayerid )
{
    
// do things with user's row

won't be fine, as "SELECT * FROM `users` WHERE `id` = MY_KEY_ID" could be actually executed before the insert (so the result will be empty, no rows, but you may expect one row EVERYTIME ! if the SELECT is executed before INSERT, there won't be any row, otherwise it will have the full row you requested), not after it like you see in the code, for that you have to use mysql_tquery. Ideally, you can still keep using mysql_pquery, but do it in this way:
PHP код:
RegisterPlayerplayerid )
{
    
mysql_pquery1"INSERT INTO `users` VALUES( 0, ... )""RegisteredPlayerInsert"playerid );
}
function 
RegisteredPlayerInsertplayerid )
{
    
// blahblahblah
    
formatlString128"SELECT * FROM `users` WHERE `id` = %d"cache_insert_id( ) );
    
mysql_pquery1lString"SelectInsertedValues"playerid );
}
function 
SelectInsertedValuesplayerid )
{
    
// do things with user's row

Not the best real life example, but some other things may look similar to this. Most of the code can be made perfectly compatible with the mysql_pquery function, you just have to think how they may mess up if they won't get executed in order.
Reply
#8

It cleared things up, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)