简体   繁体   English

Oracle View上的更新速度极慢

[英]Oracle Update on View extremly slow

I have this simple UPDATE Statement: 我有这个简单的UPDATE语句:

  UPDATE   v_my_view mv
     SET   mv.name   = 
              (SELECT   RTRIM(name)
                 FROM   v_another_view av
                WHERE av.KEY_ID = mv.KEY_ID)
   WHERE mv.VALID = 1;

This Statement takes extremely long (20 secs), while other, more complicated updates on the same view take less than 1 second. 该语句耗时极长(20秒),而同一视图上的其他更复杂的更新则不到1秒。 First I thought it is the RTRIM function, but it's not, if I dont't use it, its slow as before. 首先,我认为它是RTRIM函数,但如果我不使用它,它就不会像以前那样慢。

SELECTs on both views return the records very fast. 两个视图上的SELECT都非常快速地返回记录。

There is no TRIGGER on the view, but there is one on the table behind. 视图上没有TRIGGER,但后面的桌子上有TRIGGER。 But it cannot be the bottleneck, since even when I comment all the TRIGGER code out, it has the same slow performance. 但这不是瓶颈,因为即使我注释掉所有TRIGGER代码,它的性能仍然一样慢。

Anybody has a suggestion? 有人有建议吗?

EDIT: Added missing WHERE clause EDIT: The view (or the table behind) contains only 8000 records each, no special data types. 编辑:添加了缺少的WHERE子句编辑:该视图(或后面的表)每个仅包含8000条记录,没有特殊的数据类型。

You are updating the entire view without any WHERE clause. 您正在更新整个视图,而没有任何WHERE子句。

If you have a big amount of data or even indexes, it could be slowing your operation. 如果您有大量数据甚至索引,则可能会减慢操作速度。

Do you have any indexes on column name in underlying table of v_my_view ? v_my_view基础表中的列name是否有任何索引? If yes, disable them and see if it leads to any improvements on the performance of the query. 如果是,请禁用它们并查看它是否对查询性能有任何改善。 As Nick.McDermaid puts it, it is hard to say without execution plans and wait event statistics. 正如Nick.McDermaid所说,没有执行计划和等待事件统计信息很难说。 The best you can hope for is some form of psychic debugging. 您可以期望的最好的方法是某种形式的心理调试。

merge --+ use_hash(MV,AV) no_merge(AV) no_merge(MV)
    into (select * from v_my_view MV where valid = 1)
using v_another_view AV
on MV.key_id = AV.key_id
when matched then
    update
    set MV.name = rtrim(AV.name)
;

Although I'm not absolutely sure about merge ing into an inline view, but you may try it at least (and post a comment if it does not work). 虽然我不确定要merge到内联视图中,但是您可以至少尝试一下(如果不起作用,请发表评论)。

Also, it is a good practice to show execution plans of your queries along with the queries. 另外,最好将查询的执行计划与查询一起显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM