Есть такой запрос
EXPLAIN Select otchet.*, @d:=otchet.date,@p:=otchet.point, (SELECT COUNT(*) FROM zaqvka WHERE DATE(zaqvka.data)=@d AND zaqvka.n_point=@p) as count_zaqvok from otchet where otchet.date LIKE "2013-04-25" AND otchet.point="1"\G
Получаем
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: otchet
type: ref
possible_keys: date,point
key: point
key_len: 2
ref: const
rows: 218
Extra: Using where
*************************** 2. row ***************************
id: 2
select_type: UNCACHEABLE SUBQUERY
table: zaqvka
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 6598
Extra: Using where
2 rows in set (0.00 sec)
Но индексы в подзапросной таблице
zaqvka есть и на
zaqvka.data и в
zaqvka.n_poinEXPLAIN SELECT COUNT(*) FROM zaqvka WHERE DATE(data)="2013-04-25" AND zaqvka.n_point="1"\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: zaqvka
type: ref
possible_keys: zaqvka_n_point
key: zaqvka_n_point
key_len: 2
ref: const
rows: 2822
Extra: Using where
1 row in set (0.00 sec)
Отчего так происходит?