Initial query rewrite support.

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

Instead of returning all mismatches (rewrite failure), may be we should short circuited further attempts as song as it hits first failure.