20.10.1.4853

```sql
drop table if exists xp;
drop table if exists xp_d;

create table xp(A Date, B Int64, S String) Engine=MergeTree partition by toYYYYMM(A) order by B;
insert into xp select '2020-01-01', number , '' from numbers(100000);
insert into xp select '2020-10-01', number , '' from numbers(100000);
create table xp_d as xp Engine=Distributed(test_shard_localhost, currentDatabase(), xp);

select count() from xp_d prewhere toYYYYMM(A) global in (select toYYYYMM(min(A)) from xp_d) where B > -1;
┌─count()─┐
│       0 │     <------ expected 100000
└─────────┘

-- global in & both predicates in prewhere 
select count() from xp_d prewhere toYYYYMM(A) global in (select toYYYYMM(min(A)) from xp_d) and B > -1;
┌─count()─┐
│  100000 │
└─────────┘

-- global in & both predicates in where 
select count() from xp_d where toYYYYMM(A) global in (select toYYYYMM(min(A)) from xp_d) and B > -1;
┌─count()─┐
│  100000 │
└─────────┘

-- not global
select count() from xp_d prewhere toYYYYMM(A) in (select toYYYYMM(min(A)) from xp_d) where B > -1;
┌─count()─┐
│  100000 │
└─────────┘



select count() from xp_d prewhere toYYYYMM(A) global in (select 202001) where B > -1;
┌─count()─┐
│       0 │
└─────────┘
```

hmm, it worked in 19.13.7.57
{
    
    if (!query.distinct && !query.limitBy() && !query.limit_with_ties && !query.arrayJoinExpressionList() && query.limitLength())
    {
        auto [limit_length, limit_offset] = getLimitLengthAndOffset(query, context);
        if (limit_length > std::numeric_limits<UInt64>::max() - limit_offset)
            return 0;
        return limit_length + limit_offset;
    }
    return 0;
}
static bool hasWithTotalsInAnySubqueryInFromClause(const ASTSelectQuery & query)
{
    if (query.group_by_with_totals)
        return true;
    /** NOTE You can also check that the table in the subquery is distributed, and that it only looks at one shard.
      * In other cases, totals will be computed on the initiating server of the query, and it is not necessary to read the data to the end.
      */
    if (auto query_table = extractTableExpression(query, 0))
    {
        if (const auto * ast_union = query_table->as<ASTSelectWithUnionQuery>())
        {
            for (const auto & elem : ast_union->list_of_selects->children)
                if (hasWithTotalsInAnySubqueryInFromClause(elem->as<ASTSelectQuery &>()))
                    return true;
        }
    }
    return false;
}
void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInputStreamPtr & prepared_input, std::optional<Pipe> prepared_pipe)