```sql
SELECT count()
FROM 
(
    SELECT number
    FROM numbers_mt(100000000)
    ORDER BY number DESC
    LIMIT 100
    UNION ALL
    SELECT number
    FROM numbers_mt(100000000)
    ORDER BY number DESC
    LIMIT 100
    UNION ALL
    SELECT number
    FROM numbers_mt(100000000)
    ORDER BY number DESC
    LIMIT 100
)


SET experimental_use_processors = 0;
-- 1 rows in set. Elapsed: 1.581 sec. Processed 300.00 million rows, 2.40 GB (189.78 million rows/s., 1.52 GB/s.) 

SET experimental_use_processors = 1;
-- 1 rows in set. Elapsed: 3.569 sec. Processed 300.00 million rows, 2.40 GB (84.06 million rows/s., 672.50 MB/s.) 
```

Similar for MergeTree:

```sql
create table test engine=MergeTree order by tuple() as select * from numbers(30000000);

select count() from (select number from test group by number order by number limit 10 union all select number from test group by number order by number limit 10);

set experimental_use_processors=0;
-- Elapsed: 2.664 sec

set experimental_use_processors=1;
-- Elapsed: 3.656 sec
```
{
    if (!initialized())
        throw Exception("QueryPipeline wasn't initialized.", ErrorCodes::LOGICAL_ERROR);
}
void QueryPipeline::checkInitializedAndNotCompleted()
{
    checkInitialized();
    if (streams.empty())
        throw Exception("QueryPipeline was already completed.", ErrorCodes::LOGICAL_ERROR);
}
void QueryPipeline::checkSource(const ProcessorPtr & source, bool can_have_totals)
{
    if (!source->getInputs().empty())
        throw Exception("Source for query pipeline shouldn't have any input, but " + source->getName() + " has " +
                        toString(source->getInputs().size()) + " inputs.", ErrorCodes::LOGICAL_ERROR);
    if (source->getOutputs().empty())
        throw Exception("Source for query pipeline should have single output, but it doesn't have any",
                ErrorCodes::LOGICAL_ERROR);
    if (!can_have_totals && source->getOutputs().size() != 1)
        throw Exception("Source for query pipeline should have single output, but " + source->getName() + " has " +
                        toString(source->getOutputs().size()) + " outputs.", ErrorCodes::LOGICAL_ERROR);
    if (source->getOutputs().size() > 2)
        throw Exception("Source for query pipeline should have 1 or 2 outputs, but " + source->getName() + " has " +
                        toString(source->getOutputs().size()) + " outputs.", ErrorCodes::LOGICAL_ERROR);
}
void QueryPipeline::init(Pipe pipe)