Test Database : MySQL
create table test1(
id int not null default '0',
s_id int not null default '0',
g_id int not null default '0',
primary key(id),
key classID (s_id,g_id)
);
mysql> explain select * from test1 where s_id =1;
Don't used index
but
mysql> explain select * from test1 where s_id =1 and g_id =1;
Used index
also
create table test2(
id int not null default '0',
s_id int not null default '0',
g_id int not null default '0',
primary key (id),
key classID (s_id)
);
mysql > explain select * from test2 where s_id =1;
Used index
create table test3{
id int not null default '0',
s_id char(10) not null,
g_id char(10) not null,
primary key (id),
key classID (s_id,g_id)
);
mysql> explain select * from test3 where s_id='abc';
Used index
I don't understand. Why don't use index of test1 ?
Please help me!!! Anyone explain the appearance.