MySQL Forums
Forum List  »  Newbie

Using an index vs. full table scan, character vs. integers.
Posted by: kevin
Date: August 19, 2004 08:52PM

I've got what are surprising (to me!) results from a very simple query. I'm hoping that some of the experts around here could confirm that my understanding of things is correct.

Given the table:
mysql> desc my_table;
+-----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| year | char(4) | | PRI | | |
| id | char(5) | | PRI | | |
+-----------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

which has a unique index on both fields:

create unique index my_index_1 on my_table (year, id);

and about 38,000 rows in it.

and given these two queries against the table:

mysql> explain select * from my_table where year = 2003 and id = 38590 \G
*************************** 1. row ***************************
table: my_table
type: index
possible_keys: my_index_1
key: my_index_1
key_len: 9
ref: NULL
rows: 38487
Extra: Using where; Using index
1 row in set (0.00 sec)

mysql> explain select * from my_table where year = '2003' and id = '38590' \G
*************************** 1. row ***************************
table: my_table
type: const
possible_keys: my_index_1
key: my_index_1
key_len: 9
ref: const,const
rows: 1
Extra:
1 row in set (0.00 sec)

Both queries have a "key: my_index_1" which makes me think that my index is being used, but the "rows: 38487" for the first query makes me wonder if the first query is acutally doing a full table scan, because of some sort of integer to character conversion. could someone explain?

Thanks!
Kevin

Options: ReplyQuote


Subject
Written By
Posted
Using an index vs. full table scan, character vs. integers.
August 19, 2004 08:52PM


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.