简体   繁体   English

Oracle数据库10g VIEW性能

[英]Oracle Database 10g VIEW performance

I have a view in one of my Oracle Database that is taking too long to execute. 我的一个Oracle数据库中的一个视图执行时间太长。 When the statement runs, it does not seem to stop. 语句运行时,它似乎并没有停止。

Is there anyway that we can verify the performance of this view or how we can check to see if the statement session is 'hanging'? 无论如何,我们是否可以验证此视图的性能,或者如何检查语句会话是否正在“挂起”?

Thanks, N2EE 谢谢,N2EE

UPDATE 更新

I realised that the issue is with the underlying query in the view. 我意识到问题出在视图中的基础查询。 Thanks to Edwin for the autotrace fix. 感谢Edwin提供的自动跟踪修复程序。

Most likely the execution of your query is very slow. 查询的执行很可能非常慢。

You can see how the query in executed in the database by using explain plan. 您可以使用说明计划查看查询如何在数据库中执行。

If you have SQL*Plus you can do this very easy with the following statement: 如果您拥有SQL * Plus,则可以使用以下语句轻松完成此操作:

set autotrace traceonly

Then type in the query, and you will get statistics on your query like this: 然后输入查询,您将获得有关查询的统计信息,如下所示:

SQL> set autotrace traceonly
SQL>  select * from o_drops;

4461 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3820245448

-----------------------------------------------------------------------------
| Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |         |  4287 |   280K|    11  (10)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| O_DROPS |  4287 |   280K|    11  (10)| 00:00:01 |
-----------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
        333  consistent gets
         48  physical reads
          0  redo size
     337057  bytes sent via SQL*Net to client
       2316  bytes received via SQL*Net from client
        299  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
       4461  rows processed

If one of the resources is very high, it could work to rewrite the query and/or add indexes to the table you are using. 如果其中一种资源非常多,则可以重写查询和/或向正在使用的表中添加索引。

You'll need to take a look of the performance of the query that makes up the view. 您需要查看组成视图的查询的性能。 The best way to do that is to do an explain plan on the sql statement the view uses. 最好的方法是对视图使用的sql语句进行解释计划。 That will indicate if its doing full table scans or some other less than optimal behavior. 这将表明它是在执行全表扫描还是其他一些非最佳行为。 Tune the query and your view should run much better. 调整查询,您的视图应运行得更好。

Are you talking the creation or replacement of an existing view (ie executing the CREATE OR REPLACE VIEW... statement) or selecting from a view. 您是在谈论创建或替换现有视图(即执行CREATE或REPLACE VIEW ...语句)还是从视图中进行选择。

In the former case, it is probably that some session has it locked. 在前一种情况下,可能是某个会话已将其锁定。 For example, if someone is updating or deleting through the view you won't be able to replace it. 例如,如果某人正在通过视图进行更新或删除,则您将无法替换它。 Depending on your version, you might be able to see the blocker by checking the 'BLOCKING_SESSION' column of v$session. 根据您的版本,您可能可以通过查看v $ session的“ BLOCKING_SESSION”列来查看阻止程序。

In the latter case, it isn't a view that is slow, but a query. 在后一种情况下,不是慢的视图而是查询。 The view is pretty much irrelevant. 该视图几乎无关紧要。 Check the explain plan (preferably using DBMS_XPLAN.DISPLAY_CURSOR with the sql_id from v$sql) and see what it is up to. 检查说明计划(最好将DBMS_XPLAN.DISPLAY_CURSOR与来自v $ sql的sql_id一起使用),并查看其计划。 v$session_longops may give a pointer. v $ session_longops可以给出一个指针。

Generate AWR report based on snapshot ID's 根据快照ID生成AWR报告

There is TWO sql script to create AWR report. 有两个SQL脚本可以创建AWR报告。 1. awrrpt.sql If we have only One Oracle Database then run awrrpt.sql sql script. 1. awrrpt.sql如果只有一个Oracle数据库,请运行awrrpt.sql sql脚本。

  1. awrrpti.sql If we have more than One Oracle Instance (Like RAC) then run awrrpti.sql script so that we can particular instance for awr report creation. awrrpti.sql如果我们有多个Oracle实例(如RAC),请运行awrrpti.sql脚本,以便我们可以为awr报告创建特定实例。

Location of AWR report sql script $ORACLE_HOME/rdbms/admin AWR报告SQL脚本$ ORACLE_HOME / rdbms / admin的位置

Assuming that the problem is the underlying query, the performance problems might be because the tables used haven't been analyzed. 假设问题是基础查询,则性能问题可能是因为尚未分析所使用的表。
You can use the DBMS_STATS package to update Oracle's information about the tables and then see if the speed of the query improves. 您可以使用DBMS_STATS包来更新Oracle关于表的信息,然后查看查询速度是否提高。

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

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