SA-MP Forums Archive
MySQL vs for() - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: MySQL vs for() (/showthread.php?tid=624317)



MySQL vs for() - corne - 14.12.2016

I've read through a few existing topics but found conflicting answers on this issue. I'm building an ingame map editor and now working on the ability to save a single map (the one you'd be editing) on command, the average map would have about 50 to 200 objects, with about 20 maps on the server.


Now, I'm trying to figure out whether it would be faster to loop through ALL objects and use strcmp to check the map name each time, and if it's the one you've edited then save them to the database id stored in a variable.

... or ....

Use MySQL in order to retrieve all ingame ids stored in a table, then loop through those and save them.

--

My guess would be MySQL as strcmp is quite slow, just interested in your opinions.


Re: MySQL vs for() - Vince - 14.12.2016

Sorry what? I'm not really following. It sounds like your tables aren't properly normalized. If you have many maps and each map can have many objects then you need two tables: one that declares the map properties (id, name, author, creation date, whatever) and another one that is linked to it that stores the actual objects (id, mapid, modelid, x, y, z, ...).


Re: MySQL vs for() - PrO.GameR - 14.12.2016

I'm sorry but why on earth would you save a mapname on object instead of it's mysql index?
As a rule of thumb you should index things whenever possible instead of using string comparison.


Re: MySQL vs for() - SickAttack - 14.12.2016

Just save the ID of the map the object belongs to in each row. Select all objects or within a LIMIT with that ID using an SQL statement.


Re: MySQL vs for() - CodeStyle175 - 14.12.2016

PHP Code:
new id=Iter_Free(fObjects);
if(
id==-1)return scm(pid,-1,"No free slot to add object!");
Iter_Add(fObjects,id);

new 
s[200];
format(s,sizeof(s),"INSERT INTO objects(mid,x,y,z,rx,ry,rz) VALUES('%d','%f','%f','%f','%f','%f','%f')",mid,x,y,z,rx,ry,rz);
new 
Cache:cq=mysql_query(sc,s);
Object[id][sid]=cache_insert_id();
cache_delete(cq); 



Re: MySQL vs for() - NeXoR - 14.12.2016

Create a threaded query, such command might and will lag your server


Re: MySQL vs for() - SickAttack - 14.12.2016

Quote:
Originally Posted by NeXoR
View Post
Create a threaded query, such command might and will lag your server
Lies


Re: MySQL vs for() - NeXoR - 15.12.2016

Quote:
Originally Posted by SickAttack
View Post
Lies
I am speaking out of self experiences.


Re: MySQL vs for() - SickAttack - 16.12.2016

Quote:
Originally Posted by NeXoR
View Post
I am speaking out of self experiences.
Still lies.


Re: MySQL vs for() - corne - 17.12.2016

Alright, sorry for the late reply, been busy.

Quote:
Originally Posted by Vince
View Post
Sorry what? I'm not really following. It sounds like your tables aren't properly normalized. If you have many maps and each map can have many objects then you need two tables: one that declares the map properties (id, name, author, creation date, whatever) and another one that is linked to it that stores the actual objects (id, mapid, modelid, x, y, z, ...).
That's exactly what I have. I just didn't see the point in my mentioning it as it was somewhat unrelevant to the question because only the objects are updated on a save, nothing happens to the `maps` table.

Quote:
Originally Posted by PrO.GameR
View Post
I'm sorry but why on earth would you save a mapname on object instead of it's mysql index?
As a rule of thumb you should index things whenever possible instead of using string comparison.
Well, to be honest comparing strings in MySQL is not that problematic, while it's generally recommended to use an INT I believe that's mostly because strings are prone to change, while an unique id doesnt. I'm not saying that there isn't a performance difference between the two, but it's not that problematic, especially not in this situation where it's only loaded on start and saved after an edit. I did change it to use an unique id instead as the main reason I started with a varchar was out of laziness.

---

Either way, thanks for all the input.