On Wed, Jan 23, 2002 at 02:32:49PM +0300, Artem V. Ryabov wrote: > Hello mysql, > > Why query type > > select count(*) from table_name where key_field between 'min' and > 'max' so slow? > > example: > > mysql> select count(*) from Textes where ID between 7937 and 45061; > +----------+ > | count(*) | > +----------+ > | 36360 | > +----------+ > 1 row in set (0.42 sec)
How large is your key_buffer? How many rows are in the table? > mysql> explain select count(*) from Textes where ID between 7937 and 45061; > >+--------+-------+---------------+---------+---------+------+-------+-------------------------+ > | table | type | possible_keys | key | key_len | ref | rows | Extra > | > >+--------+-------+---------------+---------+---------+------+-------+-------------------------+ > | Textes | range | PRIMARY | PRIMARY | 4 | NULL | 36361 | where used; >Using index | > >+--------+-------+---------------+---------+---------+------+-------+-------------------------+ > 1 row in set (0.00 sec) > > why explain much faster? Because it doesn't actually run the query. > why rows from expalain not exactly match count(*)? Because it's just an esitmate which helps MySQL decide the fastest way to execute the query. > Will It's be fixed in 4.0? Hard to say. We don't know what the problem is yet. Can you run "ANALYZE TABLE Textes" and see if that helps? 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 22 days, processed 513,809,364 queries (265/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