views:

263

answers:

3

This is related to the queries I'm running from this question, namely:

SELECT  CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude) 
FROM    places
WHERE   state='NY'
        AND city='New York'
GROUP BY
        state, city

I've been looking at phpMyAdmin and they have one value red-flagged, Handler_read_rnd_next. I think it makes sense; given the above query, if a location has multiple zip codes, the AVG() functions are going to group by city/state and then scan through each zip code.

My question is, when does this become a terrible thing? Should I be caching these averages to begin with, or is an increase of a few thousand Handler_read_rnd_next every few minutes an acceptable thing for a database? It seems like this would number will increase for any query that uses GROUP BY, so I'm wondering if this is just standard fare.

A: 

High values of random statistic counters are not dangerous. If you don't have a performance issue, you don't need to worry. As far as caching:

  1. Do not perform premature optimization. Unless you know this is going to become a bottleneck (or it already is), do not optimize it. Caching data by hand is not free; it makes your app have to carefully keep the cache in sync.

  2. If places is basically read-only, which I'm guessing it probably is, MySQL's query cache will already cache this for you. Since MySQL keeps this in sync transparently, the only cost is memory (which is quite cheap). Check your query cache parameters.

derobert
A: 

I know Roger is not around anymore but for anyone concerned about this...

phpMyAdmin itself increments this value a good 300 to 1k on any Status page load.

So don't really go by phpMyAdmin results only.

Frankie
A: 

thanks frankie!

Jim