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)