I have a table storing latitude, longitude, address and auto-generated id. The table contains 6 hundred thousand records in it. I have to apply UNIQUE INDEX to the combination of lat-lon. But it is taking too much time, and query timesout. The query is
ALTER TABLE `<db name>`.`<table name>`
ADD UNIQUE `latLonIndex`(`latitude`, `longitude`);.
I am using MySQL server 5.0. Please suggest a way.
Also, the current table has some duplicate lat-lon combination. Hence, I can not apply the unique index. Please suggest a way to overcome this difficulty as well.
Create a second table that has the same columns and the index you need. Insert from the other table in batches. When done, remove the old table and rename the new one to the old one’s name.