Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

You must change a column type from INT to BIGINT on a 1.5 billion row MySQL table that serves 5,000 writes per second. Compare gh-ost and pt-online-schema-change and describe the execution plan.

Changing INT to BIGINT needs a full table copy, and a plain ALTER would block writes for hours, so we use an online schema change tool that builds a shadow table and swaps it in. pt-online-schema-change copies rows in chunks and keeps the shadow table current with triggers, which add work and lock contention to every write. gh-ost copies in chunks too but reads ongoing changes from the binlog, with no triggers, can be throttled, paused and controlled interactively, and lets us decide when the cutover happens; at 5,000 writes per second I would choose gh-ost, test it on a replica first, and keep the old table until the result is verified.

Why this question is asked

An INT primary key or counter running towards 2,147,483,647 is a classic emergency, and at 1.5 billion rows the table is already three quarters of the way there. The change itself is one line of SQL, but on a table this size with this much traffic it is a multi-day operation that must not disturb production. Interviewers ask this scenario to see whether we know why the change cannot be done in place, how the two common tools differ under heavy writes, and how to plan the run safely. In this answer, we will see why a copy is needed, how each tool keeps the copy current, compare them, plan the execution, and look at how gh-ost performs the final swap.

1Why INT to BIGINT Needs a Full Copy

An INT column takes 4 bytes and a BIGINT 8, so every row on every page changes its layout, and every index containing the column must be rebuilt. InnoDB cannot do this as an INSTANT or INPLACE change; it needs ALGORITHM=COPY, which builds a new table and blocks writes for the entire copy.

SQL
ALTER TABLE events MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, ALGORITHM=INPLACE, LOCK=NONE;
-- ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change
-- column type INPLACE. Try ALGORITHM=COPY.

With 1.5 billion rows, a blocking copy would take many hours, and at 5,000 writes per second that is tens of millions of failed or queued writes. So the copy has to happen while the table keeps working, which is what online schema change tools are for. Both create an empty shadow table with the new definition, copy the existing rows into it in small chunks, keep it up to date with ongoing changes, and finally swap the names.

2Pt-online-schema-change: Triggers Keep the Copy Current

pt-online-schema-change, from Percona Toolkit, creates three triggers on the original table, for INSERT, UPDATE and DELETE, that repeat every change on the shadow table inside the same transaction. Then it copies rows in chunks with INSERT ... SELECT, sizing chunks so each takes about half a second.

At 5,000 writes per second, this design has costs. Every application write now does a second write to the shadow table in the same transaction, which roughly doubles write work and adds latency. The trigger writes and the chunk copies touch the same rows, so they contend for locks and can deadlock. Creating and dropping triggers needs a metadata lock on the busy table. And triggers cannot be paused: once installed, they run until the tool finishes or is cleaned up.

3Gh-ost: The Binlog Keeps the Copy Current

gh-ost, from GitHub, uses no triggers. It connects to MySQL like a replica, reads the row-based binlog (which must be in ROW format with binlog_row_image=FULL), and applies each change to the shadow table itself, asynchronously, interleaved with its chunked row copy. The application's writes do no extra work at all.

Because gh-ost controls both streams, it can throttle completely: when replica lag or server load passes a limit, it stops copying and stops applying, and the original table carries on alone. It can be paused, resumed and re-tuned while running through a Unix socket, for example changing the chunk size. And the cutover waits until we allow it, for example by deleting a flag file during a quiet hour.

pt-online-schema-change and gh-ost
pt-online-schema-changegh-ost
Keeps the copy current withtriggers, in the app's transactionbinlog events, applied by gh-ost
Extra load on each writea second write plus lock contentionnone on the write path
Throttlingpauses the copy; triggers keep runningpauses copy and apply completely
Control while runninglimitedinteractive commands, pause, chunk size
Cutoverautomatic atomic RENAME at the endwhen we allow it, postponable
Foreign keyssupported with chosen methodslargely unsupported

4The Execution Plan

Before starting, we check disk space: the shadow table will be a full copy of a table that may be hundreds of gigabytes, plus the binlogs generated by the copy itself, plus some margin. We estimate the duration: if gh-ost copies 25,000 rows per second between throttles, 1.5 billion rows take about 60,000 seconds, roughly 17 hours, and in practice with throttling more like one to two days.

Then we rehearse. We run gh-ost against a replica in test-on-replica mode, which performs the whole migration there and stops replication at the end, so we can compare the two tables and measure the impact. For the real run, gh-ost reads the binlog from a replica and writes to the primary, with limits on replica lag and on load.

Java
gh-ost \
--host=replica-1 --database=app --table=events \
--alter="MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT" \
--max-lag-millis=1500 \
--max-load=Threads_running=40 --critical-load=Threads_running=200 \
--chunk-size=1000 \
--postpone-cut-over-flag-file=/tmp/ghost.postpone \
--execute
# Copy: 412000000/1500000000 27.5%; Lag: 0.6s; State: migrating; ETA: 31h12m

When the copy finishes, gh-ost keeps applying binlog events and waits. We delete the flag file during the lowest-traffic hour, the cutover happens, and gh-ost keeps the old table under a name like _events_del. We keep it until the application has run cleanly on the new table and row counts and spot checks agree, then drop it, ideally in a quiet period, because dropping a huge table also costs I/O.

5Foreign Keys Complicate Both Tools

If the table has foreign keys, check each tool's documentation and our schema carefully. gh-ost does not support tables with foreign keys in general, because its swap would leave constraints pointing to the old table. pt-online-schema-change can handle child tables with options such as --alter-foreign-keys-method, each with trade-offs, such as briefly disabling checks or rebuilding the child tables. And remember the referencing side: if other tables store this id in INT columns, they need the same change, often first, or values over the INT limit will fail to insert there.

6Follow-up questions

How does gh-ost perform the final table swap?

It uses a two-connection sequence designed to be atomic. One connection creates a placeholder table with the old table's future name and takes LOCK TABLES ... WRITE on the original table and the placeholder, so application writes wait. A second connection issues RENAME TABLE original TO old, shadow TO original, which blocks behind that lock. gh-ost applies the last binlog events, drops the placeholder and releases the lock, and MySQL runs the waiting RENAME before the queued writes. If anything fails midway, the placeholder makes the RENAME fail and the original table stays in place. Check the gh-ost documentation for your version for the exact details.

Can we stop gh-ost halfway?

Yes. Stopping it leaves the original table untouched; we drop the shadow and changelog tables it created and can start again later. That is one of its main safety advantages over a blocking ALTER.

Why not just switch to a new BIGINT column in the application?

That is another valid approach: add a new BIGINT column, backfill it, dual write, switch reads, and drop the old one. It avoids one huge copy but needs several application releases, and for a primary key it is harder than for a plain column.

7Conclusion

In this answer, we saw that INT to BIGINT requires a full table copy, so on a 1.5 billion row table at 5,000 writes per second we need an online schema change tool. pt-online-schema-change keeps the shadow table current with triggers, adding load and lock contention to every write, while gh-ost reads the binlog with no triggers, throttles and pauses fully and lets us choose the cutover time. The plan checks disk space, estimates duration, rehearses on a replica, throttles on lag and load, cuts over in a quiet hour and keeps the old table until verified, with foreign keys checked carefully for both tools.

What to say in the interviewAbout 90 seconds aloud

Open with

Changing INT to BIGINT changes the row layout, so InnoDB needs a full copy with ALGORITHM=COPY, which would block writes for many hours on 1.5 billion rows. So I would use an online schema change tool.

Then, if they want more

Both tools build a shadow table with the new definition, copy rows in chunks and swap names at the end; the difference is how they keep up with ongoing writes. pt-online-schema-change installs triggers that repeat every insert, update and delete on the shadow table inside the application's transaction.

At 5,000 writes per second that roughly doubles the write work and adds lock contention, and the triggers cannot be paused. gh-ost has no triggers.

It reads the row-based binlog like a replica and applies changes itself, so the application's writes are unaffected, it can throttle and pause completely on replica lag or load, it can be retuned while running, and the cutover waits for us, using a postpone flag file. So I would pick gh-ost.

My plan would be: check disk space for a full copy plus binlogs, estimate the duration, probably one to two days, rehearse with test-on-replica, run with max-lag and max-load limits, cut over during the lowest traffic, and keep the old table until counts and the application confirm it is fine.

I would check foreign keys first, because gh-ost does not support them, and also widen any referencing INT columns.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
MySQL reference manual
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You must change a column type from INT to BIGINT on a 1.5 billion row MySQL table that...": https://scrivio-interview-library.netlify.app/databases/mysql/bff8361457/