How does MYSQL create indexes

There is a table with 10 million records. I decided to experiment creating indexes.

Code:

CREATE INDEX price_index ON products_table (price);

It's been 1.5 hours and still loading. It made me curious!

1 - How long is it gonna take? Should I restart the server?

2 - How does the process of creating indexes work? Is it going through every record and do something special there? Is it orgonizing the data? Or is it simply adding index in to specific locaitons on file?

Yes, it goes through every record and does something, so the time it takes to add an index does correspond to the number of records in the table. However, it's not something that's easily predictable as far as I know. Restarting the server in the middle of it definitely is not going to make it go any faster.

Exactly what it does for each record depends on the index type. It is organizing the data in some way, usually a tree or a hash map.

Yes, it goes through every record and does something, so the time it takes to add an index does correspond to the number of records in the table. However, it's not something that's easily predictable as far as I know. Restarting the server in the middle of it definitely is not going to make it go any faster.

Exactly what it does for each record depends on the index type. It is organizing the data in some way, usually a tree or a hash map.

Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. An .frm file stores the table format. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension.

If you on the other hand are using InnoDB then both indexes and the table data (which in fact is also stored as part of the primary key index) is stored in the ibdata1 file(s) (or whatever you call your ibdata files).

Google for MyISAM and InnoDB together with mysql manual and the mysql internals if you want to read up on all details, they are a lot of useful information there.