add detection of query rewrite