select 非常快,insert into select 非常慢

shenhong088 2011-09-01 09:37:50
1、select * from (...) where rownum<3;一晃而过
2、select * from (...)如果完全执行,将所有结果集都查出来,是很慢。大约几百秒的样子。

但是
3、insert into tab 1 select * from (...) where rownum<3; 看执行计划,无论第一条还是所有,都是和2一个执行计划。
而且根本就执行不完,1个小时也是他。

如果4、insert into tab 1 select * from (...id=22) ;id为其中一个表的主键,则一晃而过,能成功插入。


晕了,用了这么久oracle ,第一次发生这种事。
...全文
7857 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenhong088 2011-09-13
  • 打赏
  • 举报
回复
存在主键及一个联合索引。没有delete,我测试都是truncate

第二个结果集有400万,其实并不算多吧。

inthirties 2011-09-10
  • 打赏
  • 举报
回复
第二个的结果集有多少呀。
aptweasel 2011-09-10
  • 打赏
  • 举报
回复
你要看一下你的数据库数据是不是已经很多了,或是建的索引太多了,索引建的不好,会严重影响插入的。
尤其是主键索引和非唯一索引,要慎用,还有如果数据不多的话,这个表不是不有大量的DELETE操作,DELETE删除数据时,会使索引变得臃肿,如果是这样,你要检查代码,以后不要做DELETE操作了,表已经慢了,那就只能做rebuild,然后就好了。
shenhong088 2011-09-08
  • 打赏
  • 举报
回复
看不太明白v$session_wait,等待的不是当前sql,而是其他的,而其他的这些用sid查询没有语句。
另:
insert into tab 1 select * from (...) where rownum<3; --前两条插入tab1
jdsnhan 2011-09-06
  • 打赏
  • 举报
回复
看一下v$session_wait,看有什么在等待
walkman_22 2011-09-06
  • 打赏
  • 举报
回复
insert into tab 1 select * from (...) where rownum<3;

这句表示什么含义?
lnuwhy 2011-09-02
  • 打赏
  • 举报
回复
如果觉得慢,可以使用并行操作
shenhong088 2011-09-02
  • 打赏
  • 举报
回复
没有多个会话都在对该表做写操作,现在加入函数rownum就比较快了。但是我觉得还是慢。50w--558s
目前语句是这样
insert into ql_tz_total (total_ID, state, PERSON_CARD_ID, ql_job_id)
select aa.person_ID,'0',
LOOKUP_person(LOOKUP_image(aa.IMAGE_ID), 'FIELD_10') FIELD_10,
aa.QL_JOB_ID
from (select c.FEATURE_ID, c.IMAGE_ID, e.QL_JOB_ID
from total c, ql_tz_job e
where c.LOGIC_DB_ID = e.LOGIC_DB_ID
and c.total _ID > 0
and e.QL_JOB_ID = 322) aa
left OUTER JOIN ql_tz_total d on (d.QL_JOB_ID = 322 and
aa.total_id = d.total_id)
where d.total_id is null
and rownum<500000;

原先是insert into ql_tz_total
(total_ID, state, PERSON_CARD_ID, ql_job_id)
select /*+ first_rows(1) */ cc.total_id, 0, a.FIELD_10, cc.ql_job_id
from person a,
image b,
(select aa.total_ID, aa.IMAGE_ID,aa.QL_JOB_ID
from (select c.total_ID, c.IMAGE_ID,e.QL_JOB_ID
from total c, ql_tz_job e
where c.LOGIC_DB_ID = e.LOGIC_DB_ID
and c.total_ID>0
and e.QL_JOB_ID = 322
/* and c.total_ID=29495518*/) aa
left OUTER JOIN ql_tz_total d on (d.QL_JOB_ID = 322 and
aa.total_id = d.total_id)
where d.total_id is null) cc
where a.person_id = b.person_id
and b.image_id = cc.image_id--628
and rownum<2;
lnuwhy 2011-09-02
  • 打赏
  • 举报
回复
是不是多个会话都在对该表做写操作,有没有可能是锁的问题?
coolkisses 2011-09-02
  • 打赏
  • 举报
回复
这是正常现象,楼主为什么反而觉得是问题呢?
shenhong088 2011-09-02
  • 打赏
  • 举报
回复
但是,“4、insert into tab 1 select * from (...id=22) ;id为其中一个表的主键,则一晃而过,能成功插入。
”这时就非常快。感觉insert into tab 1 select * from (...) 和select * from (...) 不是一个执行计划。insert into tab 1 select /*+ first_rows(1) */ * from (...) ,这样也是非常慢!
dawugui 2011-09-02
  • 打赏
  • 举报
回复
select 是查询.不更改数据
insert 是插入数据,更改数据,
这两个哪个快?哪个不快,很明显吧.

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧