**Describe the bug**
`SELECT i FROM generateRandom('i Array(Int8)', 1048575, 10, 1048577) LIMIT 1048575`

Memory limit should be respected.
if (settings.calculate_text_stack_trace)
        setExceptionStackTrace(elem);
    logException(context, elem);
    
    CurrentThread::finalizePerformanceCounters();
    if (settings.log_queries && elem.type >= settings.log_queries_min_type)
        if (auto query_log = context.getQueryLog())
            query_log->add(elem);
    ProfileEvents::increment(ProfileEvents::FailedQuery);
    if (ast)
    {
        if (ast->as<ASTSelectQuery>() || ast->as<ASTSelectWithUnionQuery>())
        {
            ProfileEvents::increment(ProfileEvents::FailedSelectQuery);
        }
        else if (ast->as<ASTInsertQuery>())
        {
            ProfileEvents::increment(ProfileEvents::FailedInsertQuery);
        }
    }
}
static void setQuerySpecificSettings(ASTPtr & ast, Context & context)
{
    if (auto * ast_insert_into = dynamic_cast<ASTInsertQuery *>(ast.get()))
    {
        if (ast_insert_into->watch)
            context.setSetting("output_format_enable_streaming", 1);
    }
}
static std::tuple<ASTPtr, BlockIO> executeQueryImpl(