MySQLテーブルの2つのdatetime列を比較または操作すると、かなり重大なパフォーマンス上の問題が発生します。私は約1,100万行のテーブルtbl
を持っています。MySQLはdatetime列のインデックスを無視しているようです
`id` int(11) NOT NULL AUTO_INCREMENT,
`last_interaction` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
`last_maintenence` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`),
KEY `last_maintenence_idx` (`last_maintenence`),
KEY `last_interaction_idx` (`last_interaction`),
ENGINE=InnoDB AUTO_INCREMENT=12389814 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
私はこのクエリを実行すると、それが実行する分程度かかり:クエリを記述
SELECT id FROM tbl
WHERE last_maintenence < last_interaction
ORDER BY last_maintenence ASC LIMIT 200;
がこれをレンダリング:
id: 1
select_type: SIMPLE
table: tbl
type: index
possible_keys: NULL
key: last_maintenence_idx
key_len: 5
ref: NULL
rows: 200
Extra: Using where
それがどのように見えるそれは次のようになりますMySQLはlast_interaction
のインデックスを検索/使用していません。それがなぜ起こるのか、どのようにそれを引き起こすのか誰にも分かりますか?
正解ありがとうございました。 – Matt
助けてうれしいです。 – e4c5