| InnoDB data layout [message #338] |
Wed, 08 November 2006 16:05  |
micboh Messages: 2 Registered: November 2006 |
Junior Member |
|
|
Say I have an innodb table with three columns:
fid (int),
date (datetime),
val (int).
The primary key for this table is fid,date and if I understand correctly, InnoDB will cluster on this key, so the data will be sequential on disk. In this case, fid and val are foreign keys to other tables, and date is stamped with now() on every insert. Additionally, most queries need to lookup by fid, so clustering on date,fid would not be ideal.
Can someone explain to me how room gets made on disk when an insert occurs on this table? Specifically, I'm wondering what happens when a page for a given fid,date is full. Does MySQL make room in the next page by moving data around so it can stay sequential on disk? Or is another page allocated at the end, and is the data not really seqential anymore until some later rebuild?
Thanks,
Mike
|
|
|
| Re: InnoDB data layout [message #354 is a reply to message #338 ] |
Sun, 12 November 2006 22:33   |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
What about fid ? Are they inserted in random or sequential orfer ?
If order is random clustering by (date,fid) may be faster and you can add separate key on fid.
Regarding what happens if page becomes full with new insert - in this case page split happens and so you get two pages instead of one. One of them will be stored in the same place while other moved to different location - this is how fragmentation occures.
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
|
|
| Re: InnoDB data layout [message #359 is a reply to message #358 ] |
Mon, 13 November 2006 19:58  |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
OK. This is good choice then.
Innodb table fragmentation will affect you only if you do large ranges on primary keys or full table scans. Rows do not fragment with Innodb and is it is still always clustered within one page.
OPTIMIZE TABLE can be used to defragment but it locks table
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
|