DEV Community

MySQL Added a Column. When Can Downstream Read It?

ALTER TABLE ... ADD COLUMN shipping_note returns Query OK on MySQL. A few seconds later, the first order carrying that note arrives.

Before the reporting team ships a dashboard built on the new field, three things still need to be proven separately:

  • Does this column really exist in PostgreSQL, and do its type and nullability match expectations?
  • Did the value on the new row actually arrive - did that row survive the change?
  • While the new field is in flight, can the old consumers still read their data as usual?

A successful DDL proves nothing by itself. It is only the first step of the whole chain, not the acceptance conclusion for the whole chain.

The Sentence That Causes the Most Trouble

"Schema evolution" is often described as if the engine forwarded your DDL to the target. A more accurate - and more useful - way to put it is an ordering constraint:

Every downstream write must be handled by a structure compatible with the row that produced it.

If the target has not yet added the column, the write may fail. If some link in the chain quietly drops the field, the job may keep reporting healthy while the data quietly changes shape.

A column that exists and a column that is correct are two different acceptance criteria - this article is about telling them apart.

First, Split the Changes into Two Classes

Not every DDL belongs in the same basket.

Class one - additive and nullable. The new column allows NULL, has no default, and carries no new constraint. This is the only change this article treats as a "candidate for automatic evolution."

Class two - any change that may break an old reader or invalidate existing rows. Drop a column, rename it, narrow a type, or add NOT NULL. Even if the connector can transmit the event, the business layer should not treat it as a compatible release.

If you really need a rename, add the new column first, dual-write and backfill on the source, move the consumers over, then review "retiring the old column" as a separate change. Don't outsource business compatibility to a connector.

The SeaTunnel 3.1.0 schema evolution documentation lists the engine (Zeta only), the sources (MySQL-CDC, Oracle-CDC), the targets, and the supported event types - ADD COLUMN, DROP COLUMN, RENAME COLUMN, MODIFY COLUMN.

Two things matter more than this matrix:

  • Schema evolution is off by default on the CDC source; you must turn it on explicitly with schema-changes.enabled = true.
  • Transform is not supported. If your pipeline projects, renames, or hand-builds output SQL, you cannot assume this path applies.

The docs also state that cross-database DDL does not carry the column's default value.

The last point is worth stating plainly: automatic schema evolution covers a narrow, direct path. It is not a general promise that "any pipeline can adapt to any DDL."

The configuration skeleton for this path is short. Schema change capture is off by default, so it must be enabled on the CDC source; the JDBC sink writes generated SQL against a stable target table:

source {
  MySQL-CDC {
    table-names = ["shop.orders"]
    url = "jdbc:mysql://mysql-host:3306/shop"
    schema-changes.enabled = true
  }
}
sink {
  Jdbc {
    url = "jdbc:postgresql://pg-host:5432/shop"
    driver = "org.postgresql.Driver"
    generate_sink_sql = true
    database = "shop"
    table = "public.orders"
    primary_keys = ["id"]
  }
}

Credentials, server-id, and engine settings are deliberately omitted - this is the minimal shape related to the schema, not a complete job file. The target account needs DML privileges plus permission to alter the target table; don't grant instance-wide privileges to save a step.

Before Changing the Schema, Prove the Stream Is Live

A snapshot that looks aligned proves nothing about the incremental path. Before the DDL, send one deterministic change through the pipeline and wait for it at the target.

Assume shop.orders has completed its initial sync to public.orders, both sides use id as the primary key, and there is a string column status that can serve as a probe. Keys 42 and 43 exist; 44 is free. If the table has other required columns, add them to the INSERT below.

-- MySQL: prove the job has left the snapshot phase and can carry new writes
UPDATE shop.orders SET status = 'cdc-ready-42' WHERE id = 42;

On PostgreSQL, poll SELECT status FROM public.orders WHERE id = 42; until it returns cdc-ready-42, with a predetermined timeout deadline. A fixed sleep is not a synchronization guarantee.

The SeaTunnel 3.1.0 schema-change E2E case uses the same idea - before testing the DDL, use a deterministic DML as a probe. Only then change the schema:

-- MySQL: a nullable new column, plus two traceable writes
ALTER TABLE shop.orders ADD COLUMN shipping_note VARCHAR(120) NULL;
UPDATE shop.orders SET shipping_note = 'cdc-canary-42' WHERE id = 42;
-- the new key verifies INSERT under the new structure
INSERT INTO shop.orders (id, status, shipping_note) VALUES (44, 'cdc-insert', 'cdc-canary-44');

Check the Column, Then Check the Values

First look at what the target actually created, not what you intended to create:

-- PostgreSQL: type, length, nullability, default
SELECT data_type, character_maximum_length, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'orders' AND column_name = 'shipping_note';

Why check this: in JdbcDialect.java at commit 2d3983a, the ADD COLUMN branch only checks whether a column with the same name already exists. It does so by trying SELECT <column> FROM <table> WHERE 1 != 1; if the statement executes, the column is deemed to exist and the physical ADD is skipped. It never compares the existing column's type, length, nullability, or default.

And when the source and sink dialects differ, the code does not carry the default value across databases - there is an explicit TODO there (cross-database defaults). So a green job + an existing column can still hide a definition that doesn't match your intent.

Then check the data. A column that exists is not acceptance:

-- PostgreSQL: the three-row contract
SELECT id, shipping_note FROM public.orders WHERE id IN (42, 43, 44) ORDER BY id;
  • 42: cdc-canary-42 - An existing row picked up the update to the new field
  • 43: NULL - An untouched old row stays stable under the new schema
  • 44: cdc-canary-44 - INSERT works under the new structure

Cross-check all three rows against the source. Then run the real query of the old consumer, not an equivalent query you hand-picked. An explicit column list may be fine, but a program that deserializes SELECT * by ordinal position will break when one more column appears. That is a client contract, not an engine metric - no job dashboard will tell you it broke.

When handing off, draw these four hops explicitly: source DDL → target schema → actual target values → downstream query. Passing any one hop does not mean the next one passes.

The Four-Check Acceptance Card

If you take only one thing from this article, take this card. Run it in an isolated environment with the same topology, versions, and target privileges as production.

  1. Source DDL committed - Evidence: SHOW CREATE TABLE on MySQL - What it cannot prove: That any downstream table changed
  2. Target column defined - Evidence: information_schema.columns - What it cannot prove: That type, length, nullability, or default matches the source
  3. Incremental values landed - Evidence: The 42/43/44 contract above - What it cannot prove: That old consumers can still read
  4. Old consumer still works - Evidence: Its real query, executed - What it cannot prove: That another class of DDL in the future is safe

All four passing - for this additive nullable column - means you're done. One passing loudly doesn't count.

Two Things That Can Stop a Lightweight ADD COLUMN

A Long Transaction on the Target. PostgreSQL's ALTER TABLE documentation states that unless a subform notes otherwise, an ACCESS EXCLUSIVE lock is acquired, and ADD COLUMN is not noted otherwise. The docs also state that you must own the table to alter it.

Adding a column without DEFAULT (or with a non-volatile default) does not rewrite the table - but it still needs that lock, so a long transaction can hold it open. Having INSERT and UPDATE grants on the target does not mean the account can change its definition.

When observing from an operations connection, filter pg_locks by the current database and the table's OID, and call pg_blocking_pids(pid) for the backend waiting on the DDL. If the array contains 0, the blocker is a prepared transaction, not a process you can kill. If XA is enabled, cross-check pg_prepared_xacts against the coordinator's records - don't roll anything back just to "clear the lock."

Decide before release: who runs the DDL, the maximum acceptable lock wait, the criterion for stopping the release when the threshold is exceeded, and how to reconcile the source position against the target's real structure afterward.

The Pause During a Schema Change. On Zeta, after the source receives a schema-change signal, it triggers dedicated before/after checkpoints and pauses capture in the corresponding phase; the coordinator sends checkpoint-end only after the completion notification succeeds, and the paused phase resumes only after receiving it. A brief data gap during the column addition is not necessarily a stuck CDC job.

If the pause exceeds your budget, distinguish three causes before acting: the before-checkpoint hasn't finished, the target DDL hasn't finished, or the after-checkpoint hasn't finished.

Before the schema barrier, the multi-table sink writer drains its write queues, then dispatches the change to the relevant writers - including sibling writers sharing the same physical target. That is an ordering guarantee on that execution path, not a cluster-wide DDL lock. The PostgreSQL example in the docs uses multi_table_sink_replica = 2; XA is a separate test. Neither can be taken as an assertion about your own concurrency and failure conditions.

One hard "don't": if the DDL fails, don't manually add the column on the target and restart. The ADD branch skips the physical change when a column with that name already exists, and the JDBC writer uses a separate connection for physical DDL, so events replayed after a restore will not re-emit it. Don't expect checkpoint or savepoint recovery to roll back a PostgreSQL DDL that has already committed. Rehearse the case where "the structure changed but the job state didn't advance."

The Boundaries of This Article

This procedure covers only a single additive and nullable ADD COLUMN on a direct MySQL-CDC → Jdbc-Postgres path, with no Transform. It deliberately does not certify:

  • Dropping, renaming, narrowing, or NOT NULL. These belong to class two and need their own design and rollback plans.
  • Defaults and constraints landing unchanged across databases. The cross-database path does not carry defaults; the "same name, skip" check does not compare constraints.
  • Any pipeline with a Transform in the middle. The supported path excludes it.
  • Concurrent writes under XA or your own failure conditions. The referenced configuration and test cases cannot prove these.
  • Your production system. When multi-database routing is involved, remember that mapping is part of the contract itself. If two source databases both have orders, don't by default merge independently evolving tables into the same physical target table. Route to stable names and roll out one at a time; combine tables only after schema compatibility and key collisions have both been designed for.

Finally, let one owner drive the change boundary: either take the accepted automatic evolution path and inspect its results, or take a target-first migration with a defined plan for subsequent CDC events. Never let both paths alter the table at the same time.

What to Say at the Release Gate

Back to that Query OK. It only says the DDL was accepted; it proves nothing about anything downstream. The acceptance criterion for release is not "supports ADD COLUMN," but this sentence:

Old readers can still read, the new field really landed, and a restart after failure still explains every row.

Before the dashboard goes live, you should be able to say four things without hedging: which source DDL committed; what the target column's type, length, and nullability actually are; how keys 42, 43, and 44 came out; and which query the old consumer ran - and passed. If any of these is "I assumed," the column merely exists, and the release has not been verified.

A green job is a useful time anchor. It is not the receipt, not the value, and not the compatibility check. Those are three different facts, and each needs its own evidence.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.