MySQL / Concurrency, performance, and operations / Lesson 21
Rehearse an online schema change
Plan a compatible column addition, observe metadata locks, and verify a staged migration.
On this page
Lesson goals
- Explain application compatibility during a schema change.
- Read an explicit DDL algorithm request as a constraint, not a zero-impact guarantee.
- Design verification, recovery, and rollout evidence.
- Plan compatible expansion, bounded backfill and verified constraint enforcement.
- Assess metadata-lock, replica and recovery evidence for an online DDL rehearsal.
Plan the compatibility window
A live application may have old and new versions running at the same time. Adding a nullable column can be one step in an expand-and-contract migration: first introduce a backward-compatible representation, then deploy compatible readers and writers, backfill under a separate controlled procedure, and only later consider stricter constraints. The actual order depends on the application contract. Inventory every consumer, including reports and background jobs.
Inspect a disposable starting table
The following SQL is illustrative and belongs only in a new disposable MySQL 8.4 InnoDB lab. It creates two synthetic orders and displays the initial definition. Do not point this example at a configured application database. In a real migration, record the existing schema, data volume, long transactions, replication topology, backup, and available resource headroom before deciding on a procedure.
CREATE TABLE lab_migration_orders (
id INT PRIMARY KEY,
status VARCHAR(12) NOT NULL
) ENGINE=InnoDB;
INSERT INTO lab_migration_orders VALUES (1, 'new'), (2, 'paid');
SHOW CREATE TABLE lab_migration_orders;
The fixture has two rows and only id and status columns. SHOW CREATE TABLE is an inspection example; its actual output depends on the server and is not reproduced here.
Request a specific algorithm
The next example explicitly requests INSTANT for a nullable column addition to the disposable table. If the requested algorithm is not supported under the actual table and server conditions, the statement can fail rather than silently satisfying an unsupported assumption. Consult the official operation-specific restrictions for the deployed version. The request does not establish that there will be no metadata-lock wait or operational impact.
ALTER TABLE lab_migration_orders
ADD COLUMN source_code VARCHAR(20) NULL, ALGORITHM=INSTANT;
SHOW CREATE TABLE lab_migration_orders;
SELECT id, status, source_code FROM lab_migration_orders ORDER BY id;
If the statement succeeds for this fixture, existing rows read NULL for source_code. Inspect the returned definition and rows; actual DDL support, lock waits, and output depend on the environment and are not claimed here.
Observe locking and recovery
Online DDL can still need metadata locks, and long transactions can delay an operation. Rehearse against representative isolated data with concurrent traffic, monitor the documented lock and resource signals, and account for replicas. DDL transaction behavior differs from ordinary DML; do not promise that a surrounding ROLLBACK will undo the schema change. Define a tested forward repair or recovery procedure and a stopping condition before deployment.
Verify each migration stage
After the change, compare the actual definition and expected row count, then test old and new application versions with representative reads and writes. If backfilling, use a bounded, observable procedure and verify completeness before tightening constraints. Record duration, lock waits, application errors, and replica progress in the rehearsal. A successful ALTER statement is one observation; the full compatibility and recovery contract must also be demonstrated.
Define a compatibility window
An online schema change is a coordinated application and database rollout, not merely an ALTER statement. Inventory every consumer: old and new application instances, reports, background jobs, importers and administrative tools. Specify what each version reads and writes while both may run. For a new required attribute, a common expand-and-contract pattern begins with a nullable compatible column, deploys readers and writers that tolerate both states, backfills existing rows, verifies completeness and only then considers a stricter constraint. The correct order depends on the actual application contract and must be rehearsed.
A nullable addition can keep old code working only if that code truly tolerates the altered schema. Positional INSERT statements, SELECT * consumers, generated mappings and deployment assumptions may behave differently from explicit column lists. Test both old and new versions against a representative isolated copy. Record the starting definition, row counts, versions, table size, long transactions, replication topology and recovery point before selecting an operation.
Treat an algorithm request as a constraint
MySQL InnoDB offers operation-specific online DDL algorithms and restrictions. An explicit ALGORITHM=INSTANT request asks the server to use that algorithm for a particular supported change; if the actual table and operation cannot use it, the statement can fail rather than silently providing an unsupported assumption. Review the MySQL 8.4 manual for the exact operation and table conditions, and test the deployed patch level and schema. Do not extrapolate one successful column addition to every ALTER operation.
Even an instant metadata change can need metadata locks and can wait behind a long transaction. It also does not prove zero application latency, replica impact or operational risk. Establish a deadline and stopping conditions, observe lock and resource evidence through authorized channels and rehearse concurrent traffic. A hypothetical success for the lesson fixture makes its existing rows read NULL for the added nullable source_code; it is not a claim that a live server executed the DDL.
Backfill without losing new writes
Adding a nullable column is only the expansion stage when the final business rule requires a value. Deploy compatible code that writes the new field before or during a controlled backfill according to the rollout contract. Backfill in bounded batches with observable progress, a stable key range and a documented retry policy. Avoid overwriting a newer value written by the application: a predicate such as source_code IS NULL can protect already populated rows when that matches the business rule, but concurrent behavior still requires testing.
After backfill, count missing and invalid values and verify representative row mappings, not only the number of updates. Ensure all active writers satisfy the new rule so NULL cannot reappear between validation and enforcement. If one row remains NULL, imposing NOT NULL is premature until the cause is resolved. Design the stricter change, its locking and recovery separately; a successful first ALTER does not prove that the later constraint will succeed or be online under the same conditions.
Plan metadata locks and recovery
DDL can require metadata locks even when row data need not be rebuilt. A long transaction that accessed a table may retain metadata protection after its SELECT returns, delaying the ALTER and potentially affecting later requests. Inspect authorized lock evidence and transaction age during rehearsal, and define who can resolve a blocker under the established procedure. Increasing a timeout does not shorten the blocking transaction. Set a stop threshold before rollout and monitor application errors, resource pressure and replica progress.
MySQL DDL has transaction behavior distinct from ordinary rollbackable DML. Do not assume a surrounding ROLLBACK will undo an ALTER TABLE. Prepare a tested forward repair, reverse migration where appropriate, or restore strategy, and understand what data written by new code would be lost or transformed. Keep backups independent and verify restore readiness. The public examples do not alter any configured database or provide an operational deployment command.
Rehearse every stage and decision
A successful ALTER is one observation, not complete rollout evidence. After each stage inspect the actual schema definition, expected row counts, representative values and constraints. Exercise old and new readers and writers, including background jobs; test a long transaction, a failed algorithm request, a partially completed backfill and a retry. Measure duration, metadata-lock waits, application error rate and replica progress on representative synthetic data. Verify that the rollout remains within its predeclared stop criteria.
Record the exact server version, table definition, data distribution, concurrent workload and recovery procedure so the result is reproducible. Rehearse the forward repair or restore and test that application behavior remains correct after it. Compare counts and selected identities rather than relying on one aggregate. SQL and timelines below are non-runnable MySQL 8.4 illustrations, using the two-row lab fixture or explicitly declared synthetic scenarios; no schema, data or server was modified.
20 worked examples
1. Starting definition
Problem: What columns and rows does the synthetic starting table contain?
- The declared table contains id and status before the column addition.
- The two inserted rows have identifiers 1 and 2 with the stated statuses.
CREATE TABLE lab_migration_orders (id INT PRIMARY KEY, status VARCHAR(12) NOT NULL) ENGINE=InnoDB;
INSERT INTO lab_migration_orders VALUES (1, 'new'), (2, 'paid');
SELECT id, status FROM lab_migration_orders ORDER BY id;
1 | new
2 | paid
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Two rows with id and status.
Why this result follows: A documented baseline makes later schema and data comparisons meaningful. This follows the stated schema and migration assumptions.
2. Nullable addition
Problem: If the declared nullable column addition succeeds, what do existing rows show?
- The new column permits NULL and no value is supplied for existing rows.
- Under the stated successful addition both preexisting rows read NULL for source_code.
-- Independent disposable fixture with rows 1/new and 2/paid.
ALTER TABLE lab_migration_orders ADD COLUMN source_code VARCHAR(20) NULL, ALGORITHM=INSTANT;
SELECT id, source_code FROM lab_migration_orders ORDER BY id;
1 | NULL
2 | NULL
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Both existing rows show NULL.
Why this result follows: A nullable addition provides a compatible interim representation for absent old values.
3. Algorithm unsupported
Problem: What should a rehearsal conclude if an explicit INSTANT request is unsupported?
- The explicit algorithm is a requirement for this statement rather than a guaranteed capability.
- An unsupported operation cannot be counted as a successful instant change.
-- Synthetic outcome: ALTER TABLE ... ALGORITHM=INSTANT is rejected as unsupported for this table.
-- No alternative algorithm was requested.
The requested operation failed; reassess the change and supported options.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Stop and review the actual table and server restrictions.
Why this result follows: An explicit algorithm request constrains execution but does not prove support. This follows the stated schema and migration assumptions.
4. Metadata blocker
Problem: Why might an instant column addition wait in a synthetic two-session rehearsal?
- A accessed the table within a transaction that remains open.
- DDL may need a metadata lock even when its requested algorithm avoids a table rebuild.
-- A: START TRANSACTION; SELECT id FROM lab_migration_orders WHERE id=1; -- remains open
-- B: ALTER TABLE lab_migration_orders ADD COLUMN source_code VARCHAR(20) NULL, ALGORITHM=INSTANT; -- may wait
-- A: COMMIT;
B may wait for metadata-lock access until A ends.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Investigate the blocker and apply the predeclared stop policy.
Why this result follows: An online or instant algorithm does not eliminate metadata-lock requirements. This follows the stated schema and migration assumptions.
5. Old explicit insert
Problem: What happens in the staged schema when old code names only the original columns?
- The explicit insert supplies the required original id and status columns.
- The newly added nullable column receives NULL when omitted in this scenario.
-- Assumes source_code VARCHAR(20) NULL has been added successfully.
INSERT INTO lab_migration_orders (id, status) VALUES (3, 'new');
SELECT id, status, source_code FROM lab_migration_orders WHERE id=3;
3 | new | NULL
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: 3/new/NULL.
Why this result follows: Explicit column lists can support a compatible expansion when the new column permits omission.
6. Positional insert risk
Problem: Why must an old positional INSERT be tested after a column is added?
- The old statement depends on the tableโs complete column layout.
- Adding source_code changes that layout while the statement still supplies two values.
-- Old consumer statement before expansion:
INSERT INTO lab_migration_orders VALUES (3, 'new');
-- Later schema has id, status, source_code.
The old two-value positional insert no longer matches the three-column layout.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: The consumer requires a compatible explicit-column change.
Why this result follows: Schema compatibility includes client statement shape, not only whether the new column is nullable.
7. New writer
Problem: What value does a compatible new writer store after expansion?
- The new writer explicitly names and supplies source_code.
- The value web fits the declared VARCHAR(20) column in this scenario.
-- Assumes nullable source_code exists.
INSERT INTO lab_migration_orders (id, status, source_code) VALUES (3, 'new', 'web');
SELECT source_code FROM lab_migration_orders WHERE id=3;
web
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: web.
Why this result follows: A new writer can populate the expanded representation without requiring old rows to be complete.
8. Backfill first batch
Problem: What is the result of filling the first missing synthetic row?
- The predicate selects only id 1 while its source_code is missing.
- The update fills that row and leaves id 2 for a later batch.
-- Initial expanded rows: (1,new,NULL), (2,paid,NULL).
UPDATE lab_migration_orders SET source_code='legacy' WHERE id=1 AND source_code IS NULL;
SELECT id, source_code FROM lab_migration_orders ORDER BY id;
1 | legacy
2 | NULL
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: One row filled; one remains NULL.
Why this result follows: A bounded key predicate makes backfill progress observable and limits the write scope.
9. Protect new value
Problem: What happens when a backfill encounters a value already written by new code?
- The current value api is not NULL.
- The backfill predicate therefore does not match the already populated row.
-- Synthetic current row: id 2, source_code = 'api'.
UPDATE lab_migration_orders SET source_code='legacy' WHERE id=2 AND source_code IS NULL;
0 rows changed; source_code remains api.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: The new value is preserved.
Why this result follows: A missing-only predicate avoids overwriting this newer value under the stated rule.
10. Incomplete backfill
Problem: Can NOT NULL be considered ready while one synthetic row remains missing?
- One row still lacks the value required by the proposed final contract.
- The missing row must be resolved and active writers checked before tightening.
-- Synthetic validation: 100 rows total; 99 valid source_code values; 1 NULL.
SELECT COUNT(*) AS remaining FROM lab_migration_orders WHERE source_code IS NULL;
1
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: The column is not ready for NOT NULL.
Why this result follows: Completeness is a prerequisite to enforcing a required field on existing data.
11. Concurrent old writer
Problem: What risk remains if old code can still insert NULL after validation?
- The old writer omits the nullable source_code field.
- The earlier zero count describes only the state at validation time.
-- Synthetic sequence: validation finds 0 NULL rows.
-- An old writer then inserts id 4 without source_code.
-- A later constraint change is attempted.
A new missing value can appear between validation and enforcement.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Make active writers compatible and recheck before tightening.
Why this result follows: A one-time completeness count does not control future concurrent writes. This follows the stated schema and migration assumptions.
12. Bad mapping
Problem: Why is a zero NULL count insufficient to prove a backfill mapping correct?
- The completeness count checks absence, not whether values match their source facts.
- Both non-NULL values can be wrong while the count still reports zero.
-- Synthetic rows: id 1 should map to web; id 2 should map to api.
-- Backfill writes legacy to both, leaving zero NULL values.
Both rows are populated, but their values violate the intended mapping.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Verify representative mappings and domain validity.
Why this result follows: Completeness and correctness are separate validation properties. This follows the stated schema and migration assumptions.
13. Repeated batch
Problem: What happens when a completed missing-only batch is run again?
- The row no longer meets source_code IS NULL after the first successful batch.
- Repeating the same predicate leaves the existing value unchanged.
-- Synthetic current row: id 1, source_code = 'legacy'.
UPDATE lab_migration_orders SET source_code='legacy' WHERE id=1 AND source_code IS NULL;
0 rows changed; legacy remains.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: The repeated batch changes zero rows.
Why this result follows: A carefully scoped missing-only update can be safely repeatable for this stated mapping.
14. Rollback misconception
Problem: Does a surrounding ROLLBACK generally undo the schema change?
- MySQL DDL such as ALTER TABLE has implicit-commit behavior.
- A data-transaction rollback is not a tested reverse migration for the schema.
START TRANSACTION;
ALTER TABLE lab_migration_orders ADD COLUMN source_code VARCHAR(20) NULL;
ROLLBACK;
The ALTER is not generally undone by the rollback.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Use the documented forward repair or recovery procedure.
Why this result follows: DDL transaction behavior differs from ordinary rollbackable DML. This follows the stated schema and migration assumptions.
15. Replica progress
Problem: Why should a synthetic rollout observe replicas after source DDL completes?
- DDL must reach and be applied by the replica in the stated topology.
- New code routed there before application may encounter an incompatible schema.
-- Synthetic topology: source ALTER completes; replica apply is delayed.
-- New application code can read from the replica.
The replica may not yet expose the new schema to readers.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Monitor replica progress and gate routing or rollout appropriately.
Why this result follows: Source completion and replica readiness are separate observations. This follows the stated schema and migration assumptions.
16. Stop threshold
Problem: What should happen when a synthetic metadata-lock wait exceeds the rehearsal limit?
- The observed wait exceeds the five-second limit by three seconds.
- Continuing would violate the decision threshold established before the change.
-- Rehearsal policy: stop if metadata-lock wait exceeds 5 seconds.
-- Observed synthetic wait: 8 seconds.
Stop according to the predeclared policy and investigate the blocker.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Stop and follow the authorized procedure.
Why this result follows: A predeclared threshold turns monitoring evidence into a controlled decision. This follows the stated schema and migration assumptions.
17. Old and new readers
Problem: What should a compatible reader do with existing NULL source_code values?
- Existing rows have not necessarily been backfilled during expansion.
- A reader that assumes a non-NULL code immediately can fail before backfill completes.
-- Synthetic expanded row: id 1, status new, source_code NULL.
-- New reader supports both old and populated representations.
Handle NULL according to the documented compatibility policy.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Read the row without inventing an unverified code.
Why this result follows: The compatibility window requires consumers to tolerate both data states. This follows the stated schema and migration assumptions.
18. Index and resource evidence
Problem: What measurements matter when a backfill touches a large indexed table?
- A backfill can consume write, index-maintenance and replication resources.
- Rows changed alone do not reveal application latency or replica impact.
-- Synthetic rehearsal records batch duration, rows changed, write latency, replica progress and errors.
Compare batch throughput and collateral workload effects with the rollout limits.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Record progress and resource effects for each bounded batch.
Why this result follows: Operational readiness includes the wider workload, not only a successful update count.
19. Counts and identity
Problem: Can two restored migration rows preserve count while one id is wrong?
- The row count remains two in both the expected and observed sets.
- Comparing identities reveals the substitution that the count hides.
-- Expected ids: 1, 2.
-- Synthetic observed ids: 1, 9.
SELECT COUNT(*) FROM lab_migration_orders;
Both sets contain two rows, but id 2 is missing and id 9 is unexpected.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Count alone does not establish correct row identity.
Why this result follows: Representative key checks complement aggregate row-count verification. This follows the stated schema and migration assumptions.
20. Recovery rehearsal
Problem: What evidence demonstrates more than a successful ALTER in a synthetic rehearsal?
- A successful schema statement does not prove that consumers tolerate both data states.
- Backfill, replica readiness and repair each have separate failure paths.
-- Rehearsal checklist: schema definition, old/new reads and writes, backfill validation, replica progress, repair test.
Verify compatibility and tested recovery as well as the DDL result.
Illustrative MySQL 8.4 SQL or labeled synthetic migration scenario; outcomes are conditional and reasoned, and no schema was changed locally.
Expected result: Record all stage results and stop criteria.
Why this result follows: A rollout is a multi-stage contract rather than a single DDL exit status.
Common errors and fixes
An online change waits unexpectedly.
- Why it happens
- A transaction holds a metadata lock needed by the DDL.
- How to fix it
- Investigate authorized lock evidence and resolve the blocking transaction using the approved procedure.
- Prevent it next time
- Rehearse with long transactions and monitor metadata-lock waits.
An old application version fails after deployment.
- Why it happens
- The migration changed a schema contract before every consumer was compatible.
- How to fix it
- Use the documented repair or rollback plan for the deployment.
- Prevent it next time
- Inventory consumers and test the compatibility window.
A failed rollout cannot be undone with ROLLBACK.
- Why it happens
- The plan treated DDL like ordinary transactional DML.
- How to fix it
- Follow the tested forward-repair or restore procedure.
- Prevent it next time
- Document MySQL DDL transaction behavior and rehearse recovery.
20 practice exercises
1. If the disposable ALTER succeeds, what value do existing fixture rows have for source_code?
Show hint
Consider the new columnโs nullability and the absence of supplied values.
Show worked solution
Both existing rows read NULL because the added column is nullable and has no explicitly supplied value. Verify the actual definition and results in the intended lab; the example does not claim a live execution.
If the nullable addition succeeds as specified, both existing fixture rows read NULL for source_code. Inspect the actual table definition and row values in the disposable lab; the conditional example does not establish a live result.
Check your solution
- Row 1 reads NULL.
- Row 2 reads NULL.
2. Why is ALGORITHM=INSTANT not proof of zero downtime?
Show hint
Separate algorithm support from metadata-lock and workload effects.
Show worked solution
The server must support that operation and conditions, and metadata locks and other resource effects still matter. Test representative traffic and long transactions, monitor the rollout, and prepare recovery.
The requested algorithm must be supported for the exact operation and table, and DDL can still wait for metadata locks or affect clients and replicas. Rehearse representative concurrency, monitor stop criteria and prepare a tested repair or restore path.
Check your solution
- Verify operation-specific algorithm support.
- Test metadata waits and recovery.
3. The two-row fixture receives a nullable source_code column successfully. Predict the existing values.
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Both existing rows read NULL because the new column is nullable and no explicit value was supplied for those rows. Verify the actual definition and row results in the isolated lab. This is a conditional prediction, not evidence of a live ALTER.
Check your solution
- Row 1 is NULL
- Row 2 is NULL
4. Explain why ALGORITHM=INSTANT is not a guarantee of zero downtime for a column addition.
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The exact operation and table must support the requested algorithm, and DDL can still wait for metadata locks or affect resources and replicas. Rehearse with representative traffic and long transactions, monitor predeclared limits and prepare a tested recovery path.
Check your solution
- Support is operation-specific
- Metadata-lock waits remain possible
5. An old consumer uses INSERT INTO table VALUES with two values. A third column is added. What must be tested?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The positional statement depends on the full column layout and can fail when the table gains a column. Change and test the consumer to name its intended columns explicitly, and verify that the new nullable column may be omitted. Inventory background jobs as well as the application.
Check your solution
- Positional insert may fail
- Test explicit-column consumer
6. A new writer supplies source_code while an old writer omits it. What compatibility behavior is needed?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The expanded schema and readers must handle both a populated value and NULL during the overlap, according to a documented policy. Test old and new reads and writes before tightening the constraint. Ensure all active writers eventually provide a valid value.
Check your solution
- Readers tolerate both states
- Writers become compatible before tightening
7. A backfill updates 200 rows per batch. Why record batch progress and write latency separately?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Rows updated show progress, but they do not reveal effects on application writes, locks or replicas. Record duration, throughput, write latency, errors and replica progress for each bounded batch. Apply the predeclared stop threshold if operational impact exceeds the agreed limit.
Check your solution
- Track rows and duration
- Track write and replica effects
8. A backfill sets source_code only where it is NULL. What does this protect, and what does it not prove?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The predicate avoids overwriting an already populated value written by new code in the stated design. It does not prove that existing non-NULL values are correct or that every concurrent scenario is safe. Verify mappings and active writer behavior under representative concurrency.
Check your solution
- Preserve existing non-NULL values
- Validate mapping and concurrency
9. A validation query finds one NULL in 100 rows. Should the new NOT NULL constraint be enforced immediately?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
No. Resolve the missing row according to the business mapping, verify all other values and ensure active writers cannot reintroduce NULL. Then rehearse the stricter change with its own locking and recovery plan. A successful earlier nullable addition does not prove readiness.
Check your solution
- One NULL remains
- Verify writers before tightening
10. A zero NULL count is followed by an old writer inserting NULL. What rollout gap does this reveal?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The validation was a point-in-time observation while an incompatible writer remained active. Deploy or gate writers so new missing values cannot appear, then revalidate immediately before enforcement under the intended procedure. A count alone cannot guarantee future completeness.
Check your solution
- Old writer reintroduced NULL
- Gate writers and revalidate
11. A backfill fills every field but assigns the wrong source to two rows. Why does COUNT WHERE NULL miss it?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The missing-value count tests only whether a value exists, not whether it is the correct mapped value. Compare representative keys and source facts and validate the allowed domain in addition to counting NULLs. Correct the mapping under a reviewed procedure before enforcing the final contract.
Check your solution
- Zero NULLs can hide wrong values
- Verify per-row mappings
12. A transaction reads the table and stays open while ALTER waits. Which lock class should be investigated?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Investigate metadata locking and the age and ownership of the blocking transaction. A transaction may retain table metadata protection after its SELECT returns, delaying DDL. Follow the authorized blocker-resolution procedure and the predeclared stop threshold; a longer timeout does not release the lock.
Check your solution
- Investigate metadata lock
- Inspect blocker transaction age
13. A rehearsal sets a five-second lock-wait stop limit and observes eight seconds. What decision follows?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
The observed wait exceeds the limit by three seconds, so stop according to the established rollout policy and investigate the blocker. Do not redefine the threshold during the incident merely to continue. Record the observation and repair plan before another rehearsal.
Check your solution
- Eight exceeds five seconds
- Stop and investigate
14. The source applies DDL but a replica is delayed. Why can new application code still fail?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
A client routed to the replica may reach a schema that has not yet applied the new column. Monitor replica progress and gate rollout or routing according to the documented compatibility plan. Source success alone is not evidence that every read endpoint is ready.
Check your solution
- Replica may lack the column
- Gate routing on readiness
15. A developer plans ROLLBACK after ALTER TABLE as the only reversal. Explain the defect.
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
MySQL DDL such as ALTER TABLE has implicit-commit behavior and is not generally undone by a surrounding application ROLLBACK. Prepare and rehearse a forward repair, reviewed reverse migration or restore strategy. Consider data written by new code before choosing a reversal.
Check your solution
- ROLLBACK is not general DDL undo
- Test an explicit recovery path
16. The DDL succeeds on two rows in a lab. Why is that insufficient to predict production impact?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
A tiny fixture cannot reproduce table size, metadata-lock contention, concurrent workload, replica lag or resource pressure. Use representative synthetic data and traffic in an isolated rehearsal, record the exact server and schema, and compare measurements with predeclared stop criteria.
Check your solution
- Two rows do not represent scale
- Measure locks and workload
17. An ALTER requests INSTANT but the operation is unsupported for the actual table. What should the rollout do?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Treat the rejected statement as a failed stage and stop to review the operation-specific MySQL version and table restrictions. Do not assume an unsupported algorithm succeeded or silently substitute another method. Rehearse a reviewed alternative and its lock and recovery implications.
Check your solution
- Explicit request can fail
- Review and rehearse an alternative
18. Two expected rows have ids 1 and 2; restored rows have ids 1 and 9. Why is count two insufficient?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Both datasets contain two rows, so COUNT(*) alone matches despite the missing id 2 and unexpected id 9. Compare selected keys, relationships and representative values in addition to counts. Use known synthetic expectations to identify the substitution.
Check your solution
- Count remains two
- Ids differ
19. A rollout plan lists only the ALTER statement. Name two missing categories of evidence.
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
It also needs compatibility evidence for old and new consumers and a tested recovery or forward-repair procedure. Record backfill completeness, metadata-lock waits, replica progress and application errors as applicable. A successful DDL statement alone does not demonstrate the full rollout contract.
Check your solution
- Test consumer compatibility
- Test recovery and monitoring
20. A migration changes a column used by reports and a background job. Why inventory both consumers?
Show hint
Trace consumer compatibility, DDL conditions, validation and recovery separately.
Show worked solution
Each consumer may use different SQL assumptions, privileges and deployment timing, so an application-only test can miss failures. Document and test reports, jobs, importers and all running application versions during the compatibility window. Coordinate their rollout before enforcing a stricter schema contract.
Check your solution
- Reports and jobs are consumers
- Test their version overlap
Key takeaways
- Stage changes around old and new application compatibility.
- An explicit algorithm request is not a guarantee of no lock wait.
- Verify data, application behavior, and recovery on representative isolated data.
- Nullable expansion is one stage of an application compatibility contract.
- INSTANT is an algorithm request, not a zero-impact guarantee.
- DDL needs a tested repair or recovery plan outside ordinary transaction rollback.