0

I notice mysqldump always put the command ALTER after INSERT.

CREATE TABLE ...;
INSERT table ....;
ALTER TABLE ...;

Is it possible to change the sequence to ALTER table first?

CREATE TABLE ...;
ALTER TABLE ...;
INSERT table ....;

When restoring data, this is needed as ALTER could be very slow with large tables with many records. Sometimes it could take more than 10 minutes to ALTER table.

neobie
  • 131
  • 2
  • 7
  • What alters are that? There is usually a reason to do them after data import - foreign keys are added after other tables are imported because otherwise it might break, indexes may be added after data because that way the total time of insert+alter is significantly less than what inserts into a table with indexes would take etc. – jkavalik Oct 28 '21 at 11:38
  • In some cases, it is faster to build an index after all the data is present, rather than building on the fly. – Rick James Jan 23 '22 at 04:37

0 Answers0