```
CREATE TABLE t (x UInt8, PROJECTION p (SELECT x GROUP BY x)) ENGINE = MergeTree ORDER BY ();
INSERT INTO t VALUES (0);

SET group_by_overflow_mode = 'any', max_rows_to_group_by = 1000, totals_mode = 'after_having_auto';
SELECT x FROM t GROUP BY x WITH TOTALS;
```
const DataPartStates & affordable_states, const DataPartsLock & , DataPartStateVector * out_states) const
{
    DataPartsVector res;
    DataPartsVector buf;
    for (auto state : affordable_states)
    {
        auto range = getDataPartsStateRange(state);
        std::swap(buf, res);
        res.clear();
        std::merge(range.begin(), range.end(), buf.begin(), buf.end(), std::back_inserter(res), LessDataPart()); 
    }
    if (out_states != nullptr)
    {
        out_states->resize(res.size());
        for (size_t i = 0; i < res.size(); ++i)
            (*out_states)[i] = res[i]->getState();
    }
    return res;
}
MergeTreeData::DataPartsVector