Optimize cluster aggregation job query