On Thu, Aug 23, 2001 at 07:54:38PM +0200, Osus wrote:
[snip]
> when I run this query
> mysql> explain select Nick from mytable where Inicial='P' AND Sexo=1 and
> ok=1;
> .
> +----------+------+-----------------------------------+-------------+-------
> --+-------+------+------------+
> | table | type | possible_keys | key |
> key_len | ref | rows | Extra |
> +----------+------+-----------------------------------+-------------+-------
> --+-------+------+------------+
> | mytable | ref | ok,inicial,sexo | ok | 1 | const | 10 | where
> used |
> +----------+------+-----------------------------------+-------------+-------
> --+-------+------+------------+
>
> only one index is used, why?
>
> ok is 1 or 0
> sexo is 1 or 0
>
> but inicial is A, B, C, D, E, F, G.....Z
> So it would be better to use Inicial as index bacause should get
> less records...
Actually, you sort of answered yourself.
Since inicial can have many possible values, odds are that you'll get
*fewer* rows by using it to limit the query results. Imagine a table
with 1 million records and the keys are equally distributed. Using
either "ok" or "sexo" columns will only eliminate about 50% of the
rows. The "inicial" column will eliminate many more.
Jeremy
--
Jeremy D. Zawodny, <[EMAIL PROTECTED]>
Technical Yahoo - Yahoo Finance
Desk: (408) 349-7878 Fax: (408) 349-5454 Cell: (408) 685-5936
MySQL 3.23.41-max: up 6 days, processed 89,557,252 queries (148/sec. avg)
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php