停止SQL代码执行

Meh*_*lar 3 sql database oracle sql-navigator

我们有一个庞大的Oracle数据库,我经常使用SQL Navigator(v5.5)获取数据.有时,我需要通过单击Stop按钮来停止代码执行,因为我意识到我的代码中缺少部分.问题是,点击Stop按钮后,完成停止过程需要很长时间(有时需要数小时!).该计划Stopping...在底栏显示,我失去了很多时间,直到它完成.

这背后的理由是什么?如何加快停止过程?以防万一,我不是管理员; 我是一个使用某些视图访问数据库的有限用户.

Vin*_*rat 5

Two things need to happen to stop a query:

  1. The actual Oracle process has to be notified that you want to cancel the query
  2. If the query has made any modification to the DB (DDL, DML), the work needs to be rolled back.

For the first point, the Oracle process that is executing the query should check from time to time if it should cancel the query or not. Even when it is doing a long task (big HASH JOIN for example), I think it checks every 3 seconds or so (I'm looking for the source of this info, I'll update the answer if I find it). Now is your software able to communicate correctly with Oracle? I'm not familiar with SLQ Navigator but I suppose the cancel mechanism should work like with any other tool so I'm guessing you're waiting for the second point:

Once the process has been notified to stop working, it has to undo everything it has already accomplished in this query (all statements are atomic in Oracle, they can't be stopped in the middle without rolling back). Most of the time in a DML statement the rollback will take longer than the work already accomplished (I see it like this: Oracle is optimized to work forward, not backward). If you are in this case (big DML), you will have to be patient during rollback, there is not much you can do to speed up the process.

If your query is a simple SELECT and your tool won't let you cancel, you could kill your session (needs admin rights from another session) -- this should be instantaneous.