Very long MYSQL Query string help
#1

Done it, but is there anyway to get rid of this?

Code:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:           5700 bytes
Code size:           483132 bytes
Data size:          1421108 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements: 1926324 bytes
Reply
#2

What kind of query holds 16k characters?
Are you saving 1000 variables at once during OnPlayerDisconnect, using only 1 query?
Reply
#3

Sure, will show
Code:
mysql_format(mysql, query, sizeof(query),
	"UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f, `Weap0` = %d, `AWeap0` = %d, `Weap1` = %d, `AWeap1` = %d, `Weap2` = %d, `AWeap2` = %d, `Weap3` = %d, `AWeap3` = %d, `Weap4` = %d, `AWeap4` = %d, `Weap5` = %d, `AWeap5` = %d, `Weap6` = %d, `AWeap6` = %d, `Weap7` = %d, `AWeap7` = %d, `Weap8` = %d, `AWeap8` = %d, `Weap9` = %d, `AWeap9` = %d, `Weap10` = %d, `AWeap10` = %d, `Weap11` = %d, `AWeap11` = %d, `Weap12` = %d, `AWeap12` = %d WHERE `ID` = %d",
    GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Wea0,AWea0,Wea1,AWea1,Wea2,AWea2,Wea3,AWea3,Wea4,AWea4,Wea5,AWea5,Wea6,AWea6,Wea7,AWea7,Wea8,AWea8,Wea9,AWea9,Wea10,AWea10,Wea11,AWea11,Wea12,AWea12,Player[playerid][ID]);
    mysql_tquery(mysql, query, "", "");
Reply
#4

You really need to split up that query.
When a player's money changes, it doesn't have any effect on weapondata, so why update weapondata along with it?

Have small queries that only update what needs to be updated.
You can write many small functions to update data in the script and save it to mysql at the same time.
Like this one:
PHP Code:
// This function adds the given Money and Score values to the given player
Player_Reward(playeridMoneyScore)
{
    new 
Query[128];
    
// Add the given Money and Score to the player's account
    
pData[playerid][PlayerMoney] = pData[playerid][PlayerMoney] + Money;
    
pData[playerid][PlayerScore] = pData[playerid][PlayerScore] + Score;
    
// Update money and score for this player in the player's account in MySQL
    
mysql_format(SQL_dbQuerysizeof(Query), "UPDATE playerdata SET Money = '%i', Score = '%i' WHERE ID = '%i'"pData[playerid][PlayerMoney], pData[playerid][PlayerScore], pData[playerid][SQLID]);
    
mysql_tquery(SQL_dbQuery"""");
    return 
1;

Big queries like yours are slowing mysql down alot.
Mysql needs to analyze your big query, parse each column-name, search for it, update data and do some internal sorting stuff on the data to allow faster searching (called indexing).
With big queries, this takes alot more time compared to sending a few small ones.
You're not updating ALL fields every second or so anyways.

Also, you seem to have multiple columns for weapondata.
You need to normalize your tables (split them up) and save each weapon in a separate row.
General rule is if your column-names have numbers in them, you're doing it wrong.

Also, don't restrict your script to saving everything at once upon disconnecting.
If players keep playing for hours and make alot of progress, and your server goes down unexpectedly (server crash, power failure, DDOS attack, rare bug in the script, ...), all that data would be gone and your players will get mad because they lost hours of playtime.

Save whatever changes when it changes, simple as that.
Player earns money -> save the money.
Player earns scorepoints -> save the scorepoints.
Player buys a house -> update housedata (for that house only, don't update ALL houses).

Don't keep it all gathered in memory and just save when the player leaves, it will lead to dataloss and furious players.
Reply
#5

Quote:
Originally Posted by AmigaBlizzard
View Post
You really need to split up that query.
When a player's money changes, it doesn't have any effect on weapondata, so why update weapondata along with it?

Have small queries that only update what needs to be updated.
You can write many small functions to update data in the script and save it to mysql at the same time.
Like this one:
PHP Code:
// This function adds the given Money and Score values to the given player
Player_Reward(playeridMoneyScore)
{
    new 
Query[128];
    
// Add the given Money and Score to the player's account
    
pData[playerid][PlayerMoney] = pData[playerid][PlayerMoney] + Money;
    
pData[playerid][PlayerScore] = pData[playerid][PlayerScore] + Score;
    
// Update money and score for this player in the player's account in MySQL
    
mysql_format(SQL_dbQuerysizeof(Query), "UPDATE playerdata SET Money = '%i', Score = '%i' WHERE ID = '%i'"pData[playerid][PlayerMoney], pData[playerid][PlayerScore], pData[playerid][SQLID]);
    
mysql_tquery(SQL_dbQuery"""");
    return 
1;

Big queries like yours are slowing mysql down alot.
Mysql needs to analyze your big query, parse each column-name, search for it, update data and do some internal sorting stuff on the data to allow faster searching (called indexing).
With big queries, this takes alot more time compared to sending a few small ones.
You're not updating ALL fields every second or so anyways.

Also, you seem to have multiple columns for weapondata.
You need to normalize your tables (split them up) and save each weapon in a separate row.
General rule is if your column-names have numbers in them, you're doing it wrong.

Also, don't restrict your script to saving everything at once upon disconnecting.
If players keep playing for hours and make alot of progress, and your server goes down unexpectedly (server crash, power failure, DDOS attack, rare bug in the script, ...), all that data would be gone and your players will get mad because they lost hours of playtime.

Save whatever changes when it changes, simple as that.
Player earns money -> save the money.
Player earns scorepoints -> save the scorepoints.
Player buys a house -> update housedata (for that house only, don't update ALL houses).

Don't keep it all gathered in memory and just save when the player leaves, it will lead to dataloss and furious players.
Should have known that tbh, thank you very much.... silly me XD
Reply
#6

Tutorials in my signature may help. There's one specifically for weapons.
Reply
#7

Quote:
Originally Posted by Vince
View Post
Tutorials in my signature may help. There's one specifically for weapons.
Yes, since this thread i've already looked at that tutorial of yours, was about to use it awesome information Vince!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)