读书人

mysql百万数据查询 用什么代替in,该如

发布时间: 2012-03-09 21:42:54 作者: rapoo

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 Bset STATU_ID=2,USER_ID='c'where A.IMG_ID=B.IMG_ID 

读书人网 >Mysql

热点推荐