テーブル:
- 外部ID_1
- 外部ID_2
- 整数
- 日付1
- 日付2
- プライマリ (foreign_id_1、foreign_id_2)
クエリ:delete from table where (foreign_id_1 = ? or foreign_id_2 = ?) and date2 < ?
日付クエリを使用しない場合、約 40 秒かかります。それは高すぎます:(日付がはるかに長い..
オプションは次のとおりです。
create
別のテーブルとinsert
select
、次にrename
limit を使用してクエリを複数回実行するforeign_id_1
次に実行する分割クエリforeign_id_2
- 選択を使用してから単一行で削除
より速い方法はありますか?
mysql> explain select * from compatibility where user_id = 193 or person_id = 193 \G
id: 1
select_type: SIMPLE
table: compatibility
type: index_merge
possible_keys: PRIMARY,compatibility_person_id_user_id
key: PRIMARY,compatibility_person_id_user_id
key_len: 4,4
ref: NULL
rows: 2
Extra: Using union(PRIMARY,compatibility_person_id_user_id); Using where
1 row in set (0.00 sec)
mysql> explain select * from compatibility where (user_id = 193 or person_id = 193) and updated_at < '2010-12-02 22:55:33' \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: compatibility
type: index_merge
possible_keys: PRIMARY,compatibility_person_id_user_id
key: PRIMARY,compatibility_person_id_user_id
key_len: 4,4
ref: NULL
rows: 2
Extra: Using union(PRIMARY,compatibility_person_id_user_id); Using where
1 row in set (0.00 sec)