sql >> Base de Datos >  >> RDS >> Mysql

Usar IN con una subconsulta no usa índice

Puede ver las respuestas a esta pregunta Te saldrán bien las ideas.

Estoy citando algunas respuestas

Brevemente, intente forzar el índice:

SELECT *
FROM mapping_channel_fqdn_virtual_host FORCE INDEX (name of the index you want to use)
WHERE (mapping_channel_fqdn_virtual_host.id IN (1,2,3,4,5,6,7,8,9,10));

O use JOIN en su lugar y vea la explicación

SELECT * FROM mapping_channel_fqdn_virtual_host mcf
JOIN (select max(id) as ids from mapping_channel_fqdn_virtual_host group by channel_id, fqdn_virtual_host_id)) AS mcfv 
ON mcf.id = mcfv.ids;