Improving time for creating indices in MySQL ?

Hi guys I have been working on a program that will populate and index a database. The populating doesn’t take too long, but the indexing does. My question is: Is there a better approach to indexing this table than the one I’m using right now?

I’m doing this through QtSql.

for (int i = 0; i < headers.size(); ++i) {
q.exec(“ALTER TABLE temptable ADD INDEX(” + headers[i] + “);”);
}

Thanks in advance,

Ed.

Hi,

create the table with indexes,…
than call:
ALTER table DISABLE KEYS;

Populate the data

Call:
ALTER table ENABLE KEYS;

This should build all indexes in one table scan… (parallel)

With your method a complete table scan has to be done for each index… (serial)