I have a Mysql database with 2 tables:
clientes and code
clientes have a field called celda (index called CG)
and code have a field called CG (index called CG)
they have the same data type
I have indexes in both fields.
EXPLAIN EXTENDED SELECT *
FROM Clientes
WHERE celda IN ('26022','26023','26024')
that uses the indexes and gave me this EXPLAIN
Code:
id select_type table type possible_keys key key_len ref rows Extra
------ ----------- ----------------------- ------ ------------- ------ ------- ------ ------ -------------
1 SIMPLE Clientes range CG CG 20 (NULL) 389 Using where
SET @sitio='AAA';
EXPLAIN EXTENDED SELECT *
FROM Clientes
WHERE celda IN (SELECT CG FROM CODE
WHERE sitio=@sitio)
the subquery gives as a result the same values im using directly in previuos query: '26022','26023','26024' but the explain is this:
Code:
id select_type table type possible_keys key key_len ref rows Extra
------ ------------------ ----------------------- -------------- ------------- ------ ------- ------ ------- -------------
1 PRIMARY Clientes ALL (NULL) (NULL) (NULL) (NULL) 2689275 Using where
2 DEPENDENT SUBQUERY CODE index_subquery CG CG 23 func 1 Using where
Any idea why mysql is not using the index in the seccond query?
thanks!