Skip to content

Commit 43943e7

Browse files
Backport ClickHouse#91386 to 25.8: Reset async_insert value in the queue
1 parent cc1a701 commit 43943e7

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

src/Interpreters/AsynchronousInsertQueue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,8 @@ try
826826
/// 'resetParser' doesn't work for parallel parsing.
827827
key.settings->set("input_format_parallel_parsing", false);
828828
/// It maybe insert into distributed table.
829-
/// It doesn't make sense to make insert into destination tables asynchronous.
830-
key.settings->set("async_insert", false);
829+
/// We want the remote part to decide if the insert will be async or not.
830+
key.settings->setDefaultValue("async_insert");
831831

832832
insert_context->makeQueryContext();
833833

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2
2+
4
3+
1 test1
4+
1 test1
5+
2 test2
6+
2 test2
7+
3 test3
8+
3 test3
9+
4 test4
10+
4 test4
11+
5 test5
12+
5 test5
13+
6 test6
14+
6 test6
15+
7 test7
16+
7 test7
17+
8 test8
18+
8 test8
19+
9 test9
20+
9 test9
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
# shellcheck source=../shell_config.sh
5+
. "$CURDIR"/../shell_config.sh
6+
7+
SYNC_USER="${CLICKHOUSE_DATABASE}_sync_user"
8+
ASYNC_USER="${CLICKHOUSE_DATABASE}_async_user"
9+
10+
${CLICKHOUSE_CLIENT} --multiquery <<EOF
11+
DROP TABLE IF EXISTS source_table, target_table, target_table_remote_sync, target_table_remote_async, async_insert_mv, sync_insert_mv;
12+
DROP USER IF EXISTS ${SYNC_USER}, ${ASYNC_USER};
13+
14+
CREATE USER ${SYNC_USER} HOST ANY IDENTIFIED WITH NO_PASSWORD SETTINGS async_insert = 0;
15+
CREATE USER ${ASYNC_USER} HOST ANY IDENTIFIED WITH NO_PASSWORD SETTINGS async_insert = 1;
16+
GRANT ALL ON target_table TO ${SYNC_USER};
17+
GRANT ALL ON target_table TO ${ASYNC_USER};
18+
19+
CREATE TABLE source_table (
20+
id UInt64,
21+
data String
22+
)
23+
ENGINE=MergeTree()
24+
ORDER BY id;
25+
26+
CREATE TABLE target_table (
27+
id UInt64,
28+
data String
29+
)
30+
ENGINE=MergeTree()
31+
ORDER BY id;
32+
33+
CREATE TABLE target_table_remote_sync (
34+
id UInt64,
35+
data String
36+
)
37+
AS remote('127.0.0.2', currentDatabase(), 'target_table', '${SYNC_USER}');
38+
39+
CREATE TABLE target_table_remote_async (
40+
id UInt64,
41+
data String
42+
)
43+
AS remote('127.0.0.2', currentDatabase(), 'target_table', '${ASYNC_USER}');
44+
45+
CREATE MATERIALIZED VIEW async_insert_mv TO target_table_remote_async AS
46+
SELECT * FROM source_table;
47+
48+
CREATE MATERIALIZED VIEW sync_insert_mv TO target_table_remote_sync AS
49+
SELECT * FROM source_table;
50+
51+
-- Default setting, unset async_insert, so its default is 0
52+
SET async_insert = DEFAULT;
53+
-- One type of inserts each
54+
INSERT INTO source_table (id, data) VALUES (1, 'test1'), (2, 'test2'), (3, 'test3');
55+
SET async_insert = 1;
56+
-- One type of inserts each
57+
INSERT INTO source_table (id, data) VALUES (4, 'test4'), (5, 'test5'), (6, 'test6');
58+
SET async_insert = 0;
59+
-- This time both inserts have async_insert = 0, so 2 async and 4 sync inserts in total
60+
INSERT INTO source_table (id, data) VALUES (7, 'test7'), (8, 'test8'), (9, 'test9');
61+
62+
SYSTEM FLUSH LOGS query_log;
63+
SELECT count() FROM system.query_log
64+
WHERE query_kind = 'Insert' AND type = 'QueryFinish'
65+
AND user IN ('${SYNC_USER}', '${ASYNC_USER}')
66+
-- AND current_database = currentDatabase() -- to silent strange style check warning
67+
AND tables = [currentDatabase() || '.target_table']
68+
GROUP BY Settings['async_insert']
69+
ORDER BY count() ASC;
70+
71+
SELECT * FROM target_table ORDER BY id;
72+
EOF

0 commit comments

Comments
 (0)