Home » Performance » MySQL » Mysql not using index for ORDER BY ?
Mysql not using index for ORDER BY ? [message #1240] Sat, 12 May 2007 05:47 Go to previous message
arnoooooo  is currently offline arnoooooo
Messages: 3
Registered: May 2007
Junior Member
Hi all,

I am having trouble with a query on a large (39m rows) table : MySQL won't use the index, for the ORDER BY clause, and creates a temporary table, which takes a lot of disk space and time.

EXPLAIN SELECT * FROM histos_backtest ORDER BY id;

+----+-------------+-----------------+------+---------------+------+---------+------+----------+----------------+
| id | select_type | table           | type | possible_keys | key  | key_len | ref  | rows     | Extra          |
+----+-------------+-----------------+------+---------------+------+---------+------+----------+----------------+
|  1 | SIMPLE      | histos_backtest | ALL  | NULL          | NULL | NULL    | NULL | 39252003 | Using filesort |
+----+-------------+-----------------+------+---------------+------+---------+------+----------+----------------+


SHOW INDEX FROM histos_backtest;
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table           | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| histos_backtest |          0 | PRIMARY  |            1 | id          | A         |    39252003 |     NULL | NULL   |      | BTREE      | NULL    |
| histos_backtest |          1 | id       |            1 | id          | A         |    39252003 |     NULL | NULL   |      | BTREE      | NULL    |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+


I created an index on the same column as the primary key just to make sure... I use Sybase at work and sometimes, the primary key is not enough. Apparently it is not the case with MySQL.

Any help would be greatly appreciated Smile

Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:Bad Performance or Bad Query ?
Next Topic:MySQL Extremely Slow Starting Up
Goto Forum:

  


Current Time: Thu Jul 9 21:17:31 EDT 2009

Total time taken to generate the page: 0.02333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.