With a large volume of queries per second logging all queries gets expensive, it would be nice to be able to log only a configurable fraction of the queries, selected at random.
auto finish_callback = [elem, context, ast,
                 log_queries,
                 log_queries_min_type = settings.log_queries_min_type,
                 log_queries_min_query_duration_ms = settings.log_queries_min_query_duration_ms.totalMilliseconds(),
                 status_info_to_query_log
            ]
                (IBlockInputStream * stream_in, IBlockOutputStream * stream_out, QueryPipeline * query_pipeline) mutable
            {
                QueryStatus * process_list_elem = context->getProcessListElement();
                if (!process_list_elem)
                    return;
                
                CurrentThread::finalizePerformanceCounters();
                QueryStatusInfo info = process_list_elem->getInfo(true, context->getSettingsRef().log_profile_events);
                double elapsed_seconds = info.elapsed_seconds;
                elem.type = QueryLogElementType::QUERY_FINISH;
                
                
                const auto finish_time = std::chrono::system_clock::now();
                elem.event_time = time_in_seconds(finish_time);
                elem.event_time_microseconds = time_in_microseconds(finish_time);
                status_info_to_query_log(elem, info, ast, context);
                auto progress_callback = context->getProgressCallback();
                if (progress_callback)
                    progress_callback(Progress(WriteProgress(info.written_rows, info.written_bytes)));
                if (stream_in)
                {
                    const BlockStreamProfileInfo & stream_in_info = stream_in->getProfileInfo();
                    
                    elem.result_rows = stream_in_info.rows;