Squash each select

And optimize away the empty pipeline that was created in the case of a trivial select.