Server: optimize query