Helper Table: `Migrate`
This table has only 1 row.
CREATE TABLE Migrate (
running TINYINT UNSIGNED NOT NULL DEFAULT '0',
clump_size INT UNSIGNED NOT NULL DEFAULT '100',
delay FLOAT NOT NULL DEFAULT '1',
left_off_1 ... (INT, VARCHAR, etc, matching first field in KEY being used)
left_off_2 ... (more field(s), if needed)
clumps_moved INT UNSIGNED NOT NULL DEFAULT '0',
rows_moved BIGINT UNSIGNED NOT NULL DEFAULT '0',
lock_time DOUBLE NOT NULL DEFAULT '0',
move_time DOUBLE NOT NULL DEFAULT '0',
sleep_time DOUBLE NOT NULL DEFAULT '0',
last_move TIMESTAMP NOT NULL
) ENGINE=MyISAM;
Discussion:
⚈ `running` is 1 while Alter is running. INSERTs, etc, check this to know whether to INSERT into the new table.
⚈ clump_size says how many rows to move per iteration; "100" is used as an example. This can be dynamically tuned.
⚈ delay is how long to sleep() between iterations; 1 second is a good first guess. This is tunable.
⚈ left_off_* contain the value(s) of the last key used by the last clump. (Initialize to 0 or '', or whatever is less than first key.)
⚈ clumps_moved and rows_moved tally the progress.
⚈ the *_time fields keep track of the seconds consumed by the phases of the loop.
⚈ last_move is a timestamp, overwritten at the end of each iteration. At the end of Alter, it is the finish time. (If the value is too long ago, but not finished, maybe it is broken.)
⚈ MyISAM was chosen to avoid any risk of involving this in BEGIN..COMMIT transactions.
⚈ Replicating the table is optional; it has no function on Slaves.
⚈ It was not intended to JOIN this table with any other; I don't know if "left_off_*" is useful.
The table must be CREATEd before the Layer has the code in it that
looks at the table. The imporant value (at that point) is
running=0.