I'm trying to get distinct id's out of a 6 million row table. The query is pretty simple, and the explain seems ok. The distict row is indexed as part of a grouped index of uid-date-time.
The query is
SELECT DISTINCT uid FROM events;and returns 334117 rows in 17 min 15.54 seconds. The explain is
+----+-------------+-------------+-------+---------------+----------------+---- ----+------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | keylen | ref | rows | Extra | +----+-------------+-------------+-------+---------------+----------------+--------+------+------+--------------------------+ | 1 | SIMPLE | events | range | NULL | dateuid_idx | 4 | NULL | 10 | Using index for group-by | +----+-------------+-------------+-------+---------------+----------------+---- ----+------+------+--------------------------+
would this be faster if the uid where held in a seperate index? or is there another way to speed this up?