MySQL Forums
Forum List  »  Performance

Multi-column index issue?
Posted by: Marc Gregoire
Date: April 27, 2005 06:21AM

Hi,

I'm having a problem with a multi-column index.
My table has the following layout:
mysql> desc test;
+-----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+-------+
| SGSN_IP_1 | int(10) unsigned | | PRI | 0 | |
| SGSN_IP_2 | int(10) unsigned | | PRI | 0 | |
| result | varchar(255) | | | | |
+-----------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)


mysql> show index from test;
+------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| test | 0 | key_index | 1 | SGSN_IP_1 | A | NULL | NULL | NULL | | BTREE | |
| test | 0 | key_index | 2 | SGSN_IP_2 | A | 10000 | NULL | NULL | | BTREE | |
+------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (0.00 sec)

A few values in the table:
+-----------+-----------+--------+
| SGSN_IP_1 | SGSN_IP_2 | result |
+-----------+-----------+--------+
| 16777472 | 16777477 | 1 |
| 16777472 | 16777733 | 2 |
| 16777984 | 16777989 | 3 |
| 16778240 | 16778245 | 4 |
| 16778496 | 16778501 | 5 |
| 16778752 | 16778757 | 6 |
| 16779008 | 16779013 | 7 |
| 16779264 | 16779269 | 8 |
| 16779520 | 16779525 | 9 |
| 16779776 | 16779781 | 10 |
| 16780032 | 16780037 | 11 |
| 16780288 | 16780293 | 12 |
....
10000 rows in set

Now, the following query isn't using the index:
mysql> explain SELECT result FROM test WHERE SGSN_IP_1<="1644167936" AND SGSN_IP_2>="1644167936";
+------+------+---------------+------+---------+------+-------+-------------+
| table| type | possible_keys | key | key_len | ref | rows | Extra |
+------+------+---------------+------+---------+------+-------+-------------+
| test | ALL | key_index | NULL | NULL | NULL | 10000 | Using where |
+------+------+---------------+------+---------+------+-------+-------------+
1 row in set (0.00 sec)

Why isn't it using the index? How can I optimize this query? What is the fastest way to do such a range query?

Kind Regards,
Marc Gregoire

Options: ReplyQuote


Subject
Views
Written By
Posted
Multi-column index issue?
3144
April 27, 2005 06:21AM
1988
April 27, 2005 06:39AM
2192
April 27, 2005 06:47AM
1941
April 27, 2005 07:19AM
2114
April 27, 2005 07:34AM
3349
April 27, 2005 11:47AM


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.