query rewrite for join transformation