I had a task to create an indexed table with 180M of rows in the fastest way.
I tried to use default approach:
- to create an empty table without indexes
- to fill the table using LOAD DATA INFILE
- to add required indexes using ALTER TABLE
With default configuration mysql performed quickly the second step (approx 30 minutes), but hanged up on the third. I waited for 30 hours, but without any success.
Then I read about key_buffer_size variable and changed it to 1.5G (machine had 2G of RAM). After that mysql applied primary key for 8 hours. Not very good result, because mssql creates the same index for less than an hour. I think the problem was in slow per-row algorythm mysql uses when creating unique indexes and the final primary key file size - 3G, which didn’t fit into 1.5G of key buffer.
Then I tried to use the following approach:
- to create an empty table with indexes
- to disable indexes by ALTER TABLE DISABLE KEYS
- to fill the table using LOAD DATA INFILE
- to enable indexes by ALTER TABLE ENABLE KEYS
But this approach didn’t work too, becasue mysql doesn’t disable primary key and unique indexes usage after performing
ALTER TABLE DISABLE KEYS
Can anybody answer me the following questions:
- why mysql doesn’t disable unique indexes on ALTER TABLE DISABLE KEYS query?
- why mysql uses slow per-row algorithm when creating unique indexes, while it uses fast filesort algroithm when creating non-unique indexes on ALTER TABLE ADD [UNIQUE INDEX | PRIMARY KEY] query?
- is there any non-tricky workaround for this problem? I’ve read Peter’s article here [URL]http://peter-zaitsev.livejournal.com/11772.html[/URL] , so it doesn’t fit me.