Query rewrite explained