Initial query rewrite support.

Currently supports matching columns, literals and count(*) in the selection
and columns in grouping.


It seems odd to have two separate top-level cases for "there was a match".  It seems like you want _one_ top level "the match was found" case and a subsidiary "it matched `no groupings" vs "it matched this set of groupings", since the main question to be answered is "it is an aggregate query" vs "it is not an aggregate query".