diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 49a17e8910d..3a31a4b21c8 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -137,14 +137,14 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src) auto & dst_column_host_name = typeid_cast(*mutable_columns[name_pos["host_name"]]); auto & dst_array_current_time = typeid_cast(*mutable_columns[name_pos["current_time"]]).getData(); - auto & dst_array_thread_id = typeid_cast(*mutable_columns[name_pos["thread_id"]]).getData(); + // auto & dst_array_thread_id = typeid_cast(*mutable_columns[name_pos["thread_id"]]).getData(); auto & dst_array_type = typeid_cast(*mutable_columns[name_pos["type"]]).getData(); auto & dst_column_name = typeid_cast(*mutable_columns[name_pos["name"]]); auto & dst_array_value = typeid_cast(*mutable_columns[name_pos["value"]]).getData(); const auto & src_column_host_name = typeid_cast(*src.getByName("host_name").column); const auto & src_array_current_time = typeid_cast(*src.getByName("current_time").column).getData(); - // const auto & src_array_thread_id = typeid_cast(*src.getByName("thread_id").column).getData(); + const auto & src_array_thread_id = typeid_cast(*src.getByName("thread_id").column).getData(); const auto & src_column_name = typeid_cast(*src.getByName("name").column); const auto & src_array_value = typeid_cast(*src.getByName("value").column).getData(); @@ -169,6 +169,16 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src) rows_by_name[id] = src_row; } + /// Filter out snapshots + std::set thread_id_filter_mask; + for (size_t i = 0; i < src_array_thread_id.size(); ++i) + { + if (src_array_thread_id[i] != 0) + { + thread_id_filter_mask.emplace(i); + } + } + /// Merge src into dst. for (size_t dst_row = 0; dst_row < dst_rows; ++dst_row) { @@ -180,6 +190,11 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src) if (auto it = rows_by_name.find(id); it != rows_by_name.end()) { size_t src_row = it->second; + if (thread_id_filter_mask.contains(src_row)) + { + continue; + } + dst_array_current_time[dst_row] = src_array_current_time[src_row]; switch (dst_array_type[dst_row]) @@ -199,24 +214,18 @@ static void incrementProfileEventsBlock(Block & dst, const Block & src) /// Copy rows from src that dst does not contains. for (const auto & [id, pos] : rows_by_name) { + if (thread_id_filter_mask.contains(pos)) + { + continue; + } + for (size_t col = 0; col < src.columns(); ++col) { mutable_columns[col]->insert((*src.getByPosition(col).column)[pos]); } } - /// Filter out snapshots - std::set thread_id_filter_mask; - for (size_t i = 0; i < dst_array_thread_id.size(); ++i) - { - if (dst_array_thread_id[i] != 0) - { - thread_id_filter_mask.emplace(i); - } - } - dst.setColumns(std::move(mutable_columns)); - dst.erase(thread_id_filter_mask); } diff --git a/tests/queries/0_stateless/02050_client_profile_events.reference b/tests/queries/0_stateless/02050_client_profile_events.reference index ac7978506a2..c8e031d3562 100644 --- a/tests/queries/0_stateless/02050_client_profile_events.reference +++ b/tests/queries/0_stateless/02050_client_profile_events.reference @@ -2,6 +2,8 @@ do not print any ProfileEvents packets 0 print only last (and also number of rows to provide more info in case of failures) [ 0 ] SelectedRows: 131010 (increment) +regression test for incorrect filtering out snapshots +0 print everything OK print each 100 ms diff --git a/tests/queries/0_stateless/02050_client_profile_events.sh b/tests/queries/0_stateless/02050_client_profile_events.sh index 5a9a7c42180..5470c44594c 100755 --- a/tests/queries/0_stateless/02050_client_profile_events.sh +++ b/tests/queries/0_stateless/02050_client_profile_events.sh @@ -10,6 +10,10 @@ $CLICKHOUSE_CLIENT -q 'select * from numbers(1e5) format Null' |& grep -c 'Selec echo 'print only last (and also number of rows to provide more info in case of failures)' $CLICKHOUSE_CLIENT --max_block_size=65505 --print-profile-events --profile-events-delay-ms=-1 -q 'select * from numbers(1e5)' |& grep -o -e '\[ 0 \] SelectedRows: .*$' -e Exception +echo 'regression test for incorrect filtering out snapshots' +$CLICKHOUSE_CLIENT --print-profile-events --profile-events-delay-ms=-1 -n -q 'select 1; select 1' >& /dev/null +echo $? + echo 'print everything' profile_events="$($CLICKHOUSE_CLIENT --max_block_size 1 --print-profile-events -q 'select sleep(1) from numbers(2) format Null' |& grep -c 'SelectedRows')" test "$profile_events" -gt 1 && echo OK || echo "FAIL ($profile_events)"