Representative interview topic

Data engineering interview: How do you use MySQL invisible columns for safe schema evolution?

DataMedium
Offer.cc Editorial TeamPublished Updated

Question

An old service heavily uses SELECT * on a MySQL table that needs a new field. Explain how an invisible column reduces compatibility risk, and how you would validate writes, indexes, backups, and replication.

Prompt and context

An old client depends on SELECT * and positional result decoding, while a new service needs an additional field. Explain how a MySQL 8.4 INVISIBLE column lets old and new clients coexist, including explicit references, write defaults, indexes, backups, and rollback boundaries.

What the interviewer evaluates

  • Whether you understand that invisibility changes implicit column expansion, not storage or constraint participation.
  • Whether you distinguish SELECT *, explicit lists, INSERT lists, and CREATE TABLE ... SELECT.
  • Whether you consider primary and unique keys, foreign keys, checks, binary logging, and backup restore.
  • Whether you can plan staged rollout, observability, and a final move to VISIBLE queries.

Clarifying questions to ask

Confirm the MySQL version, storage engine, replication topology, backup tools, and whether old clients truly decode by position. Ask whether the new field needs a default, participates in a unique constraint, is consumed by reports or CDC, and must survive rollback with its data intact.

30-second answer

An invisible column is still part of the table, but SELECT * and tbl.* omit it; explicit references can read and write it. Add the field as INVISIBLE so old result shapes stay stable, while new clients use explicit lists for reads and backfills. Test defaults, unique indexes, foreign keys, CDC, backup restore, and CREATE TABLE ... SELECT visibility. After every consumer migrates, change visibility to VISIBLE. It is a compatibility tool, not authorization or data isolation.

Step-by-step deep dive

1. Confirm invisible-column semantics

In MySQL 8.4, an invisible column is absent from SELECT *, tbl.*, and TABLE results unless named explicitly. It does not hide storage, indexes, or constraints, and it is not column-level access control.

2. Design compatible DDL

Use ALTER TABLE ... ADD COLUMN ... INVISIBLE and choose a safe default or NULL behavior for old writes. Keep at least one visible column. New clients should start with explicit lists instead of continuing the * contract.

3. Validate reads, writes, and constraints

Old clients should receive the original column set. New clients explicitly read and write the field; an omitted invisible column receives MySQL’s implicit default behavior. Primary, unique, foreign-key, and check constraints still apply, so test duplicates, cascades, and failed transactions.

4. Account for replication and pipelines

Invisible columns are treated like visible columns in row events; their inclusion depends on settings such as binlog_row_image. Test CDC, ETL, ORM mappings, and data-quality checks with actual column lists instead of inferring replication from SELECT *.

5. Write the smallest migration script

sql
ALTER TABLE orders
  ADD COLUMN risk_score DECIMAL(5, 2) NULL INVISIBLE;

SELECT order_id, status, risk_score
FROM orders
WHERE order_id = ?;

ALTER TABLE orders
  MODIFY COLUMN risk_score DECIMAL(5, 2) NULL VISIBLE;

Run the DDL first, deploy explicit reads and backfills, observe old-client errors and CDC lag, and only then switch visibility. Production planning must also assess locks, online-DDL support, and the rollback window.

6. Check backups, table creation, and restore

mysqldump and SHOW CREATE TABLE preserve invisibility metadata. Restoring to an older server that does not support the feature can make the column visible because version comments are ignored. An explicit invisible column in CREATE TABLE ... SELECT may become visible in the target unless the definition repeats INVISIBLE.

High-quality sample answer

I would treat an invisible column as a compatibility tool, not a security boundary. First verify that old clients really depend on SELECT *, then add an INVISIBLE column with nullable or safe-default semantics through an online DDL path. Old clients keep their original result shape; new clients must use explicit lists for reads, backfills, and writes. Tests cover defaults, explicit updates, primary and unique conflicts, foreign keys and checks, ORM mappings, CDC behavior under binlog_row_image, backup restore, and CREATE TABLE ... SELECT visibility. During migration, monitor error rate, replication lag, and data integrity. After every consumer uses a stable explicit contract, switch the field to VISIBLE. Rollback can restore the application version while retaining the column and data; cross-version restore requires checking support and dump metadata. Long term, remove SELECT * so the result contract is explicit.

Common mistakes

  • Assuming invisible columns do not participate in keys, checks, foreign keys, or binary logging.
  • Testing only SELECT * and skipping explicit reads, writes, and ORM mappings.
  • Treating invisibility as column permissions, privacy, or data isolation.
  • Ignoring CREATE TABLE ... SELECT, dump restore, and older-server behavior.
  • Continuing to use SELECT * in new clients and recreating the compatibility problem later.

Follow-up questions and responses

Does an invisible column solve every SELECT * compatibility problem?

No. It stabilizes the returned set, but positional decoding, ORM reflection, reports, and CDC still need individual validation. The long-term fix is explicit column lists.

What happens on insert when the invisible column is omitted?

It receives MySQL’s implicit default behavior. To write a specific value, name the column explicitly and test NOT NULL, unique, and check constraints.

When should you change it back to VISIBLE?

After reads, writes, CDC, backups, and reports all use a stable explicit contract, and monitoring and rollback drills pass. Then change visibility in a staged rollout.

Public sources

Related questions