Initial query rewrite support.

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

Wouldn't it be better to return all mismatches instead of just the first one?