+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | zipcodes | 0 | PRIMARY | 1 | id | A | 29356 | NULL | NULL | | BTREE | | | zipcodes | 1 | foo | 1 | town | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | foo | 2 | state | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | foo | 3 | latitude | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | foo | 4 | longitude | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | foo | 5 | population | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | bar | 1 | state | A | NULL | NULL | NULL | | BTREE | | | zipcodes | 1 | bar | 2 | town | A | NULL | NULL | NULL | | BTREE | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 8 rows in set (0.04 sec) mysql> explain SELECT DISTINCT town, state, SUM(population) -> AS pop, ACOS((SIN(RADIANS(AVG(latitude))) * SIN(RADIANS(42.878462333333))) -> + (COS(RADIANS(AVG(latitude))) * COS(RADIANS(42.878462333333)) * -> COS(RADIANS(AVG(longitude) - (-85.621038))))) * 3963.190275 AS dist FROM -> zipcodes GROUP BY town, state ORDER BY dist LIMIT 10; +----------+-------+---------------+------+---------+------+-------+---------------------------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +----------+-------+---------------+------+---------+------+-------+---------------------------------+ | zipcodes | index | NULL | foo | 79 | NULL | 29356 | Using temporary; Using filesort | +----------+-------+---------------+------+---------+------+-------+---------------------------------+ 1 row in set (0.01 sec)