tb1 1000W id为主键
tb2 10W id为主键
优化下边的SQLdelete from tb1 a
 where not exists (select * from tb2 b where b.id=a.id);
表 test
id  value
     33
     23
     14
     3
     43
     11更新test表id列,按value升序,求最高效SQL
id value
1 3
2 11
3 14
4 23
5 33
6 43

解决方案 »

  1.   

    http://topic.csdn.net/t/20040806/11/3248313.html
    参考下
      

  2.   

    delete from tb1 a
     where not exists (select * from tb2 b where b.id=a.id);tb2  10w,TB1 1000W,一般来说上面用exists不合适,可以测试下,
    改为 not in试试,反正你的是主键,没有NULL
    以执行计划为准
      

  3.   

    看错了,你是not exists,基本会删除tb1表990W行,用SQL肯定是全表扫描了
    如果加快速度可以考虑PL/SQL的批处理,你这个直接用SQL基本要等大半天,你可以试试
      

  4.   


    delete from tb1 a
     where not exists (select * from tb2 b where b.id=a.id);
    这样的话,要比对1000万行,并删除索引,效率当然不高。create table tb3 as select * from tb1 where tb1.id=(select id from tb2);
    truncate tb1;
    alter table tb3  rename to tb1;
    你第二个问题的test表一开始id列是空吗?
      

  5.   

    create table tb3 as select * from tb1 where tb1.id=(select id from tb2);
    truncate tb1;
    alter table tb3 rename to tb1;
    换个角度想问题,顶一下