有两个表t1(id,charge) t2(id,charge)
两个表都在id字段上建有索引,两个表数据在1000万以上
现要列出t1表中id不在t2表中的数据初次接触大数据量查询,还请高手指点
两个表都在id字段上建有索引,两个表数据在1000万以上
现要列出t1表中id不在t2表中的数据初次接触大数据量查询,还请高手指点
解决方案 »
- ORACLE当前游标数量
- 删除了参数文件 不能启动数据库
- 求助关于to_date与to_char函数的问题
- 请问,sql语句里的location in是什么意思啊
- 在企業管理器里,點procedure,在選擇 view/edit details....,只能跳出個Edit Procedure得框,裡面得東東一點都
- java调用oracle存储过程,传出记录集,如何用java读取?--非一般--
- 请教关于oracle返回结果集的问题
- 两个关于SQL*PLUS使用的小问题.
- Oracle 中一次执行多条语句
- Oracle中Job与数据类型的基础问题
- 查询多条数据中的任意一条?
- oracle服务器安装后,其他计算机通过配置本地网络服务名访问该服务器时,总是无法连接成功!
(select 1 from t2 where newt1.id=t2.id)
两个表都在id字段上建有索引,两个表数据在1000万以上
现要列出t1表中id不在t2表中的数据 初次接触大数据量查询,还请高手指点--只查id
select t1.* from t1 where id not in (select id from t2)--同时查id , charge
select t1.* from t1 where not exists (select 1 from t2 where id = t1.id and charge = t2.charge)
select id from t01 where not exists (select 1 from t02 where t01.id=t02.id)
select id from t01 where id not in (select id from t02)
这样的句子最快。用到了两个表的INDEX.执行计划完全一样。假如想要t01里面的所有的数据,
select * from t01 where not exists (select 1 from t02 where t01.id=t02.id)
select * from t01 where id not in (select id from t02)
用到了
1.t01 的 table access full
2.t02 index的index fast full scan
也就是说,执行计划也是一样的。
这样的句子,最差。需要用到两次table access full,就是两次全表扫描,赫赫。
会死人的。
select * from t01 where id not in (select id from t02) 我试了一下,第一条语句要比第二条快很多,
有人能解释一下原因吗?
和执行顺序有关系。
Exist的时候,会先执行主查询,然后开始子查询,找到第一个匹配的。
IN的时候,会先检查子查询,然后这个结果保存在临时表里面。等到子查询全部结束了,开始主查询。就是这个需要临时表的动作以及之后和临时表的操作,浪费了时间。
外连接
注:最好2表的数据都有分区表空间,并且有索引分区表空间。
select id from t1
minus
select id from t2