Create and use external columns

Updated at:

This topic describes the version requirements, table creation and modification syntax, MCE online migration, business transparency, Binlog compatibility, and limitations of external columns.

Scope of application

  • Only Enterprise Edition instances support external columns.

  • The instance version must be 2.6.0_5.4.21-20260830 or later.

    Note

Syntax

Use external columns during table creation

Add EXTERNALIZE at the end of the column definition:

CREATE TABLE chat_messages (
    id          BIGINT PRIMARY KEY AUTO_INCREMENT,
    session_id  BIGINT,
    user_id     BIGINT,
    role        ENUM('user','assistant','system'),
    token_count INT,
    created_at  DATETIME,
    content     LONGTEXT EXTERNALIZE,
    KEY idx_session (session_id, created_at)
) PARTITION BY KEY(session_id);

Add an external column to an existing table

ALTER TABLE chat_messages
    ADD COLUMN reasoning LONGTEXT EXTERNALIZE;

Existing rows have NULL for the new column.

Online migration through MCE

MCE (Modify Column Externalization) migrates existing regular large fields to external columns online. Keep the column name and type unchanged, and add EXTERNALIZE after the column definition:

ALTER TABLE chat_messages
    MODIFY COLUMN content LONGTEXT EXTERNALIZE;

MCE performs dual-write, historical data backfill, consistency verification, read-path switchover, and old payload column reclamation in the background. During migration, applications continue to use the original table, columns, and SQL without any downtime or code changes. Each MCE operation migrates one target column at a time. The table must have a valid primary key, and the source column must allow NULL and must not have a DEFAULT declaration.

Convert back to a regular column

A column that has been externalized can be converted back to a regular column through reverse MCE. Keep the column name and type unchanged, and remove EXTERNALIZE:

ALTER TABLE chat_messages
    MODIFY COLUMN content LONGTEXT;
Note

If a covering column of a Global Secondary Index (GSI) includes the target external column, you must delete the corresponding GSI before reverse migration. GSIs that do not cover the external column do not need to be deleted. Reverse migration cannot be combined with other ALTER operations in the same statement.

Supported data types

  • Text family: TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT.

  • Binary family: BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB.

Note

The column character set must be omitted or belong to the utf8 family (utf8, utf8mb3, utf8mb4).

View table structure

SHOW CREATE TABLE outputs the logical table structure. External columns are still displayed as content LONGTEXT EXTERNALIZE. The underlying physical address columns are transparent to applications.

Business transparency

Applications continue to use the original table and column names. Standard DML, UPSERT, REPLACE, JOIN, and built-in functions work the same as with regular columns. No changes to OSS API calls or additional object address management are required.

Standard write, update, and query

INSERT INTO chat_messages(session_id, user_id, role, content, token_count, created_at)
VALUES (10001, 42, 'assistant', '{...reply content...}', 800, NOW());

UPDATE chat_messages SET content = '{...new content...}' WHERE id = 1;

SELECT content FROM chat_messages WHERE session_id = 10001;

UPSERT

INSERT INTO chat_messages(id, session_id, user_id, role, content, token_count, created_at)
VALUES (1, 10001, 42, 'assistant', '{...latest reply...}', 960, NOW())
ON DUPLICATE KEY UPDATE
    content = VALUES(content),
    token_count = VALUES(token_count),
    created_at = VALUES(created_at);

REPLACE

REPLACE INTO chat_messages(id, session_id, user_id, role, content, token_count, created_at)
VALUES (1, 10001, 42, 'assistant', '{...replaced content...}', 1024, NOW());

JOIN and built-in functions

External columns can participate in JOIN and built-in function expressions. The following query joins a sessions table and uses UPPER and CONCAT to format message display content:

SELECT m.id,
       s.session_title,
       CONCAT(UPPER(m.role), ': ', m.content) AS formatted_content
FROM chat_messages m
JOIN chat_sessions s ON s.id = m.session_id
WHERE s.user_id = 42
ORDER BY m.created_at DESC
LIMIT 20;

If a SQL statement does not involve external columns, for example, querying only role, it follows the pure data node (DN) path.

Binlog compatibility

External columns are compatible with business Binlog and support GDN replication and DTS data reading and synchronization. Downstream consumers continue to use the original table and column names to consume logical column values without identifying or processing internal external column addresses. However, before using these features, confirm that the target instance version supports the current capability.

Limitations

Operation

Supported

Description

CREATE TABLE ... EXTERNALIZE

Yes

--

ALTER TABLE ADD COLUMN ... EXTERNALIZE

Yes

Existing rows have NULL for the new column.

ALTER TABLE DROP COLUMN

Yes

OSS objects are cleaned up asynchronously.

ALTER TABLE MODIFY COLUMN ... EXTERNALIZE

Yes

Online migration through MCE. One target column per operation. Requires a valid primary key.

Remove EXTERNALIZE with same-type MODIFY

Yes

  • Converts back to a regular column through reverse MCE.

  • Only when a covering column of a GSI includes the target external column must the corresponding GSI be deleted first.

Change external column type

No

Cannot change the type or other column attributes through MCE.

ALTER TABLE CHANGE external column

No

Use DROP then ADD instead.

DEFAULT 'xxx'

No

External columns cannot have default values.

Regular, unique, and full-text indexes

No

External columns can appear as covering columns in a Global Secondary Index (GSI).

External column table combined with CCI

No

Tables with an existing Columnar Index (CCI) cannot add or migrate external columns. External column tables cannot create a CCI.

TRUNCATE TABLE

No

--

RENAME TABLE

No

--

CREATE TABLE AS SELECT (source table contains external columns)

No

--

ADD CHECK constraint

No

--

Non-utf8 character set

No

Only utf8, utf8mb3, and utf8mb4 are allowed.

FAQ

  • Do I need to modify application SQL to use external columns?

    No. Applications continue to use the original table and column names. The database handles payload reads and writes at the underlying layer. No OSS address management is required.

  • Do I need to manage OSS myself?

    No. OSS buckets, access credentials, object addresses, data uploads, and lifecycle management are all handled internally by the database. Applications only read and write the original table and columns. No OSS configuration or awareness of underlying objects is required.

  • What are the table requirements for MCE?

    The table must have a valid primary key. Each MCE operation migrates one target column. The source column must allow NULL and must not have a DEFAULT declaration. MCE cannot simultaneously change the field type or combine with other ALTER operations.

  • Can MCE be canceled?

    Yes, but only before the task enters the irreversible phase. If MCE is running, first execute PAUSE DDL <job_id>, confirm through SHOW DDL that the status has changed to PAUSED, and then execute CANCEL DDL <job_id>. After entering the irreversible phase, the task can only move forward to completion.

  • Do external columns support UPSERT, REPLACE, JOIN, and built-in functions?

    Yes. Standard business SQL is supported, including INSERT ... ON DUPLICATE KEY UPDATE, REPLACE INTO, JOIN, and built-in functions such as UPPER and CONCAT. Expressions involving external column payloads require reading the payload. Actual response time (RT) should be verified against query return volume, cache state, and business concurrency.

  • When is OSS space released after data deletion?

    After business data is deleted, the corresponding external objects are asynchronously cleaned up by version in the background. Physical space is gradually released as background cleanup tasks progress after the SQL deletion completes.

  • Which scenarios require careful evaluation?

    Scenarios with large volumes of historical cold reads and strict RT requirements, full-text or fuzzy search on large fields, building regular indexes on external columns, or combining external column tables with CCI should be evaluated separately before migration.