1 select id,start_member_id,start_date,modify_member_id,modify_date from formmain_0141 where id not in (select content_data_id from ctp_content_all where content_template_id='6890363387462501722' and content_data_id is not null ) limit 20000, 10000\G
Empty set (3 min 2.01 sec)
可見,生產中,該語句運行時間是3分2秒。
我們來看看其執行計劃,為什么這么慢:
2、我改寫后的索引,用的是 not exists ,內外交互式子查詢:
mysql> select id,start_member_id,start_date,modify_member_id,modify_date from formmain_0141 where not exists (select 1 from ctp_content_all where content_data_id= formmain_0141.id and content_data_id is not null and content_template_id='6890363387462501722') limit 20000, 10000 ;
Empty set (13.84 sec)