facebook/presto — pull request #1516 by dain (2014-07-28 05:24:08+00:00)
Title: Rewrite count(constant) to count(*)

This adds an optimizer to replace `count(constant)` with `count(*)` since it is much cheaper to compute. This results in the removal of the projection of the expression, but does not end up removing an empty projection. This is because the `PruneRedundantProjections` will not remove a projection that "constrains the output tuple from the underlying operator", so we end up with the following plan:

```
SELECT COUNT(42) FROM ORDERS

- Output[_col0]
_col0 := count
- Aggregate => [count:bigint]
count := "count"(*)
- Project => []
- TableScan[local:tpch:orders:sf0.01, original constraint=true] => [orderkey:bigint]
orderkey := local:tpch:orderkey:0
```

I'm not sure why we ever end up with the `orderkey` symbol in the first place, since we can support empty source operators. Once that is fixed the empty projection should be eliminated.