如何在 Oracle 中显示 SQL 执行进度以及执行计划?
问题:
您想要查看 Oracle SQL 在 SQL 执行计划中花费时间的位置。
解决方案
使用 Oracle 11g 版本,我们可以在 SQL 运行时查看 SQL 执行计划进度。“V$SQL_PLAN_MONITOR” 视图包含 SQL 语句执行计划的每个步骤的一行。下面的 SQL 将有助于查看执行计划以及进度。
“V$SQL_PLAN_MONITOR” 为您提供有关使用最多资源的步骤的信息。“V$SQL_PLAN_MONITOR” 中的统计信息每秒更新一次。
我们还可以使用 DBMS_SQLTUNE 包的 REPORT_SQL_MONITOR 函数生成执行计划中查询进度的实时文本、HTML 甚至 XML 报告。
示例
select a.sid ,a.status ,to_char(a.sql_exec_start,'yymmdd hh24:mi') start_time ,a.plan_line_id ,a.plan_operation ,a.plan_options ,a.output_rows ,a.workarea_mem mem_bytes ,a.workarea_tempseg temp_bytes from v$sql_plan_monitor a ,v$sql_monitor b where a.status NOT LIKE '%DONE%' and a.key = b.key order by a.sid, a.sql_exec_start, a.plan_line_id;
生成 HTML 报告。
示例
SET LINES 3000 PAGES 0 LONG 1000000 TRIMSPOOL ON SPOOL report.html select dbms_sqltune.report_sql_monitor(session_id=> 901, event_detail => 'YES' ,report_level => 'ALL' ,type => 'HTML' ) from dual; SPOOL OFF;