¿Cómo indicar el índice a utilizar en una consulta de MySQL select?


Tengo una consulta MySQL (ejecutando MySQL 5.0.88), que estoy tratando de acelerar. La tabla subyacente tiene múltiples índices y para la consulta en cuestión, se utiliza el índice incorrecto (i_active - 16.000 filas, frente a i_iln - 7 filas).

No tengo mucha experiencia con MySQL, pero he leído que hay una pista use index, que puede forzar a MySQL a usar un determinado índice. Lo estoy intentando así:

 SELECT art.firma USE INDEX (i_iln)
 ...

Pero esto produce un error de MySQL.

Pregunta:
¿Puede alguien decirme lo que estoy haciendo mal? (Excepto correr 5.0.88, que no puedo cambiar.)

Author: JYelton, 2012-07-31

3 answers

Te perdiste el FROM table

El SQL correcto debe ser:

SELECT art.firma FROM your_table USE INDEX (i_iln) WHERE ....

 41
Author: Raptor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-31 01:15:06
select * from table use index (idx);

Http://dev.mysql.com/doc/refman/5.0/en/index-hints.html

 5
Author: Markus Mikkolainen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-20 22:17:32

Seleccione Coloumn1,Coloumn2,Coloumn.... DE TABLE_NAME ÍNDICE de USO(index_name) DONDE Columna="condición";

Si tiene un índice correcto, no necesita usar index(). su consulta automic seleccione el índice correcto.Si su consulta lenta después de usar índice thn vuelva a comprobar su índice, algo mal en el índice. gracias de antemano.introduzca el código aquí

 -1
Author: kuldeep upadhyay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-29 11:17:25