List:General Discussion« Previous MessageNext Message »
From:Renars Jeromans Date:February 18 2003 10:22am
Subject:Slow retrieval of distinct on indexed fields
View as plain text  
Hello,

This is not an urgent problem, but it has always intrigued me...
It's simplified case, but it makes the point. Let us assume that we have a 
table

create table T (id unsigned int unique, name char(10));
create index i_name on T(name);

Let's insert into it say 5 mil rows with name field being just say 5 
distinct values AAA, BBB, CCC, DDD, EEE.

Now the question. Why a query like

select distinct name from T;

takes about 3 sec to return just a bunch of rows?
As I understand it, index contains all these 5 values, so just simple 
lookup into index should take fractions of a second.
Can anyone comment on this? MySQL team?

Thanks,
Ren

Thread
Slow retrieval of distinct on indexed fieldsRenars Jeromans18 Feb
  • Re: Slow retrieval of distinct on indexed fieldsDan Nelson18 Feb
    • Re: Slow retrieval of distinct on indexed fields [OT?]Michael T. Babcock18 Feb
  • Re: Slow retrieval of distinct on indexed fieldsPeter Grigor18 Feb
    • Re: Slow retrieval of distinct on indexed fieldsDan Nelson18 Feb
  • Re: Slow retrieval of distinct on indexed fieldsPeter Grigor18 Feb