Initial query rewrite support.

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

I can think of certain cases where it could be really useful, like a rollup for "the first x pages of a given groupby" where the whole thing is too big to make sense as a rollup, then essentially the entire rest of the query would have to match, and the limit and offset would have to be within the constraints of the rollup.  That would be a totally different high level matching patch though.  But yeah, not something I'm thinking about now.