I have a query that takes 0.2650 seconds to run and I would like to optimize it, I have done a lot of tests (Add new indexes, delete them, create views) but nothing has improved the performance of the following query:
SELECT enlace_click.id,enlace_click.enlace,enlace_click.cantidad
FROM enlace_click
INNER JOIN enlace ON enlace_click.enlace = enlace.id
ORDER BY enlace_click.cantidad ASC , enlace_click.enlace DESC
Mostrando filas 0 - 29 (total de 802430, La consulta tardó 0.2650 seg)
EXPLAIN:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE enlace_click ALL UNIQUE,enlace NULL NULL NULL 1074631 Using filesort
1 SIMPLE enlace eq_ref PRIMARY PRIMARY 4 gnula_serie.enlace_click.enlace 1 Using index
Searching why it may take so long:
SELECT enlace_click.id,enlace_click.enlace,enlace_click.cantidad
FROM enlace_click
INNER JOIN enlace ON enlace_click.enlace = enlace.id
ORDER BY enlace_click.cantidad ASC , enlace_click.enlace ASC
Mostrando filas 0 - 29 (total de 802430, La consulta tardó 0.0016 seg)
EXPLAIN:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE enlace_click ALL UNIQUE,enlace NULL NULL NULL 1074631 Using filesort
1 SIMPLE enlace eq_ref PRIMARY PRIMARY 4 gnula_serie.enlace_click.enlace 1 Using index
SELECT enlace_click.id,enlace_click.enlace,enlace_click.cantidad
FROM enlace_click
INNER JOIN enlace ON enlace_click.enlace = enlace.id
Mostrando filas 0 - 29 (total de 802489, La consulta tardó 0.0009 seg)
EXPLAIN:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE enlace_click ALL UNIQUE,enlace NULL NULL NULL 1074670 NULL
1 SIMPLE enlace eq_ref PRIMARY PRIMARY 4 gnula_serie.enlace_click.enlace 1 Using index
INDEX:
Nombre de la clave Tipo Único Empaquetado Columna Cardinalidad Cotejamiento Nulo
cantidad,enlace BTREE No No cantidad 2023 A No
enlace 1074590 A No