optimize sql query, no host filter