MySQL vs for()
#1

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.
Reply
#2

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, ...).
Reply
#3

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.
Reply
#4

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.
Reply
#5

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); 
Reply
#6

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

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

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

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)