Adds plan rewriting to remove empty Apply

Because of the way Ronja produces plans, Apply is used in
a number of places that are not strictly needed, and where a
simpler plan does the same job. This rewriter finds such plans
and removes Apply from them.
Merge pull request #3159 from systay/remove-empty-apply

[2.2] Adds plan rewriting to remove empty Apply