In the business process, two sheets are poor
At first a small table, thought that the amount of data is not very large, so there is no index.
When the actual operation of the process, the small table slowly grew up, found that two tables to find the difference between the time can reach a few hours!!! amazing!
What to do, to build index chant
Then the problem arises, the small table has the duplicate data, the whole, one deletes too SB
Write SQL
DELETE from Solr_indexed_max_incidentid WHERE incidentid in (SELECT Incidentid from Solr_indexed_max_incidentid GROUP by I Ncidentid having count (Incidentid) > 1);
Error:
ERROR 1093 (HY000): You can ' t specify target table ' Solr_indexed_max_incidentid ' for update on FROM clause
Oh, no.
Another want to switch
Build a temporary table and bake the data after the deduplication.
CREATE TABLE Solr_tmp as SELECT * from Solr_indexed_nax_incidentid GROUP by Incidentid have count (Incidentid) > 1;
and delete the original watch.
drop table Solr_indexed_max_incidentid; (later thought it was too unprofessional to change the table to a name equivalent to the backup there, in case the next mistake is not crazy?) )
and change the name.
RENAME TABLE solr_tmp to Solr_indexed_max_incidentid;
Then add the index
ALTER TABLE ' Solr_indexed_max_incidentid ' Add primary key (' Incidentid ');
Continue running business logic for a few seconds to finish!
Remember the big pits in the business-mysql have the additional primary key under duplicate data