Database query optimization

shape