私はInnoDBとMEMORYバージョンのテーブルを持っています。両方とも同じ索引と同じ30,000行のデータを持ちます。 MEMORYテーブルに対して実行すると非常に遅く実行される特定のクエリがあります。ここで なぜMEMORYテーブルのこのクエリはInnoDBのツインよりも遅いのですか?
は、InnoDBは反対だ:SELECT emails.id
FROM emails
LEFT JOIN custom_data_person pd1 ON (pd1.person_id = emails.person_id)
WHERE pd1.field_id = 13
2928 rows in set (0.24 sec)
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pd1
type: ref
possible_keys: person_id,field_id
key: field_id
key_len: 5
ref: const
rows: 20240
Extra: Using where; Using index
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: emails
type: ref
possible_keys: person_id
key: person_id
key_len: 4
ref: test.pd1.person_id
rows: 1
Extra: Using index
ここでのメモリ:
SELECT emails.id
FROM emails_memory AS emails
LEFT JOIN custom_data_person pd1 ON (pd1.person_id = emails.person_id)
WHERE pd1.field_id = 13
2928 rows in set (1.40 sec)
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: emails
type: ALL
possible_keys: person_id
key: NULL
key_len: NULL
ref: NULL
rows: 30000
Extra:
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: pd1
type: ref
possible_keys: person_id,field_id
key: person_id
key_len: 10
ref: test.emails.person_id,const
rows: 1
Extra: Using where; Using index
(私はデフォルトのハッシュインデックスと同じしようとした結果が得られたPERSON_IDインデックスはBTREEインデックスであることに注意してください。同じように)
だから、MySQLは2番目のクエリを別の方法で最適化してパフォーマンスを悪化させるようです。何故ですか?それを "修正"することはできますか?
2つのテーブルで 'explain tablename'と' show indexes from tablename'を実行できますか? 2つの異なるエンジンが異なるように最適化するため、エンジンにヒントを提供する必要があります。 – DeveloperChris