I have a table with ~300,000 rows in it.
I want to do this:
SELECT COUNT(DISTINCT target) FROM stats_log;
It returns the correct number (1364), but takes 3.27 seconds to run.
In the mysql client, if I do this:
SELECT DISTINCT target FROM stats_log;
it returns the whole result set, and then says: "1364 rows in set (0.63 sec)"
I want to avoid sending the 1364 rows to my PHP script, and have PHP run a num_rows on the query, but I don't seem to have another option. (3.x seconds is WAY too long for a select query).
Is there a better way to do COUNT(DISTINCT column) ? MySQL's default algorithm seems to suck.