Count sql optimization (already done for ios