ziploc1010
Programmer
Hi,
I have created a composite index with the following query:
CREATE INDEX `idx_Object-id_all`
ON `Object-id` (id, str);
When I try to select from the `Object-id` table, it does not allow me to use the index and applys a filesort.
explain select id, str from `entrez_gene`.`Object-id` order by id,str;
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
| 1 | SIMPLE | Object-id | ALL | NULL | NULL | NULL | NULL | 72650543 | Using filesort |
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
1 row in set (0.00 sec)
If I change the query to only select with one column, it will use the composite index:
explain select id, str from `entrez_gene`.`Object-id` order by id;
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
| 1 | SIMPLE | Object-id | index | NULL | idx_Object-id_all | 775 | NULL | 72650543 | |
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
1 row in set (0.00 sec)
I have been unsuccessful using index hints, such as "use index" and "force index"
Here is the create table and index statement for `Object-id`:
describe `Object-id`
-> ;
+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| Object-id_id | int(11) | NO | PRI | 0 | |
| id | int(11) | YES | MUL | NULL | |
| str | varchar(1000) | YES | | NULL | |
+--------------+---------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
show index from `Object-id`;
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
| Object-id | 0 | PRIMARY | 1 | Object-id_id | A | 73716061 | NULL | NULL | | BTREE | |
| Object-id | 1 | idx_Object-id_all | 1 | id | A | 73716061 | NULL | NULL | YES | BTREE | |
| Object-id | 1 | idx_Object-id_all | 2 | str | A | 73716061 | 767 | NULL | YES | BTREE | |
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.27 sec)
Here is the mysql version:
show variables like "%version%";
+-------------------------+------------------------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------------------------+
| protocol_version | 10 |
| version | 5.0.77 |
| version_bdb | Sleepycat Software: Berkeley DB 4.1.24: (January 29, 2009) |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | redhat-linux-gnu |
+-------------------------+------------------------------------------------------------+
6 rows in set (0.00 sec)
I have created a composite index with the following query:
CREATE INDEX `idx_Object-id_all`
ON `Object-id` (id, str);
When I try to select from the `Object-id` table, it does not allow me to use the index and applys a filesort.
explain select id, str from `entrez_gene`.`Object-id` order by id,str;
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
| 1 | SIMPLE | Object-id | ALL | NULL | NULL | NULL | NULL | 72650543 | Using filesort |
+----+-------------+-----------+------+---------------+------+---------+------+----------+----------------+
1 row in set (0.00 sec)
If I change the query to only select with one column, it will use the composite index:
explain select id, str from `entrez_gene`.`Object-id` order by id;
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
| 1 | SIMPLE | Object-id | index | NULL | idx_Object-id_all | 775 | NULL | 72650543 | |
+----+-------------+-----------+-------+---------------+-------------------+---------+------+----------+-------+
1 row in set (0.00 sec)
I have been unsuccessful using index hints, such as "use index" and "force index"
Here is the create table and index statement for `Object-id`:
describe `Object-id`
-> ;
+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| Object-id_id | int(11) | NO | PRI | 0 | |
| id | int(11) | YES | MUL | NULL | |
| str | varchar(1000) | YES | | NULL | |
+--------------+---------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
show index from `Object-id`;
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
| Object-id | 0 | PRIMARY | 1 | Object-id_id | A | 73716061 | NULL | NULL | | BTREE | |
| Object-id | 1 | idx_Object-id_all | 1 | id | A | 73716061 | NULL | NULL | YES | BTREE | |
| Object-id | 1 | idx_Object-id_all | 2 | str | A | 73716061 | 767 | NULL | YES | BTREE | |
+-----------+------------+-------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.27 sec)
Here is the mysql version:
show variables like "%version%";
+-------------------------+------------------------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------------------------+
| protocol_version | 10 |
| version | 5.0.77 |
| version_bdb | Sleepycat Software: Berkeley DB 4.1.24: (January 29, 2009) |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | redhat-linux-gnu |
+-------------------------+------------------------------------------------------------+
6 rows in set (0.00 sec)