forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
insert_deduplication_token setting for INSERT statement
The setting allows a user to provide own deduplication semantic in Replicated*MergeTree If provided, it's used instead of data digest to generate block ID So, for example, by providing a unique value for the setting in each INSERT statement, user can avoid the same inserted data being deduplicated Inserting data within the same INSERT statement are split into blocks according to the *insert_block_size* settings (max_insert_block_size, min_insert_block_size_rows, min_insert_block_size_bytes). Each block with the same INSERT statement will get an ordinal number. The ordinal number is added to insert_deduplication_token to get block dedup token i.e. <token>_0, <token>_1, ... Deduplication is done per block So, to guarantee deduplication for two same INSERT queries, dedup token and number of blocks to have to be the same Issue: ClickHouse#7461
- Loading branch information
1 parent
fa011c6
commit 100ee92
Showing
9 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/queries/0_stateless/02124_insert_deduplication_token_multiple_blocks_replica.reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
insert 2 blocks with dedup token, 1 row per block | ||
2 | ||
1 | ||
2 | ||
insert deduplicated by token | ||
2 | ||
1 | ||
2 | ||
insert the same data by providing different dedup token | ||
4 | ||
1 | ||
1 | ||
2 | ||
2 | ||
insert 4 blocks, 2 deduplicated, 2 inserted | ||
6 | ||
1 | ||
1 | ||
2 | ||
2 | ||
3 | ||
4 | ||
disable token based deduplication, insert the same data as with token | ||
10 | ||
1 | ||
1 | ||
1 | ||
2 | ||
2 | ||
2 | ||
3 | ||
3 | ||
4 | ||
4 |
35 changes: 35 additions & 0 deletions
35
tests/queries/0_stateless/02124_insert_deduplication_token_multiple_blocks_replica.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
# shellcheck source=../shell_config.sh | ||
. "$CURDIR"/../shell_config.sh | ||
|
||
QUERY_COUNT_ORIGIN_BLOCKS="SELECT COUNT(*) FROM system.parts WHERE table = 'block_dedup_token' AND min_block_number == max_block_number;" | ||
QUERY_SELECT_FROM_TABLE_ORDERED="SELECT * FROM block_dedup_token ORDER BY id;" | ||
|
||
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS block_dedup_token SYNC" | ||
$CLICKHOUSE_CLIENT --query="CREATE TABLE block_dedup_token (id Int32) ENGINE=ReplicatedMergeTree('/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX/{table}', '{replica}') ORDER BY id" | ||
|
||
$CLICKHOUSE_CLIENT --query="SELECT 'insert 2 blocks with dedup token, 1 row per block'" | ||
DEDUP_TOKEN='dedup1' | ||
echo 'INSERT INTO block_dedup_token VALUES (1), (2)' | ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&max_insert_block_size=1&min_insert_block_size_rows=0&min_insert_block_size_bytes=0&insert_deduplication_token='$DEDUP_TOKEN'&query=" --data-binary @- | ||
$CLICKHOUSE_CLIENT --multiquery --query "$QUERY_COUNT_ORIGIN_BLOCKS;$QUERY_SELECT_FROM_TABLE_ORDERED" | ||
|
||
$CLICKHOUSE_CLIENT --query="SELECT 'insert deduplicated by token'" | ||
echo 'INSERT INTO block_dedup_token VALUES (1), (2)' | ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&max_insert_block_size=1&min_insert_block_size_rows=0&min_insert_block_size_bytes=0&insert_deduplication_token='$DEDUP_TOKEN'&query=" --data-binary @- | ||
$CLICKHOUSE_CLIENT --multiquery --query "$QUERY_COUNT_ORIGIN_BLOCKS;$QUERY_SELECT_FROM_TABLE_ORDERED" | ||
|
||
$CLICKHOUSE_CLIENT --query="SELECT 'insert the same data by providing different dedup token'" | ||
DEDUP_TOKEN='dedup2' | ||
echo 'INSERT INTO block_dedup_token VALUES (1), (2)' | ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&max_insert_block_size=1&min_insert_block_size_rows=0&min_insert_block_size_bytes=0&insert_deduplication_token='$DEDUP_TOKEN'&query=" --data-binary @- | ||
$CLICKHOUSE_CLIENT --multiquery --query "$QUERY_COUNT_ORIGIN_BLOCKS;$QUERY_SELECT_FROM_TABLE_ORDERED" | ||
|
||
$CLICKHOUSE_CLIENT --query="SELECT 'insert 4 blocks, 2 deduplicated, 2 inserted'" | ||
echo 'INSERT INTO block_dedup_token VALUES (1), (2), (3), (4)' | ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&max_insert_block_size=1&min_insert_block_size_rows=0&min_insert_block_size_bytes=0&insert_deduplication_token='$DEDUP_TOKEN'&query=" --data-binary @- | ||
$CLICKHOUSE_CLIENT --multiquery --query "$QUERY_COUNT_ORIGIN_BLOCKS;$QUERY_SELECT_FROM_TABLE_ORDERED" | ||
|
||
$CLICKHOUSE_CLIENT --query="SELECT 'disable token based deduplication, insert the same data as with token'" | ||
DEDUP_TOKEN='' | ||
echo 'INSERT INTO block_dedup_token VALUES (1), (2), (3), (4)' | ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&max_insert_block_size=1&min_insert_block_size_rows=0&min_insert_block_size_bytes=0&insert_deduplication_token='$DEDUP_TOKEN'&query=" --data-binary @- | ||
$CLICKHOUSE_CLIENT --multiquery --query "$QUERY_COUNT_ORIGIN_BLOCKS;$QUERY_SELECT_FROM_TABLE_ORDERED" | ||
|
||
$CLICKHOUSE_CLIENT --query="DROP TABLE block_dedup_token SYNC" |
24 changes: 24 additions & 0 deletions
24
tests/queries/0_stateless/02124_insert_deduplication_token_replica.reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
create replica 1 and check deduplication | ||
two inserts with exact data, one inserted, one deduplicated by data digest | ||
1 1001 | ||
two inserts with the same dedup token, one inserted, one deduplicated by the token | ||
1 1001 | ||
1 1001 | ||
reset deduplication token and insert new row | ||
1 1001 | ||
1 1001 | ||
2 1002 | ||
create replica 2 and check deduplication | ||
inserted value deduplicated by data digest, the same result as before | ||
1 1001 | ||
1 1001 | ||
2 1002 | ||
inserted value deduplicated by dedup token, the same result as before | ||
1 1001 | ||
1 1001 | ||
2 1002 | ||
new record inserted by providing new deduplication token | ||
1 1001 | ||
1 1001 | ||
2 1002 | ||
2 1002 |
48 changes: 48 additions & 0 deletions
48
tests/queries/0_stateless/02124_insert_deduplication_token_replica.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- insert data duplicates by providing deduplication token on insert | ||
|
||
DROP TABLE IF EXISTS insert_dedup_token1 SYNC; | ||
DROP TABLE IF EXISTS insert_dedup_token2 SYNC; | ||
|
||
select 'create replica 1 and check deduplication'; | ||
CREATE TABLE insert_dedup_token1 ( | ||
id Int32, val UInt32 | ||
) ENGINE=ReplicatedMergeTree('/clickhouse/tables/{database}/insert_dedup_token', 'r1') ORDER BY id; | ||
|
||
select 'two inserts with exact data, one inserted, one deduplicated by data digest'; | ||
INSERT INTO insert_dedup_token1 VALUES(1, 1001); | ||
INSERT INTO insert_dedup_token1 VALUES(1, 1001); | ||
SELECT * FROM insert_dedup_token1 ORDER BY id; | ||
|
||
select 'two inserts with the same dedup token, one inserted, one deduplicated by the token'; | ||
set insert_deduplication_token = '1'; | ||
INSERT INTO insert_dedup_token1 VALUES(1, 1001); | ||
INSERT INTO insert_dedup_token1 VALUES(2, 1002); | ||
SELECT * FROM insert_dedup_token1 ORDER BY id; | ||
|
||
select 'reset deduplication token and insert new row'; | ||
set insert_deduplication_token = ''; | ||
INSERT INTO insert_dedup_token1 VALUES(2, 1002); | ||
SELECT * FROM insert_dedup_token1 ORDER BY id; | ||
|
||
select 'create replica 2 and check deduplication'; | ||
CREATE TABLE insert_dedup_token2 ( | ||
id Int32, val UInt32 | ||
) ENGINE=ReplicatedMergeTree('/clickhouse/tables/{database}/insert_dedup_token', 'r2') ORDER BY id; | ||
|
||
select 'inserted value deduplicated by data digest, the same result as before'; | ||
set insert_deduplication_token = ''; | ||
INSERT INTO insert_dedup_token2 VALUES(1, 1001); -- deduplicated by data digest | ||
SELECT * FROM insert_dedup_token2 ORDER BY id; | ||
|
||
select 'inserted value deduplicated by dedup token, the same result as before'; | ||
set insert_deduplication_token = '1'; | ||
INSERT INTO insert_dedup_token2 VALUES(3, 1003); -- deduplicated by dedup token | ||
SELECT * FROM insert_dedup_token2 ORDER BY id; | ||
|
||
select 'new record inserted by providing new deduplication token'; | ||
set insert_deduplication_token = '2'; | ||
INSERT INTO insert_dedup_token2 VALUES(2, 1002); -- inserted | ||
SELECT * FROM insert_dedup_token2 ORDER BY id; | ||
|
||
DROP TABLE insert_dedup_token1 SYNC; | ||
DROP TABLE insert_dedup_token2 SYNC; |