表的最佳方式:刪除從InnoDB表5K行與30M行
- foreign_id_1
- foreign_id_2
- 整數
- DATE1
- DATE2
- 初級(foreign_id_1,foreign_id_2)
查詢:delete from table where (foreign_id_1 = ? or foreign_id_2 = ?) and date2 < ?
無日期查詢大約需要40秒。這是太高:(隨着時間更加長..
的選項有:
create
另一個表和insert
select
,然後rename
使用限制和查詢運行多次- 拆分查詢運行
foreign_id_1
然後foreign_id_2
- 使用select然後單行刪除
有沒有更快的方法?
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)
請在查詢中發佈`EXPLAIN`的結果。我的錢沒有足夠的索引。 – Blrfl 2010-12-02 18:46:56
添加查詢說明 – zhekanax 2010-12-02 19:05:22