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
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
解决方案 »
- 寻找ORACLE的学习方向
- oracle case when 问题!
- 高手来帮帮忙 如何在PACKAGE BODY 中引用存储过程!
- 用多线程写的JAVA类,查询Oracle数据库,但每执行一次,死链接就增加,大家帮帮忙!谢谢!
- 请问一下oracle内部存储容量的问题
- 我怎么看不到企业管理器呢!
- 一个复杂的交叉报表的sql写法
- oracle第三方工具,名字叫TOAD的工具在哪里有免费下载的?
- Oracle 静默安装执行sqlplus报错,求大神帮助~~~
- Oracle 11g自带的SQL Developer的SQL编辑器和执行结果中文显示乱码,求大神帮忙
- 触发器无效且未通过重新确认?
- oracle数据库实例等不等于sqlserver的数据库
参考下
where not exists (select * from tb2 b where b.id=a.id);tb2 10w,TB1 1000W,一般来说上面用exists不合适,可以测试下,
改为 not in试试,反正你的是主键,没有NULL
以执行计划为准
如果加快速度可以考虑PL/SQL的批处理,你这个直接用SQL基本要等大半天,你可以试试
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列是空吗?
truncate tb1;
alter table tb3 rename to tb1;
换个角度想问题,顶一下