Reduce memory usage by using fetch instead of fetchAll in query.