MySQL Forums
Forum List  »  General

why mysql not using index when that index is based on a varchar field?
Posted by: Zhixin Gao
Date: March 06, 2023 07:11PM

Say, I have a table that is:

create table test (
id int primary key auto_increment,
c_no varchar(11),
c2 varchar(2),

key c_no(c_no)
);
Then based on this table, I have a sql query which is:

select
*
from
test
where
c_no = 100
But when I used explain to analyze the sql, I found it didn't use the index on c_no:

explain select * from test2 where c_no=100


+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | test | NULL | ALL | c_no | NULL | NULL | NULL | 7 | 14.29 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 3 warnings (0.00 sec)
why?

Options: ReplyQuote


Subject
Written By
Posted
why mysql not using index when that index is based on a varchar field?
March 06, 2023 07:11PM


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.