diff --git a/src/DataStreams/RemoteQueryExecutor.cpp b/src/DataStreams/RemoteQueryExecutor.cpp index a64c4409cc9..3c78fddfd39 100644 --- a/src/DataStreams/RemoteQueryExecutor.cpp +++ b/src/DataStreams/RemoteQueryExecutor.cpp @@ -208,6 +208,12 @@ void RemoteQueryExecutor::sendQuery() auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover(settings); ClientInfo modified_client_info = context->getClientInfo(); modified_client_info.query_kind = ClientInfo::QueryKind::SECONDARY_QUERY; + /// Set initial_query_id to query_id for the clickhouse-benchmark. + /// + /// (since first query of clickhouse-benchmark will be issued as SECONDARY_QUERY, + /// due to it executes queries via RemoteBlockInputStream) + if (modified_client_info.initial_query_id.empty()) + modified_client_info.initial_query_id = query_id; if (CurrentThread::isInitialized()) { modified_client_info.client_trace_context = CurrentThread::get().thread_trace_context; diff --git a/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.reference b/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.reference new file mode 100644 index 00000000000..00750edc07d --- /dev/null +++ b/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.reference @@ -0,0 +1 @@ +3 diff --git a/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.sh b/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.sh new file mode 100755 index 00000000000..9cab6db6940 --- /dev/null +++ b/tests/queries/0_stateless/02040_clickhouse_benchmark_query_id_pass_through.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +query_id="${CLICKHOUSE_DATABASE}_$$" +benchmark_args=( + --iterations 1 + --log_queries 1 + --query_id "$query_id" + --log_queries_min_type QUERY_FINISH +) +$CLICKHOUSE_BENCHMARK "${benchmark_args[@]}" --query "SELECT * FROM remote('127.2', 'system.one')" >& /dev/null +$CLICKHOUSE_CLIENT -q "SYSTEM FLUSH LOGS" +# Number of queries: +# - DESC TABLE system.one +# - query on initiator +# - query on shard +# Total: 3 +# +# -- NOTE: this test cannot use 'current_database = $CLICKHOUSE_DATABASE', +# -- because it does not propagated via remote queries, +# -- but it uses query_id, and this is enough. +$CLICKHOUSE_CLIENT --param_query_id="$query_id" -q "SELECT count() FROM system.query_log WHERE event_date >= yesterday() AND initial_query_id = {query_id:String}"