请问如果数据量大的话,这条sql可以怎样优化效率高?
delete from table1 where pid not in(select id from table2)
或
select * from table1 where pid not in(select id from table2)
delete from table1 where pid not in(select id from table2)
或
select * from table1 where pid not in(select id from table2)
解决方案 »
- 请大家进来看看结果为何有差别,用hibernate连oracle10g进行查询的4种写法
- oracle完整安装,需要安装哪些组件?
- [求助]oracle全文检索
- 怎么样才能彻底卸载orcle 10g 啊?
- 如何用sql语句编辑对象
- 将SQL-Server存储过程转换为Oracle的,谢谢大家~~~(4)
- 这样的update怎样写?
- 我是刚开始学习oracle的请问一下关于mount和nomount的问题
- 使用sql worksheet时出错,提示“ORA-12560:TNS:协议适配器错误”?(在线给分)
- 如何使用long型?能不能用long like '%字符串%'?如果不能,有没有其他方法解决,谢谢!
- plsql创建表,注释显示问号;查询时,中文可以正常显示
- sql 缺失表达式
where pid in(
select id from t2
minus
select pid from mytable
)PS:一定要多重方法反复测试。
创建临时表,走索引
create table temp_1 as
select /*+ parallel(a,20)*/
a.id
from table2 a;create index idx_id on temp_1(id) parallel 20;select /*+ index (b)*/
*
from table1 a
where a.pid not exists (select 1 from temp_1 b where a.pid = b.id)
select * from table1 a where not exists (select 1 from table2 b where a.pid=b.id)
1.把 * 替换为表中的字段名
select t1.*
from table1 t1
left join table2 t2
on t2.id = t1.pid
where t2.id is null
1.建议把其他表的索引删除或者无效
2.通过rowid删除
3.如数数据量特别大的时候可以考虑直接获取create table 然后rname成原来的表名
delete from table1 t where rowid not in (select t2.rowid from table2 t1,table1 t2 where t1.pid = t2.pid )
或
select * from table1 where pid not in(select id from table2)
如果table2没有重复数据的话,直接外连接就好了
select t.* from table1 t,table2 t1 where t.pid = t2.id(+) and t2.id is null;