Separate queries for better mysql performance (bug 861224)