解释 Oracle 中的计划输出

Explain Plan output in Oracle

我不是 Oracle 的专家,只是刚开始研究。当我执行以下查询时,它会以 |(pipeline) 格式输出。我想要 EXPLAIN PLANtabluarjsonxml 中输出,等等...这可能吗?

EXPLAIN PLAN FOR SELECT * FROM user_master;
SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY('plan_table'));

Output:

    Plan hash value: 3060894046

    ---------------------------------------------------------------------------------
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |             |     1 |    94 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| USER_MASTER |     1 |    94 |     2   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------

如果您直接访问PLAN_TABLE,您可以以表格形式获取它:

select plan_id,
       operation,
       options,
       cost,
       cpu_cost,
       io_cost,
       temp_space,
       access_predicates,
       bytes,
       object_name,
       object_alias,
       optimizer,
       object_type
from plan_table
start with parent_id is null
connect by prior id = parent_id;

由于 plan_table 可以包含不同的计划,最好使用明确的语句 id:

explain plan 
  set statement_id = 'foo'
for
select ...;

然后在 plan_table 上的 select 中使用它:

select ....
from plan_table
start with parent_id is null and statement_id = 'foo'
connect by prior id = parent_id;

要将此设置为 XML,您可以使用:

select dbms_xplan.display_plan(type => 'xml')
FROM dual