Some queries weren't using the full power of SQL and doing some of the selection in the code, fix that (by_hash and host mapping).