Join the forums now, and start posting to receive access to our Scripts Vault!
chat_normal(id int unsigned not null,player_id mediumint unsigned not null,message varchar(150) not null,sent timestamp on update current_timestamp not null,primary key(id),index(player_id))engine=innodb;
3. You used mediumint for player_id. InnoDB silently converts mediumint to int, so limiting your numeric range there is of no real benefit.
I always overlooked mediumint existence How is it handled in modern CPUs? Back then 24 bit values were useless (except for saving space) since everything was converted to 32 bit for performance (no real support for other values than 8,16,32 and maybe 64 bit). Is this correct nowadays too?
4. You might want to consider using MyISAM for a simple chat table. Chat tables often use only INSERT / SELECT and never (or rarely) use UPDATE, so InnoDB's MVCC overhead doesn't help a whole lot. Chat tables are a lot like logging/activity tables. MyISAM + the concurrent_inserts setting will probably be faster and more compact. I expect most of this won't be that important until your game is massive $0.02
Chat may be stored like a log/activity file but it sure isn't accessed like one and there in lies the problem when it comes to chat. Log/activity files are heavy writes and very little reads, chat is just as heavy on the reads as it is on writes so you have to think of it very differently then a log/activity file.
This may be a silly question, but why are you writing a chat application? There are several IRC solutions for this that may be able to reduce your workload.
myISAM's table locking even at moderate chat use causes the write locks to queue up and cause lag. myISAM may be faster but only until the locking queue starts slowing things down. Granted we switched over to INNODB when mySQL 4.x was just getting released so myISAM maybe a bit better handling its locks. However we are going on over 5 years with using INNODB without have to tweak anything which how we like things (set it and forget it).
Why not make a buffer table (one row, one text field only with all recent chat stored as one big HTML)? You make writes normally to separate rows on chat table and then it updates the buffer table, all users read only from buffer table, the read from chat table is done only during buffer update (when someone says something).
Seems this was supported in ancient MySQLs too.
What exactly "no holes in the data file" mean? If after delete we do OPTIMIZE TABLE do we still have holes or not?
And how exactly are rows stored in database? If I delete a row from the middle and add a new one (MyISAM) the new one will go in the place of old one, regardless of AUTO INCREMENT primaty key. After OPTIMIZE nothing changes (which is strange since it is supposed to recreate the table from scratch). Seems like it will never arrange the table in IDs order...