query rewriting methods