MySQL Forums
Forum List  »  Performance

Re: Use of index for SELECT DISTINCT
Posted by: Ulf Wendel
Date: June 16, 2005 03:14PM

Dominique PRUNIER wrote:
> a: integer
> b: varchar(128)
>
> Let's say that b has only a few distinct values
> but the table has MANY rows (2 000 000). The
> column b is indexed, with of course a VERY low
> cardinality.
>
> Why optmimizer will always scan the 2 000 000
> (using index on b though) to execute query SELECT
> DISTINCT b FROM table while it knows there are
> only a few distincts values from the index ?

Dominique,

are you saying that MySQL is using an index scan? What's wrong with this strategy. MySQL should have the number of distinct values in it's statistics but it does not know the distinct values. Thus, scanning the smallest datastructure that's available to find out the distinct values (the index instead of the table) makes perfectly sense to me.

Ulf

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Use of index for SELECT DISTINCT
1772
June 16, 2005 03:14PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.