非常にゆっくりと、必要な結果を生成する複雑なクエリがあります。(600秒くらい!)
SELECT *
FROM clients
WHERE type = 'gold'
AND state IN( 'TX', 'WV', 'NV', 'IL' )
AND phone not in
(
select phone
from clients
group by phone
having count(*) > 1
)
AND cell not in
(
select cell
from clients
group by cell
having count(*) > 1
)
EXPLAIN SELECT は私に与えます:
id, select_type, table, Possible_keys, key, key_len, ref, rows, Extra
1, PRIMARY, clients, ALL, ndxCLients_state,IGA_Count, , , , 128070, Using where
2, DEPENDENT SUBQUERY, clients, ALL, , , , , 128070, Using temporary; Using filesort
3, DEPENDENT SUBQUERY, clients, index, , idx_Cell, 258, , 3, Using index
ここはどうしようか悩んでいます。電話フィールドのインデックスが必要だと私に伝えようとしていると思います。mysql ワークベンチを使用して、電話フィールドにインデックスを付けました。ここで何が欠けていますか?