Queries optimization