MySQL Forums
Forum List  »  General

Optimisation problem: sometimes uses index, sometimes doesnt??
Posted by: Ben XO
Date: January 30, 2005 05:33PM

Hi, i have an weird optimisation problem illustrated by the following:

mysql> explain select * from doa_show_instance where start > '2005-09-07' \G
*************************** 1. row ***************************
table: doa_show_instance
type: ALL
possible_keys: start
key: NULL
key_len: NULL
ref: NULL
rows: 13295
Extra: Using where
1 row in set (0.00 sec)

mysql> explain select * from doa_show_instance where start > '2005-09-08' \G
*************************** 1. row ***************************
table: doa_show_instance
type: range
possible_keys: start
key: start
key_len: 8
ref: NULL
rows: 2310
Extra: Using where
1 row in set (0.00 sec)


(one uses index, one doesnt).

The table looks like this:

+-------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------------------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| show_id | int(11) | | MUL | 0 | |
| start | datetime | | MUL | 0000-00-00 00:00:00 | |
| length | time | | | 00:00:00 | |
| regular | tinyint(1) | | | 1 | |
| description | text | | | | |
| guests | varchar(250) | YES | | NULL | |
| highlight | int(1) | YES | | NULL | |
+-------------+--------------+------+-----+---------------------+----------------+

mysql> show index from doa_show_instance
-> ;
+-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| doa_show_instance | 0 | PRIMARY | 1 | id | A | 13295 | NULL | NULL | | BTREE | |
| doa_show_instance | 1 | start | 1 | start | A | 6647 | NULL | NULL | | BTREE | |
| doa_show_instance | 1 | show_id | 1 | show_id | A | 172 | NULL | NULL | | BTREE | |
+-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

any idea what gives?

thanks in advance.

Options: ReplyQuote


Subject
Written By
Posted
Optimisation problem: sometimes uses index, sometimes doesnt??
January 30, 2005 05:33PM


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.