I am using indexes with my tables, but I honestly do not know how they work internally.
Let’s say I have the following table
id age
1 20
2 35
3 19
4 18
if I make an index of ‘age’, how does mysql organize the rows? Does it organize depends on field type? or…? how does mysql make indexes for unicode??
MySQL indexes are generally byte-ordered. The first part of the index is the data that is indexed (often the full field, though it can be a partial index of the first few characters), and the second part is the associated primary key.
For handling unicode, if MySQL is aware, it operates just like comparator classes in other languages. Unicode-aware versions of MySQL have a section of code which is aware of the proper ordering for unicode and can compare two unicode characters telling which one is greater than the other.
Your resultant index for InnoDB (assuming your PK is id) would be:
For MyISAM, an offset reference to the actual row location would be used.
Also, a good article that might give some insight: http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/