Database query improvements.