Update Selected Columns
In data update workflows, business requirements often call for modifying only a subset of fields in a row, for example:
- Update fields in real time: a user-tag table needs to keep the latest behavior fields up to date in real time so that ads and recommendation systems can perform real-time analysis and decision making.
- Join multiple sources into a wide table: data from several source tables is joined by primary key into one wide table, where each source table contributes only some of the columns.
- Correct field values: a batch operation corrects the values of certain fields in some records while leaving the other fields unchanged.
UPDATE first scans rows that match a predicate, then writes modified data. For frequent changes already identified by primary key, load-based partial updates avoid a separate application-side query and full-row assembly.
Partial column updates let your client send only the keys and changed columns. A MoW Unique Key table still reads existing values to fill missing columns and writes the resulting rows. An Aggregate Key table uses aggregation semantics, such as REPLACE_IF_NOT_NULL, to combine values.
Prepare the environment
Run SQL in the warehouse SQL Editor or a connected client. Select a database and use a SQL user with the required table and load privileges. Examples are independent unless stated otherwise, and outputs are illustrative.
For Stream Load commands, replace <endpoint> with the warehouse HTTP endpoint, including its HTTPS scheme and port, from Connection Methods. Replace <sql-user> with your SQL user. curl -u prompts for its password. Replace database names and source connection placeholders for your environment.
Compare partial update methods
| Data model | Implementation | Write performance | Query performance | Use cases |
|---|---|---|---|---|
| Unique Key (Merge-on-Write) | Fill in the full row at write time | Medium (affected by IO) | High | Real-time updates, scenarios sensitive to query performance |
Aggregate Key (REPLACE_IF_NOT_NULL) | Aggregate at query time | High (comparable to a normal load) | Depends on query-time aggregation work | Scenarios sensitive to write throughput where lower query performance is acceptable |
Update columns in Unique Key tables
For a Merge-on-Write Unique Key table, provide every Key column and the Value columns you want to update. Unspecified columns in existing rows retain their values. New keys follow the configured new-row behavior.
Warning:
- Partial column updates require the Merge-on-Write implementation of Unique Key.
- You can use
INSERT INTOfor partial column updates by settingenable_unique_key_partial_update=true.- Partial column updates are not supported on tables that have synchronous materialized views or cluster keys.
- Partial column updates are not supported on tables that are undergoing a Schema Change.
Create and seed an order table
Create and seed a Unique Key order table
Assume your warehouse contains an order table order_tbl, where the order ID is the Key column and the order status and order amount are Value columns. Create it with the Merge-on-Write Unique-Key model and load the seed row:
CREATE TABLE order_tbl (
order_id INT,
order_status VARCHAR(64),
order_amount INT
)
UNIQUE KEY (order_id)
DISTRIBUTED BY HASH (order_id) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "true"
);
INSERT INTO order_tbl VALUES (1, 'Pending payment', 100);
The current data is then:
| Order ID | Order amount | Order status |
|---|---|---|
| 1 | 100 | Pending payment |
+----------+--------------+------------------+
| order_id | order_amount | order_status |
+----------+--------------+------------------+
| 1 | 100 | Pending payment |
+----------+--------------+------------------+
1 row in set (0.01 sec)
When the user clicks pay, the order status of order ID 1 needs to change to Pending shipment without affecting the order amount field.
Load partial column updates
Update columns with Stream Load
Prepare the following CSV file:
1,Pending shipment
Save this data as update.csv. In Stream Load, add the following HTTP header:
partial_columns:true
In the columns parameter, specify the columns to load (all Key columns must be included, otherwise the update cannot be performed). The following is a Stream Load example:
curl --location-trusted -u '<sql-user>' \
-H "partial_columns:true" \
-H "column_separator:," \
-H "columns:order_id,order_status" \
-T update.csv \
<endpoint>/api/db1/order_tbl/_stream_load
For Broker Load and Routine Load, configure "partial_columns" = "true" in the job properties and map the source columns with their SQL clauses. HTTP headers apply only to Stream Load.
Update columns with INSERT INTO
Across all data models, the default behavior of INSERT INTO with a subset of columns is a full-row write. To prevent misuse, in the Merge-on-Write implementation INSERT INTO still defaults to full-row UPSERT semantics. To enable partial column update semantics, first set the following session variable:
SET enable_unique_key_partial_update=true;
INSERT INTO order_tbl (order_id, order_status) VALUES (1, 'Pending shipment');
Update columns with the Flink connector
When using the Flink Connector, add the following configuration:
'sink.properties.partial_columns' = 'true'
Specify the columns to load in sink.properties.columns (all Key columns must be included, otherwise the update cannot be performed).
Verify updated values
The result after the update is as follows:
+----------+--------------+-------------------+
| order_id | order_amount | order_status |
+----------+--------------+-------------------+
| 1 | 100 | Pending shipment |
+----------+--------------+-------------------+
1 row in set (0.01 sec)
Optimize partial update writes
Merge-on-Write fills missing values at write time, so queries can read the resolved row. Reading historical values and rewriting rows adds work to each partial update.
Optimize write performance:
-
Batch updates and size the cluster: Filling missing columns reads historical data. Monitor cluster I/O and load latency with representative batches before increasing concurrency.
-
Evaluate row store for wide tables: Row store can reduce the reads needed to retrieve missing columns, at the cost of additional storage. Enable it at table creation with the following property:
"store_row_column" = "true"
Use the same column set within a batch: all rows in the same batch write task (whether a load task or INSERT INTO) can update only the same set of columns. To update different columns, split the data into multiple batches. This constraint can be removed with the flexible column update feature described below.
Update different columns in each row
Fixed partial updates require a common column set for all rows in a load. Flexible partial updates allow each JSON row in a single load to update a different set of columns. Starting from Core 26.1.0, Routine Load also supports this mode.
Warning:
- Flexible column update supports Stream Load, Routine Load, and any tool that uses Stream Load as the underlying load method (such as the Flink Doris Connector).
- The load file must be in JSON format when using flexible column update.
Identify flexible update scenarios
When CDC is used to synchronize data from another system to VeloDB Cloud in real time, the records emitted by the source system may not be full rows but only the primary key plus the updated columns. In this case, within a time window the rows in a batch may each update different columns, and flexible column update can be used to load such data into VeloDB Cloud.
Configure flexible column updates
1. Enable flexible column updates
Enable flexible updates on a new table: specify the following properties at table creation to enable Merge-on-Write and add the bitmap hidden column required by flexible column update:
"enable_unique_key_merge_on_write" = "true"
"enable_unique_key_skip_bitmap_column" = "true"
Enable flexible updates on an existing table: for an existing Merge-on-Write table without the skip bitmap column, you can enable flexible column update with the following statement:
ALTER TABLE db1.tbl1 ENABLE FEATURE "UPDATE_FLEXIBLE_COLUMNS";
After execution, run SHOW CREATE TABLE db1.tbl1. If the result contains "enable_unique_key_skip_bitmap_column" = "true", the feature has been enabled successfully.
Tip:
Before using this approach on an existing table, make sure light-schema-change is enabled on the target table.
2. Enable flexible updates in load tasks
The configuration for each load method is as follows:
| Load method | Configuration item | Value |
|---|---|---|
| Stream Load | header | unique_key_update_mode:UPDATE_FLEXIBLE_COLUMNS |
| Flink Doris Connector | sink property | 'sink.properties.unique_key_update_mode' = 'UPDATE_FLEXIBLE_COLUMNS' |
| Routine Load | PROPERTIES | "unique_key_update_mode" = "UPDATE_FLEXIBLE_COLUMNS" |
Create a Routine Load job:
CREATE ROUTINE LOAD db1.job1 ON tbl1
PROPERTIES (
"format" = "json",
"unique_key_update_mode" = "UPDATE_FLEXIBLE_COLUMNS"
)
FROM KAFKA (
"kafka_broker_list" = "<kafka-broker>:9092",
"kafka_topic" = "my_topic",
"property.kafka_default_offsets" = "OFFSET_BEGINNING"
);
You can also use ALTER ROUTINE LOAD to change the update mode of an existing Routine Load job:
-- 1. Pause the job
PAUSE ROUTINE LOAD FOR db1.job1;
-- 2. Change the update mode
ALTER ROUTINE LOAD FOR db1.job1
PROPERTIES (
"unique_key_update_mode" = "UPDATE_FLEXIBLE_COLUMNS"
);
-- 3. Resume the job
RESUME ROUTINE LOAD FOR db1.job1;
Warning:
Check Routine Load restrictions
When using
UPDATE_FLEXIBLE_COLUMNSmode in Routine Load, the following restrictions apply:
- The data format must be JSON (
"format" = "json").- The
jsonpathsproperty cannot be specified.- The
fuzzy_parseoption cannot be enabled.- The
COLUMNSclause cannot be used.- The
WHEREclause cannot be used.
Apply flexible updates to an example table
Apply flexible updates to JSON rows
Step 1: Create a test table
CREATE TABLE t1 (
`k` INT NULL,
`v1` BIGINT NULL,
`v2` BIGINT NULL DEFAULT "9876",
`v3` BIGINT NOT NULL,
`v4` BIGINT NOT NULL DEFAULT "1234",
`v5` BIGINT NULL
) UNIQUE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "true",
"enable_unique_key_skip_bitmap_column" = "true"
);
Step 2: Load and query the initial data
INSERT INTO t1 VALUES
(0, 0, 0, 0, 0, 0),
(1, 1, 1, 1, 1, 1),
(2, 2, 2, 2, 2, 2),
(3, 3, 3, 3, 3, 3),
(4, 4, 4, 4, 4, 4),
(5, 5, 5, 5, 5, 5);
mysql> select * from t1;
+---+----+----+----+----+----+
| k | v1 | v2 | v3 | v4 | v5 |
+---+----+----+----+----+----+
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 2 | 2 | 2 | 2 | 2 | 2 |
| 3 | 3 | 3 | 3 | 3 | 3 |
| 4 | 4 | 4 | 4 | 4 | 4 |
| 5 | 5 | 5 | 5 | 5 | 5 |
+---+----+----+----+----+----+
Step 3: Prepare flexible column update data
Save the following newline-delimited JSON as test1.json. Each row can update a different set of columns:
{"k": 0, "__DORIS_DELETE_SIGN__": 1}
{"k": 1, "v1": 10}
{"k": 2, "v2": 20, "v5": 25}
{"k": 3, "v3": 30}
{"k": 4, "v4": 20, "v1": 43, "v3": 99}
{"k": 5, "v5": null}
{"k": 6, "v1": 999, "v3": 777}
{"k": 2, "v4": 222}
{"k": 1, "v2": 111, "v3": 111}
Step 4: Load through Stream Load
curl --location-trusted -u '<sql-user>' \
-H "Expect:100-continue" \
-H "strict_mode:false" \
-H "format:json" \
-H "read_json_by_line:true" \
-H "unique_key_update_mode:UPDATE_FLEXIBLE_COLUMNS" \
-T test1.json \
-XPUT <endpoint>/api/d1/t1/_stream_load
Step 5: Check the update result
mysql> select * from t1;
+---+-----+------+-----+------+--------+
| k | v1 | v2 | v3 | v4 | v5 |
+---+-----+------+-----+------+--------+
| 1 | 10 | 111 | 111 | 1 | 1 |
| 2 | 2 | 20 | 2 | 222 | 25 |
| 3 | 3 | 3 | 30 | 3 | 3 |
| 4 | 43 | 4 | 99 | 20 | 4 |
| 5 | 5 | 5 | 5 | 5 | <null> |
| 6 | 999 | 9876 | 777 | 1234 | <null> |
+---+-----+------+-----+------+--------+
Check flexible update constraints
- As with normal partial column updates, flexible column update requires every row to contain all Key columns. Rows that do not satisfy this requirement are filtered and counted in
filter rows. Whenfiltered rowsexceeds the upper bound allowed by the load'smax_filter_ratio, the entire load fails. Each filtered row is recorded in the error log. - Among the key-value pairs in a JSON object, only those whose Key matches a column name in the target table take effect. The rest are ignored. In addition, key-value pairs whose Key is
__DORIS_VERSION_COL__,__DORIS_ROW_STORE_COL__, or__DORIS_SKIP_BITMAP_COL__are also ignored. - Flexible column update is not supported on tables containing Variant columns.
- Flexible column update is not supported on tables that have synchronous materialized views.
- When using flexible column update, the following load parameters cannot be specified or enabled:
merge_typedeletefuzzy_parsecolumnsjsonpathshidden_columnsfunction_column.sequence_colsqlmemtable_on_sink_nodemove-forwardgroup_commitwhere
Control the behavior of new rows
The session variable or load property partial_update_new_key_behavior controls the behavior of newly inserted rows in partial column updates and flexible column updates.
| Value | Behavior |
|---|---|
ERROR | The Key of every row must already exist in the table, otherwise the load fails. |
APPEND | Both updating existing rows and inserting new rows whose Key does not exist are allowed. |
Create an example table
CREATE TABLE user_profile (
id INT,
name VARCHAR(10),
age INT,
city VARCHAR(10),
balance DECIMAL(9, 0),
last_access_time DATETIME
) ENGINE=OLAP
UNIQUE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "true"
);
Existing data in the table:
mysql> select * from user_profile;
+----+-------+-----+----------+---------+---------------------+
| id | name | age | city | balance | last_access_time |
+----+-------+-----+----------+---------+---------------------+
| 1 | kevin | 18 | shenzhen | 400 | 2023-07-01 12:00:00 |
+----+-------+-----+----------+---------+---------------------+
Reject new rows with ERROR
Because the Keys of the second and third rows (3 and 18) do not exist in the original table, this insert fails:
SET enable_unique_key_partial_update=true;
SET partial_update_new_key_behavior=ERROR;
INSERT INTO user_profile (id, balance, last_access_time) VALUES
(1, 500, '2023-07-03 12:00:01'),
(3, 23, '2023-07-03 12:00:02'),
(18, 9999999, '2023-07-03 12:00:03');
-- Error:
-- (1105, "errCode = 2, detailMessage = (127.0.0.1)[INTERNAL_ERROR]tablet error:
-- [E-7003]Can't append new rows in partial update when partial_update_new_key_behavior is ERROR.
-- Row with key=[3] is not in table., host: 127.0.0.1")
Append new rows with APPEND
SET enable_unique_key_partial_update=true;
SET partial_update_new_key_behavior=APPEND;
INSERT INTO user_profile (id, balance, last_access_time) VALUES
(1, 500, '2023-07-03 12:00:01'),
(3, 23, '2023-07-03 12:00:02'),
(18, 9999999, '2023-07-03 12:00:03');
After execution, the original row is updated and two new rows are added. For columns that the user did not specify:
- If the column has a default value, the default value is used.
- Otherwise, if the column allows NULL, NULL is used.
- Otherwise, the insert fails.
Query result:
mysql> select * from user_profile;
+----+-------+------+----------+---------+---------------------+
| id | name | age | city | balance | last_access_time |
+----+-------+------+----------+---------+---------------------+
| 1 | kevin | 18 | shenzhen | 500 | 2023-07-03 12:00:01 |
| 3 | NULL | NULL | NULL | 23 | 2023-07-03 12:00:02 |
| 18 | NULL | NULL | NULL | 9999999 | 2023-07-03 12:00:03 |
+----+-------+------+----------+---------+---------------------+
Update columns in Aggregate Key tables
The Aggregate table is mainly used for pre-aggregation scenarios, but it can also achieve a partial column update effect by setting the aggregate function to REPLACE_IF_NOT_NULL.
Create the table
Run this Aggregate Key example in a separate database from the Unique Key example, or use a different table name. Set the aggregate function of each field that needs column update to REPLACE_IF_NOT_NULL:
CREATE TABLE order_tbl (
order_id INT(11) NULL,
order_amount INT(11) REPLACE_IF_NOT_NULL NULL,
order_status VARCHAR(100) REPLACE_IF_NOT_NULL NULL
) ENGINE=OLAP
AGGREGATE KEY(order_id)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(order_id) BUCKETS 1;
Write data
Whether you use Stream Load, Broker Load, Routine Load, or INSERT INTO, simply write the data of the fields to be updated. No additional parameters are required.
Update selected Aggregate Key columns
Update selected Aggregate Key columns
The example is the same as before. The corresponding Stream Load command is (no extra header is needed):
$ cat update.csv
1,Pending shipment
curl --location-trusted -u '<sql-user>' \
-H "column_separator:," \
-H "columns:order_id,order_status" \
-T ./update.csv \
<endpoint>/api/db1/order_tbl/_stream_load
The corresponding INSERT INTO statement is (no extra session variable is needed):
INSERT INTO order_tbl (order_id, order_status) VALUES (1, 'Pending shipment');
Review aggregate update behavior
- Evaluate write performance: the Aggregate Key Model does no extra processing during writes, so write performance is the same as a normal data load.
- Evaluate query performance: Aggregate Key queries may need to combine multiple row versions. The overhead depends on the data, compaction state, and query.
- NULL value restriction: because the
REPLACE_IF_NOT_NULLaggregate function takes effect only on non-NULL values, a field value cannot be changed to NULL.
Troubleshoot partial update errors
| Symptom | Check and resolution |
|---|---|
| A partial update is rejected for the table | Use a MoW Unique Key table. Check synchronous materialized views and active schema changes. Flexible updates also require light schema change, a skip bitmap column, and no Variant columns. |
| Rows are filtered or a new key fails | Include all Key columns, check partial_update_new_key_behavior, and ensure missing fields can use defaults or NULL. Inspect the load response before retrying. |
| A flexible load rejects its parameters | Use JSON and remove options that conflict with the selected load interface, as listed above. |
| Authentication or connection fails | Use the warehouse endpoint and SQL credentials, and verify source connectivity and network access. |
Partial updates consume cluster compute and read existing data. Row store adds storage overhead. Drop the example tables and stop any test Routine Load jobs when you finish.