Originally posted by nemesis1931
Thanks for the feedback!
heres a question then..
Wouldnt putting johnnyfive's user id in a seperate table and instead referencing it by an id multiple times be similar?
Yes and no. Here's why:
"johnnyfive" takes up 10 bytes (assuming storage is 1 byte per ASCII character - unicode will make it about 2 to 4 bytes per character depending on the character set - I think).
So for this example, lets say 10 bytes. To store an integer value, lets say its 4 bytes (how MySQL does it).
You store "johnnyfive" once in the user table and that's 10 bytes. Then each time you store a message that references "johnnyfive", that's 4 bytes. Let's say there's 10 messages. That's 40 bytes being used plus the 10 bytes in the user table (or 50 bytes total). If you didn't have a user table but just had a message table, that would be 100 bytes ("johnnyfive" stored 10 times as a string). You probably see the pattern.
Also, when it comes to computing, its a TON easier for a computer to sort a list of numbers then it is to sort a list of names. Databases can build indexes and numeric indexes are a lot easier for the system to work with then an index filled with names.
Originally posted by nemesis1931
Would it be faster to look in a table of johnny5's messages which might contain hmm i dunno 100-200 lets just say..
or would it be faster to look in a large message table with 50000 messages just to find the 100 messages that belong to johnny5?
speed or memory isnt that always the question?
Obviously, 100-200 messages will result in a quicker turn around time. But you'll find even if you have 1,000,000 rows of data, if you properly design your tables (use numeric indexes and normalization where possible) then quering this won't be a big deal. Yes, it'll be a little longer to go through the 50,000, but if you use indexes and a numeric ID to represent "johnnyfive", then the query will still go really fast. Remember, because of indexing, the database can optimize the data in a way which allows the database to quickly find johnnyfive's ID and data.