Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
Mysql - how to design indexes for a query with WHERE and GROUP BY

I work with MySQL (MyISAM) DB.

I have a query like this:

select c1, c2, c3, MAX(c5) from T where c4=#string_value# group by c1, c2, c3

- c[1-4] are varchar(255)
- c5 is an integer

I've tried two indexes:

  • "c1_c2_c3_idx" for (c1, c2, c3) - that makes query work 3 times slower
  • "c4_idx" for (c4) - that makes query work 5 times faster

Maybe there is a way to create even more fast index?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I see the following index being optimal:

CREATE INDEX idx ON T (c4, c1, c2, c3, c5);

The index begins with c4, which appears in the WHERE clause, which is the first part of the query execution. Next, we add c1, c2, and c3, to cover the GROUP BY clause. After this, we add c5, which will make it much faster for MySQL to find MAX(c5).

Note that the above index can be said to cover the entire query, because MySQL can use the index alone to satisfy the entire query plan, without needing to seek back to the clustered index (table).

over 4 years ago · Santiago Trujillo Denunciar

0

The best index should bd based on where condition ...

 create index  idx1 on T ( c4) 

for avoid the access to data table and use only info contained in index you can also try using a redundant index adding the column involved in others clauses

create index  idx1 on T ( c4, c1,c2,c3,c5) 

leaving the where column left most

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda