A Little mysql optimization
#1

Anyone know a way to optimize this script? It hangs a server for ~2seconds on centos. On debian i didn't have this problem.
pawn Код:
stock SavePlayer(playerid, bool:simple)
{
    new query[1536],weps[2][12],Float:coo[3],IP[20];
    GetPlayerPos(playerid,coo[0],coo[1],coo[2]);
    GetPlayerIp(playerid,IP,sizeof(IP));
    for (new tmp=0; tmp<12; tmp++) GetPlayerWeaponData(playerid,tmp,weps[0][tmp],weps[1][tmp]);

    format(query,sizeof(query),"SELECT * FROM `Account` WHERE `Name`='%s'",ReturnName(playerid));
    mysql_store_result();
    if(!mysql_num_rows())
    {
        new userquery[256];
        format(userquery,sizeof(userquery),"INSERT INTO `Account` (`Name`) VALUES ('%s')",ReturnName(playerid));
        mysql_query(userquery);
        mysql_free_result();
    }
    mysql_free_result();
    if(!simple)
    {
        format(query,sizeof(query),"UPDATE `Account` SET `Money.Pocket` = %i, `Money.Bank` = %i, Seklos = %i, Zole = %i, Biznis = %i, Wanted = %i, Gangas = %i, Kalejime = %i, Mobsas = %i, Namu = %i, Ginklas0 = %i, Ammo0 = %i,Ginklas1 = %i, Ammo1 = %i,Ginklas2 = %i, Ammo2 = %i,Ginklas3 = %i, Ammo3 = %i,Ginklas4 = %i, Ammo4 = %i,Ginklas5 = %i, Ammo5 = %i,Ginklas6 = %i, Ammo6 = %i,",
        GetPlayerMoneyA(playerid),playerDB[playerid][banke],playerDB[playerid][seklos],playerDB[playerid][zole],playerDB[playerid][biznis],GetPlayerWantedLevel(playerid),playerDB[playerid][pgang],
        playerDB[playerid][kalejimo_laikas],playerDB[playerid][mobsas],playerDB[playerid][namu],
        weps[0][0],weps[1][0],weps[0][1],weps[1][1],weps[0][2],weps[1][2],weps[0][3],weps[1][3],weps[0][4],weps[1][4],weps[0][5],weps[1][5],weps[0][6],weps[1][6]);

        format(query,sizeof(query),"%s Ginklas7 = %i, Ammo7 = %i,Ginklas8 = %i, Ammo8 = %i,Ginklas9 = %i, Ammo9 = %i,Ginklas10 = %i, Ammo10 = %i,Ginklas11 = %i, Ammo11 = %i, Stilius = %i, pBoxiSkill = %i, pKneeSkill = %i, pKungSkill = %i, pGrabSkill = %i, pElbowSkill = %i, Job = %i, Drabuziai = %i, Uniforma = %i, Uniformd = %i, Adminas = %i, Xp = %i, Lytis = %i,",
        query,weps[0][7],weps[1][7],weps[0][8],weps[1][8],weps[0][9],weps[1][9],weps[0][10],weps[1][10],weps[0][11],weps[1][11],playerDB[playerid][pFS],playerDB[playerid][pBoxiSkill],playerDB[playerid][pKneeSkill],playerDB[playerid][pKungSkill],playerDB[playerid][pGrabSkill],playerDB[playerid][pElbowSkill],playerDB[playerid][specialybe],playerDB[playerid][drabuziai],playerDB[playerid][uniforma],playerDB[playerid][uniformd],playerDB[playerid][admin],GetPlayerScore(playerid),playerDB[playerid][lytis]);

        format(query,sizeof(query),"%s pos_X = '%f', pos_Y = '%f', pos_Z = '%f', Interior = %i, Drugs = %i, MotoLicense = %i, SLicense = %i, Laikrodis = %i, Namie = %i, World = %i, Insurance = %i, Teises = %i,Teorinis = %i, Kortele = %i, Imtuvas = %i, IP = '%s' WHERE Name = '%s'",
        query,coo[0],coo[1],coo[2],GetPlayerInterior(playerid),playerDB[playerid][narkotikai],playerDB[playerid][teisesm],playerDB[playerid][teisess],playerDB[playerid][laikrodis],playerDB[playerid][namie], GetPlayerVirtualWorld(playerid),playerDB[playerid][draudimas],playerDB[playerid][teises],playerDB[playerid][teor],playerDB[playerid][kortele],playerDB[playerid][imtuvas],IP,ReturnName(playerid));
    }
    else
    {
        format(query,sizeof(query),"UPDATE `Account` SET `Money.Pocket` = %i, `Money.Bank` = %i, Seklos = %i, Zole = %i, Biznis = %i, Wanted = %i, Gangas = %i, Kalejime = %i, Mobsas = %i, Namu = %i, Ginklas0 = %i, Ammo0 = %i,Ginklas1 = %i, Ammo1 = %i,Ginklas2 = %i, Ammo2 = %i,Ginklas3 = %i, Ammo3 = %i,Ginklas4 = %i, Ammo4 = %i,Ginklas5 = %i, Ammo5 = %i,Ginklas6 = %i, Ammo6 = %i,",
        GetPlayerMoneyA(playerid),playerDB[playerid][banke],playerDB[playerid][seklos],playerDB[playerid][zole],playerDB[playerid][biznis],GetPlayerWantedLevel(playerid),
        playerDB[playerid][pgang],playerDB[playerid][kalejimo_laikas],playerDB[playerid][mobsas],playerDB[playerid][namu],
        weps[0][0],weps[1][0],weps[0][1],weps[1][1],weps[0][2],weps[1][2],weps[0][3],weps[1][3],weps[0][4],weps[1][4],weps[0][5],weps[1][5],weps[0][6],weps[1][6]);

        format(query,sizeof(query),"%s Ginklas7 = %i, Ammo7 = %i,Ginklas8 = %i, Ammo8 = %i,Ginklas9 = %i, Ammo9 = %i,Ginklas10 = %i, Ammo10 = %i,Ginklas11 = %i, Ammo11 = %i, Job = %i, Uniforma = %i, Uniformd = %i, Adminas = %i, Drugs = %i, MotoLicense = %i, SLicense = %i, Namie = %i,Teises = %i,Lead = %i WHERE Name = '%s'",
        query,weps[0][7],weps[1][7],weps[0][8],weps[1][8],weps[0][9],weps[1][9],weps[0][10],weps[1][10],weps[0][11],weps[1][11],
        playerDB[playerid][specialybe],playerDB[playerid][uniforma],playerDB[playerid][uniformd],playerDB[playerid][admin],
        playerDB[playerid][narkotikai],playerDB[playerid][teisesm],playerDB[playerid][teisess],playerDB[playerid][namie],playerDB[playerid][teises],playerDB[playerid][plead],ReturnName(playerid));
    }
    mysql_query(query);
    return 1;
}
And This
pawn Код:
stock SaveMasina(playerid)
{
    new name[MAX_PLAYER_NAME];
    new var[100],query[300];
    GetPlayerName(playerid, name, sizeof(name));
    format(var, 100,"SELECT * FROM `Cars` WHERE `Owner` = '%s'",name);
    mysql_query(var);
    mysql_store_result();
    if(!mysql_num_rows())
    {
        format(query,300,"INSERT INTO `Cars` (`Owner`,`AH_Typ`,`AH2_Typ`,`AH3_Typ`,`AH_X`,`AH_Y`,`AH_Z`,`AH_Rot`,`AH2_X`,`AH2_Y`,`AH2_Z`,`AH2_Rot`,`AH3_X`,`AH3_Y`,`AH3_Z`,`AH3_Rot`) VALUES ('%s',-1,-1,-1,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000)",name);
        mysql_query(query);
    }
    mysql_free_result();
    format(var, 100, "UPDATE `Cars` SET AH_Typ=%i WHERE `Owner` = '%s'", Carlist[playerid][Typ],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_X='%f' WHERE `Owner` = '%s'", Carlist[playerid][X],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Y='%f' WHERE `Owner` = '%s'", Carlist[playerid][Y],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Z='%f' WHERE `Owner` = '%s'", Carlist[playerid][Z],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Rot='%f' WHERE `Owner` = '%s'", Carlist[playerid][Rotation],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Status=%i WHERE `Owner` = '%s'", Carlist[playerid][Status],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Lock=%i WHERE `Owner` = '%s'", Carlist[playerid][Lock],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Paintjob=%i WHERE `Owner` = '%s'", Carlist[playerid][Paintjob],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Color1=%i WHERE `Owner` = '%s'", Carlist[playerid][Color1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_Color2=%i WHERE `Owner` = '%s'", Carlist[playerid][Color2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod1=%i WHERE `Owner` = '%s'", Carlist[playerid][mod1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod2=%i WHERE `Owner` = '%s'", Carlist[playerid][mod2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod3=%i WHERE `Owner` = '%s'", Carlist[playerid][mod3],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod4=%i WHERE `Owner` = '%s'", Carlist[playerid][mod4],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod5=%i WHERE `Owner` = '%s'", Carlist[playerid][mod5],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod6=%i WHERE `Owner` = '%s'", Carlist[playerid][mod6],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod7=%i WHERE `Owner` = '%s'", Carlist[playerid][mod7],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod8=%i WHERE `Owner` = '%s'", Carlist[playerid][mod8],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod9=%i WHERE `Owner` = '%s'", Carlist[playerid][mod9],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod10=%i WHERE `Owner` = '%s'", Carlist[playerid][mod10],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod11=%i WHERE `Owner` = '%s'", Carlist[playerid][mod11],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod12=%i WHERE `Owner` = '%s'", Carlist[playerid][mod12],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod13=%i WHERE `Owner` = '%s'", Carlist[playerid][mod13],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod14=%i WHERE `Owner` = '%s'", Carlist[playerid][mod14],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod15=%i WHERE `Owner` = '%s'", Carlist[playerid][mod15],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod16=%i WHERE `Owner` = '%s'", Carlist[playerid][mod16],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH_mod17=%i WHERE `Owner` = '%s'", Carlist[playerid][mod17],name); mysql_query(var);
    if(Carlist[playerid][Carid]!=-1)
    {
        format(var, 100, "UPDATE `Cars` SET Sirena=%i WHERE `Owner` = '%s'", alarmed[Carlist[playerid][Carid]],name); mysql_query(var);
        format(var, 100, "UPDATE `Cars` SET Gas=%i WHERE `Owner` = '%s'", vehicleDB[Carlist[playerid][Carid]][gas],name); mysql_query(var);
    }
    format(var, 100, "UPDATE `Cars` SET AH2_Typ=%i WHERE `Owner` = '%s'", Carlist2[playerid][Typ],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_X='%f' WHERE `Owner` = '%s'", Carlist2[playerid][X],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Y='%f' WHERE `Owner` = '%s'", Carlist2[playerid][Y],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Z='%f' WHERE `Owner` = '%s'", Carlist2[playerid][Z],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Rot='%f' WHERE `Owner` = '%s'", Carlist2[playerid][Rotation],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Status=%i WHERE `Owner` = '%s'", Carlist2[playerid][Status],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Lock=%i WHERE `Owner` = '%s'", Carlist2[playerid][Lock],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Paintjob=%i WHERE `Owner` = '%s'", Carlist2[playerid][Paintjob],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Color1=%i WHERE `Owner` = '%s'", Carlist2[playerid][Color1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_Color2=%i WHERE `Owner` = '%s'", Carlist2[playerid][Color2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod1=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod2=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod3=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod3],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod4=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod4],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod5=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod5],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod6=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod6],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod7=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod7],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod8=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod8],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod9=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod9],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod10=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod10],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod11=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod11],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod12=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod12],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod13=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod13],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod14=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod14],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod15=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod15],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod16=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod16],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH2_mod17=%i WHERE `Owner` = '%s'", Carlist2[playerid][mod17],name); mysql_query(var);
    if(Carlist2[playerid][Carid]!=-1)
    {
        format(var, 100, "UPDATE `Cars` SET Sirena2=%i WHERE `Owner` = '%s'", alarmed[Carlist2[playerid][Carid]],name); mysql_query(var);
        format(var, 100, "UPDATE `Cars` SET Gas2=%i WHERE `Owner` = '%s'", vehicleDB[Carlist2[playerid][Carid]][gas],name); mysql_query(var);
    }
    format(var, 100, "UPDATE `Cars` SET AH3_Typ=%i WHERE `Owner` = '%s'", Carlist3[playerid][Typ],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_X='%f' WHERE `Owner` = '%s'", Carlist3[playerid][X],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Y='%f' WHERE `Owner` = '%s'", Carlist3[playerid][Y],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Z='%f' WHERE `Owner` = '%s'", Carlist3[playerid][Z],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Rot='%f' WHERE `Owner` = '%s'", Carlist3[playerid][Rotation],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Status=%i WHERE `Owner` = '%s'", Carlist3[playerid][Status],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Lock=%i WHERE `Owner` = '%s'", Carlist3[playerid][Lock],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Paintjob=%i WHERE `Owner` = '%s'", Carlist3[playerid][Paintjob],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Color1=%i WHERE `Owner` = '%s'", Carlist3[playerid][Color1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_Color2=%i WHERE `Owner` = '%s'", Carlist3[playerid][Color2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod1=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod1],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod2=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod2],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod3=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod3],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod4=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod4],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod5=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod5],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod6=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod6],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod7=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod7],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod8=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod8],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod9=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod9],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod10=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod10],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod11=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod11],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod12=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod12],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod13=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod13],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod14=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod14],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod15=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod15],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod16=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod16],name); mysql_query(var);
    format(var, 100, "UPDATE `Cars` SET AH3_mod17=%i WHERE `Owner` = '%s'", Carlist3[playerid][mod17],name); mysql_query(var);
    if(Carlist3[playerid][Carid]!=-1)
    {
        format(var, 100, "UPDATE `Cars` SET Sirena3=%i WHERE `Owner` = '%s'", alarmed[Carlist3[playerid][Carid]],name); mysql_query(var);
        format(var, 100, "UPDATE `Cars` SET Gas3=%i WHERE `Owner` = '%s'", vehicleDB[Carlist3[playerid][Carid]][gas],name); mysql_query(var);
    }

}
Reply


Messages In This Thread
A Little mysql optimization - by wups - 15.10.2010, 16:19
Re: A Little mysql optimization - by Calgon - 15.10.2010, 16:25
Re: A Little mysql optimization - by wups - 15.10.2010, 16:30
Re: A Little mysql optimization - by Sergei - 15.10.2010, 16:32
Re: A Little mysql optimization - by Leeroy. - 15.10.2010, 16:33
Re: A Little mysql optimization - by Relixious - 15.10.2010, 16:35
Re: A Little mysql optimization - by Leeroy. - 15.10.2010, 16:38
Re: A Little mysql optimization - by Calgon - 15.10.2010, 16:40
Re: A Little mysql optimization - by Leeroy. - 15.10.2010, 16:43
Re: A Little mysql optimization - by wups - 15.10.2010, 16:43

Forum Jump:


Users browsing this thread: 1 Guest(s)