facebook/presto — pull request #1162 by erichwang (2014-03-27 03:00:19+00:00)
Title: Rewrite identical projection expressions in terms of the same symbol

This is an existing gap in our optimizer whereby a projection may have the same deterministic expression being generated for multiple output symbols. This results in the expression being computed and stored multiple times unnecessarily.

For example, consider this query:
https://gist.github.com/erichwang/8f9dea33396c2d85869d

Previously our plan would look like this:
https://gist.github.com/erichwang/3f5c82c13a9c79f998ef

With the fix it looks like this:
https://gist.github.com/erichwang/e08606ae5fe17dc52a6c