Crie um índice composto em
(state, city)
e reescreva sua consulta assim:SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
GROUP BY
state, city
Observe que para esta consulta você pode omitir
GROUP BY
cláusula:SELECT 'New York, NY' AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
No entanto, esta consulta ainda precisará dela:
SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
GROUP BY
state, city