mysql百万数据查询 用什么代替in
-
SQL code
create temporary table tmp_c select IMG_ID from img_entry_one where STATU_ID=1 limit 0,10; update img_entry_one set STATU_ID=2,USER_ID='c' where IMG_ID in (select IMG_ID from tmp_c); select IMG_PATH from imgs inner join tmp_c on imgs.IMG_ID=tmp_c.IMG_ID ; DROP TABLE tmp_c;
where IMG_ID in (select IMG_ID from tmp_c);
怎么写好,用in太慢了。
update img_entry_one a inner join tmp_c b on a.IMG_ID=b.IMG_ID
set STATU_ID=2,USER_ID=’c’
在img_entry_one、tmp_c 表IMG_ID上建立索引
mysql的in嵌套select语句优化的不好 要避免
改成表连接即可
-
SQL code
update img_entry_one A,tmp_c B set STATU_ID=2,USER_ID='c' where A.IMG_ID=B.IMG_ID