Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Why Mysql explain use index for following SQL statement instead of range

I have a table:

create table user (

id int primary key,

name varchar(20)

)engine=innodb;

insert into user values(1,'lily');

insert into user values(2,'tom');

insert into user values(3,'bob');

insert into user values(4,'jimi');

insert into user values(5,'moth');

If I run

explain select * from user where id in (1,2,3)

or

explain select name from user where id in (1,2,3)

Mysql shows that the type is range, but when run:

 explain select id from user where id in (1,2,3)

Mysql shows that the type is index. So why is there such a difference?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The critical thing to realize here is that for such a small table MySQL may not choose to use any index, despite there being an index which might help the query plan execute faster. Actually, both of the queries you showed should be sargable, and MySQL should be able to use the clustered index on the id primary key. Try adding substantially more data, and MySQL would likely use an index scan to satisfy the query.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda