Update Tables from Multiple Streams
Use partial column updates on a Merge-on-Write (MoW) Unique Key table when multiple streams update different columns of the same row. Handle event ordering in the source pipelines to prevent stale events from overwriting newer values.
Warning:
Core 26.1.0 through 26.1.4 do not support
sequence_mapping.*. Partial column updates are supported, but do not provide independent Sequence ordering for each stream. The Sequence Mapping examples at the end of this page describe the upstream mechanism for reference and cannot be used on these releases.
Identify multi-stream update scenarios
In wide-table scenarios in a data warehouse, different columns of the same table often come from different data sources or different processing pipelines. Common cases include:
- Update fields from a real-time stream: Continuously updates some fields of the table (for example, columns related to user behavior).
- Update fields from an offline or on-demand stream: Updates other fields of the table at specific times (for example, columns related to user profiles or tags).
In this scenario, multiple data streams concurrently write to the same primary-key table and face two core problems:
| Pain Point | Description |
|---|---|
| Concurrent overwrite problem | Different data streams arrive at different times. A simple REPLACE aggregation cannot guarantee that the data from each stream is updated in version order. |
| High cost of joining data | Waiting for all streams to assemble a complete row can delay updates. |
The VeloDB Cloud Unique model natively supports version control based on a Sequence column, but only a single global Sequence column can be defined, which cannot independently control the update version of different columns from different data streams. The upstream Sequence Mapping mechanism addresses this with a separate Sequence column for each group of value columns. It is unavailable in the Core releases listed above.
Coordinate updates in supported releases
For Core 26.1.0 through 26.1.4:
- Use a MoW Unique Key table. Include every Key column in each update so the warehouse can identify the row.
- Assign each stream the value columns it owns. Enable partial column updates for the ingestion method, and send the keys and that stream's columns. An ordinary full-row upsert can overwrite omitted columns with defaults or
NULL. - Deduplicate events and reject stale events in the source pipeline before loading. Preserve the order of updates to each key within each stream, including retries. If streams update overlapping columns, resolve the conflict before ingestion.
- If JSON records in the same load contain different sets of updated columns, use flexible column updates and follow their table and ingestion requirements.
A global Sequence column orders updates for the row as a whole. It cannot track a separate version for each stream's column group. If independent per-stream version checks are required, perform them upstream or keep the streams in separate tables and join their results when querying. Partial column updates alone do not reject stale events from each stream.
Review upstream Sequence Mapping examples
Review upstream examples unavailable in Core 26.1.0 through 26.1.4
Control stream ordering with Sequence Mapping
Sequence Mapping is an upstream multi-stream update mechanism for Unique Key tables. Different Sequence columns control separate groups of value columns, allowing each stream to order its updates independently. It uses Merge-on-Read (MoR), unlike the MoW partial updates described above. These examples do not apply to Core 26.1.0 through 26.1.4. Example outputs and timings are illustrative, not measured VeloDB Cloud results. The two table-creation examples reuse upsert_test.
Map streams to Sequence columns
Suppose a Unique table contains the following columns:
| Column | A | B | C | D | E | s1 | s2 |
|---|---|---|---|---|---|---|---|
| Role | Key | Key | Value | Value | Value | Sequence | Sequence |
- Data stream 1 writes to columns
A, B, C, Dand usess1as the version control column. - Data stream 2 writes to columns
A, B, Eand usess2as the version control column.
With this mapping:
s1controls the version of columnsC, D: only when thes1of the new data is greater than thes1of the existing data,C, D, s1are updated.s2controls the version of columnE: only when thes2of the new data is greater than thes2of the existing data,E, s2are updated.- The two streams do not interfere with each other, and queries can read the latest data of all columns.
Configure and test Sequence Mapping
1. Create a table that supports Sequence Mapping
Use the sequence_mapping.<sequence_col> property in PROPERTIES to declare the mapping between a Sequence column and the Value columns it controls.
The following example creates a Unique table where columns c, d are version-controlled by s1, and column e is version-controlled by s2:
CREATE TABLE `upsert_test` (
`a` bigint(20) NULL COMMENT "",
`b` int(11) NULL COMMENT "",
`c` int(11) NULL COMMENT "",
`d` int(11) NULL COMMENT "",
`e` int(11) NULL COMMENT "",
`s1` int(11) NULL COMMENT "",
`s2` int(11) NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY(`a`, `b`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`a`, `b`) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "false",
"light_schema_change" = "true",
"sequence_mapping.s1" = "c,d",
"sequence_mapping.s2" = "e"
);
Supported types for Sequence columns: integer types,
DATE, andDATETIME. The type cannot be changed after the column is created.
After creation, the table schema is as follows:
MySQL > desc upsert_test;
+-------+--------+------+-------+---------+---------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-------+---------+---------+
| a | bigint | Yes | true | NULL | |
| b | int | Yes | true | NULL | |
| c | int | Yes | false | NULL | REPLACE |
| d | int | Yes | false | NULL | REPLACE |
| e | int | Yes | false | NULL | REPLACE |
| s1 | int | Yes | false | NULL | REPLACE |
| s2 | int | Yes | false | NULL | REPLACE |
+-------+--------+------+-------+---------+---------+
2. Write and query data
The following five insert operations demonstrate how different Sequence values affect updates of each column.
Write the first stream's columns: Writes only c, d, s1 and does not write e, s2.
MySQL > insert into upsert_test(a, b, c, d, s1) values (1,1,2,2,2);
Query OK, 1 row affected (0.080 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | e | s1 | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 2 | 2 | NULL | 2 | NULL |
+------+------+------+------+------+------+------+
Keep values when the Sequence value is smaller: s1=1 is less than the existing s1=2, so c, d, s1 are not updated.
MySQL > insert into upsert_test(a, b, c, d, s1) values (1,1,1,1,1);
Query OK, 1 row affected (0.048 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | e | s1 | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 2 | 2 | NULL | 2 | NULL |
+------+------+------+------+------+------+------+
Write the second stream's columns: Writes e, s2. Since the previous s2 was NULL (treated as the smallest value), e, s2 are updated.
MySQL > insert into upsert_test(a, b, e, s2) values (1,1,2,2);
Query OK, 1 row affected (0.043 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | e | s1 | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 2 | 2 | 2 | 2 | 2 |
+------+------+------+------+------+------+------+
Update the first stream with a larger Sequence value: s1=3 is greater than the existing s1=2, so c, d, s1 are updated, while e, s2 are not affected.
MySQL > insert into upsert_test(a, b, c, d, s1) values (1,1,3,3,3);
Query OK, 1 row affected (0.049 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | e | s1 | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 3 | 3 | 2 | 3 | 2 |
+------+------+------+------+------+------+------+
Update both column groups: Writes both groups of columns. Both s1=4 and s2=4 are greater than the existing values, so all columns are updated.
MySQL > insert into upsert_test(a, b, c, d, s1, e, s2) values (1,1,5,5,4,5,4);
Query OK, 1 row affected (0.050 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | e | s1 | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 5 | 5 | 5 | 4 | 4 |
+------+------+------+------+------+------+------+
A summary of the update results:
| Operation | Trigger Condition | Updated Columns |
|---|---|---|
| Insert 1 | First write of c, d, s1 | c, d, s1 |
| Insert 2 | New s1 < existing s1 | None |
| Insert 3 | First write of e, s2 | e, s2 |
| Insert 4 | New s1 > existing s1 | c, d, s1 |
| Insert 5 | Both new s1 and s2 are greater than existing values | c, d, s1, e, s2 |
3. Add or drop columns
A Sequence Mapping table supports dynamically adding or dropping columns and mappings using ALTER TABLE.
Create the initial table: Contains only one mapping s1 -> c,d.
CREATE TABLE `upsert_test` (
`a` bigint(20) NULL COMMENT "",
`b` int(11) NULL COMMENT "",
`c` int(11) NULL COMMENT "",
`d` int(11) NULL COMMENT "",
`s1` int(11) NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY(`a`, `b`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`a`, `b`) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "false",
"light_schema_change" = "true",
"sequence_mapping.s1" = "c,d"
);
Write initial data:
MySQL > insert into upsert_test(a, b, c, d, s1) values (1,1,1,1,1),(1,1,3,3,3),(1,1,2,2,2);
Query OK, 3 rows affected (0.101 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+
| a | b | c | d | s1 |
+------+------+------+------+------+
| 1 | 1 | 3 | 3 | 3 |
+------+------+------+------+------+
Add columns and mapping: Use ALTER TABLE to add columns e, s2 and declare the s2 -> e mapping at the same time.
MySQL > alter table upsert_test add column (e int(11) NULL, s2 bigint) PROPERTIES('sequence_mapping.s2' = 'e');
Query OK, 0 rows affected (0.011 sec)
MySQL > desc upsert_test;
+-------+--------+------+-------+---------+---------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-------+---------+---------+
| a | bigint | Yes | true | NULL | |
| b | int | Yes | true | NULL | |
| c | int | Yes | false | NULL | REPLACE |
| d | int | Yes | false | NULL | REPLACE |
| s1 | int | Yes | false | NULL | REPLACE |
| e | int | Yes | false | NULL | REPLACE |
| s2 | bigint | Yes | false | NULL | REPLACE |
+-------+--------+------+-------+---------+---------+
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | s1 | e | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 3 | 3 | 3 | NULL | NULL |
+------+------+------+------+------+------+------+
Write data after adding the mapping:
MySQL > insert into upsert_test(a, b, e, s2) values (1,1,2,2);
Query OK, 1 row affected (0.052 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | s1 | e | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 3 | 3 | 3 | 2 | 2 |
+------+------+------+------+------+------+------+
MySQL > insert into upsert_test(a, b, c, d, s1, e, s2) values (1,1,5,5,4,5,4);
Query OK, 1 row affected (0.050 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+------+
| a | b | c | d | s1 | e | s2 |
+------+------+------+------+------+------+------+
| 1 | 1 | 5 | 5 | 4 | 5 | 4 |
+------+------+------+------+------+------+------+
Drop columns: Drop the Value column e, and the corresponding mapping is invalidated. Then drop the Sequence column s2.
MySQL > alter table upsert_test drop column e;
Query OK, 0 rows affected (0.006 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+------+
| a | b | c | d | s1 | s2 |
+------+------+------+------+------+------+
| 1 | 1 | 5 | 5 | 4 | 4 |
+------+------+------+------+------+------+
MySQL > alter table upsert_test drop column s2;
Query OK, 0 rows affected (0.005 sec)
MySQL > select * from upsert_test;
+------+------+------+------+------+
| a | b | c | d | s1 |
+------+------+------+------+------+
| 1 | 1 | 5 | 5 | 4 |
+------+------+------+------+------+
Check Sequence Mapping constraints
When using Sequence Mapping, note the following constraints:
| Category | Constraint |
|---|---|
| Table creation configuration | light_schema_change must be enabled. If the sequence_mapping property is not declared at table creation, it cannot be enabled later. |
| Column types | Sequence columns only support integer types and time types (DATE, DATETIME), and the type cannot be changed after creation. |
| Column roles | Neither Sequence columns nor mapped columns can be Key columns. All non-Key columns must be mapped to a Sequence column. |
| Mapping relationships | Mapped columns of different Sequence columns cannot overlap (for example, d cannot be mapped to both s1 and s2). After a mapping is established, it cannot be modified (for example, a column already mapped to s1 cannot be remapped to s2). |
| DDL limitations | Column renaming is not supported. Rollup creation is not supported. |
| Storage mode | Currently only MOR (Merge-on-Read) tables are supported. Enabling alongside a global Sequence column is not supported. Batch delete operations are not supported. |
| Load semantics | Fields not included during loading are automatically filled with default values or NULL. When comparing Sequence columns, NULL is treated as the smallest value. |