Delete Rows through Loading
Load-based batch deletion applies to Unique Key tables in a VeloDB Cloud warehouse. By carrying a delete marker column during data loading, rows to be deleted are marked as deleted, and background Compaction asynchronously cleans them up.
Batch related delete events with other writes to avoid submitting one SQL statement per event. Performance depends on the table layout, batch size, and concurrent workload.
Choose load-based deletion
| Scenario | Description |
|---|---|
| CDC synchronization | When synchronizing from an OLTP database (such as MySQL) to VeloDB Cloud through binlog, Insert and Delete operations appear alternately in the binlog. Using delete markers allows both types of operations to be handled uniformly, so the consumer can process both operations in one loading path. |
| Batch deletion by primary key | Write delete markers for many keys in one load. Repeated individual deletes add transaction and version work. The exact SQL delete path depends on the table model and statement. |
Compare loading with DELETE
| Item | Load-based batch delete | DELETE statement |
|---|---|---|
| Applicable model | Unique Key | Unique Key / Aggregate Key / Duplicate Key |
| Trigger method | Carry delete markers during loading | Execute SQL |
| Data version | Shares the version of the load | Generates a new version each time |
| Work batching | Many keys share a load transaction | Batch conditions or join a staging table to avoid one request per key |
| CDC scenario fit | Native support | Requires extra handling |
Understand delete markers
Follow the marker lifecycle
- Hidden column: Every Unique Key table contains a hidden column
__DORIS_DELETE_SIGN__. A value of1indicates that the row is marked as deleted. - Load-time write: A load task can specify which rows to mark as deleted through mapping conditions. The syntax differs slightly across load methods.
- Query filtering: During query planning, the FE automatically appends the filter condition
__DORIS_DELETE_SIGN__ != true, so marked rows are invisible to users. - Background cleanup: The BE Compaction process periodically performs physical cleanup of rows marked as deleted.
Inspect a delete marker
Create the example table
Create a Unique Key table:
CREATE TABLE example_table (
id BIGINT NOT NULL,
value STRING
)
UNIQUE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 10;
View hidden columns
Use the session variable show_hidden_columns to display hidden columns:
set show_hidden_columns=true;
desc example_table;
+-----------------------+---------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------+------+-------+---------+-------+
| id | bigint | No | true | NULL | |
| value | text | Yes | false | NULL | NONE |
| __DORIS_DELETE_SIGN__ | tinyint | No | false | 0 | NONE |
| __DORIS_VERSION_COL__ | bigint | No | false | 0 | NONE |
+-----------------------+---------+------+-------+---------+-------+
Write a delete marker
Seed the table before writing the marker:
INSERT INTO example_table VALUES (1, 'foo'), (2, 'bar');
SET show_hidden_columns = false;
The table now contains:
+------+-------+
| id | value |
+------+-------+
| 1 | foo |
| 2 | bar |
+------+-------+
Use INSERT INTO to write a delete marker for the row where id = 1 (this is for illustration only; in production, use the corresponding load method):
SET show_hidden_columns=true;
insert into example_table (id, __DORIS_DELETE_SIGN__) values (1, 1);
Verify query results
By default, queries automatically filter out marked rows:
SET show_hidden_columns=false;
select * from example_table;
+------+-------+
| id | value |
+------+-------+
| 2 | bar |
+------+-------+
For diagnostic inspection, enable show_hidden_columns. The following output is illustrative: internal version values and visibility after compaction can differ. Restore the setting afterward.
mysql> set show_hidden_columns=true;
mysql> select * from example_table;
+------+-------+-----------------------+-----------------------+
| id | value | __DORIS_DELETE_SIGN__ | __DORIS_VERSION_COL__ |
+------+-------+-----------------------+-----------------------+
| 1 | NULL | 1 | 3 |
| 2 | bar | 0 | 2 |
+------+-------+-----------------------+-----------------------+
Restore normal query behavior after inspection:
SET show_hidden_columns = false;
Choose a load merge method
A load task controls data merging behavior through merge_type. Three methods are supported:
| merge_type | Behavior | Typical use |
|---|---|---|
| APPEND (default) | Writes rows normally. On Unique Key tables, rows with an existing key replace that key | Regular upserts |
| DELETE | Deletes all rows whose Key columns match the loaded data | Batch deletion by primary key |
| MERGE | Upserts or deletes each key according to the DELETE ON condition | CDC scenarios with mixed Insert/Delete |
Note:
MERGEmust be used together withDELETE ON <condition>.
Configure each load method
The syntax for setting delete markers differs slightly across load methods. Each is described below.
Delete rows with Stream Load
Delete rows with Stream Load
Configure the load: Configure the columns, merge_type, and delete fields in the HTTP Header.
Run the example:
Replace <endpoint> with the HTTPS HTTP endpoint, including its port, from the warehouse connection settings, and replace <sql-user> and <database>. curl prompts for the SQL password. The CSV file contains id,value,delete_flag fields.
curl --location-trusted -u '<sql-user>' \
-H "columns: id,value,delete_flag" \
-H "merge_type: MERGE" \
-H "delete: delete_flag=1" \
-T events.csv \
'<endpoint>/api/<database>/example_table/_stream_load'
Set load parameters:
columns: Map source fields to table columns and temporary fields, includingdelete_flagused by the delete condition.merge_type: The merge method. Valid values areAPPEND,DELETE, andMERGE.delete: Takes effect whenmerge_type=MERGE. Specifies the delete condition. The source marker is a temporary mapping field, not an additional table column.
For more examples, see the "Specify merge_type for Delete operation" and "Specify merge_type for Merge operation" sections in the Stream Load Manual.
Delete rows with Broker Load
Delete rows with Broker Load
Configure the load: Specify delete markers in the LOAD clause using the [MERGE|APPEND|DELETE] keyword and the DELETE ON clause.
Run the load:
Select a cluster for the SQL session and prepare a Unique Key table tbl1 with columns id and name. This HDFS example uses the built-in reader, without a separately deployed Broker. Replace the HDFS endpoint and source credentials with values for your source. The warehouse must be able to reach HDFS.
LOAD LABEL db1.delete_events_001
(
MERGE DATA INFILE("hdfs://<hdfs-host>:<hdfs-port>/events.csv")
INTO TABLE tbl1
COLUMNS TERMINATED BY ","
(tmp_c1, tmp_c2, delete_flag)
SET (id = tmp_c2, name = tmp_c1)
DELETE ON delete_flag = 1
)
WITH HDFS
(
"fs.defaultFS" = "hdfs://<hdfs-host>:<hdfs-port>",
"hadoop.username" = "<hdfs-user>"
)
PROPERTIES ("timeout" = "3600");
Delete rows with Routine Load
Delete rows with Routine Load
Configure the load: When creating a routine load job, specify delete markers using the WITH [MERGE|APPEND|DELETE] and DELETE ON clauses.
Run the load:
Create example_db.example_tbl as a Unique Key table with id and value columns. The Kafka CSV events contain id,value,delete_flag. Replace the bootstrap endpoint and topic, and configure authentication for your Kafka service as described in the Routine Load guide.
CREATE ROUTINE LOAD example_db.delete_events ON example_tbl
WITH MERGE
COLUMNS TERMINATED BY ",",
COLUMNS(id, value, delete_flag),
DELETE ON delete_flag = 1
PROPERTIES
(
"desired_concurrent_number" = "3",
"max_batch_interval" = "20",
"strict_mode" = "true"
)
FROM KAFKA
(
"kafka_broker_list" = "<kafka-bootstrap-host>:<kafka-port>",
"kafka_topic" = "<topic>",
"property.kafka_default_offsets" = "OFFSET_BEGINNING"
);
Resolve common questions
Choose a supported table model
Only the Unique Key model is supported. For Aggregate Key and Duplicate Key tables, use the DELETE statement.
Allow asynchronous storage reclamation
It is asynchronously cleaned up by the BE background Compaction. The timing depends on Compaction scheduling and the number of data versions, and usually requires no user intervention.
Inspect a row deletion marker
Run SET show_hidden_columns=true; and then query the table. The hidden column __DORIS_DELETE_SIGN__ becomes visible. A value of 1 indicates that the row is marked as deleted.
Select MERGE for mixed CDC events
MERGE is recommended, used together with DELETE ON to specify the delete condition. This allows Insert and Delete operations to be processed together in the same load.
Evaluate delete-marker overhead
Normal queries filter out marked rows. The overhead depends on the amount of retained data, compaction, and the query workload. Logical deletion does not guarantee immediate physical storage reclamation.