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.
}
        {
            
            NormalizeSelectWithUnionQueryVisitor::Data data{context->getSettingsRef().union_default_mode};
            NormalizeSelectWithUnionQueryVisitor{data}.visit(ast);
        }
        
        checkASTSizeLimits(*ast, settings);
        
        ProcessList::EntryPtr process_list_entry;
        if (!internal && !ast->as<ASTShowProcesslistQuery>())
        {
            
            process_list_entry = context->getProcessList().insert(query_for_logging, ast.get(), context);
            context->setProcessListElement(&process_list_entry->get());
        }
        
        context->initializeExternalTablesIfSet();
        auto * insert_query = ast->as<ASTInsertQuery>();
        if (insert_query && insert_query->select)
        {
            
            if (istr)
            {
                ASTPtr input_function;
                insert_query->tryFindInputFunction(input_function);
                if (input_function)
                {
                    StoragePtr storage = context->executeTableFunction(input_function);
                    auto & input_storage = dynamic_cast<StorageInput &>(*storage);