【问题标题】:Cost Suffix in Oracle Explain PlansOracle 解释计划中的成本后缀
【发布时间】:2021-02-21 07:40:02
【问题描述】:

我有以下解释计划的以下 sn-p:

解释计划 1

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                    | Name                         | E-Rows |E-Bytes|E-Temp | Cost (%CPU)| E-Time   |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                             |                              |        |       |       |    37M(100)|          |       |       |          |
...
|* 36 |    INDEX UNIQUE SCAN                         | ZX_ACCOUNTS_U2               |      1 |    36 |       |     0   (0)|          |  1025K|  1025K|          |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

解释计划 2

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                    | Name                         | E-Rows |E-Bytes|E-Temp | Cost (%CPU)| E-Time   |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                             |                              |        |       |       |   879T(100)|          |       |       |          |
...
|* 39 |    INDEX UNIQUE SCAN                         | ZX_ACCOUNTS_U2               |      1 |    36 |       |     0   (0)|          |  1025K|  1025K|          |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

据我所知,Explain Plan 1 的总成本是 37 Millon。但我不确定解释计划 2 的成本。是 87.9 万吗?还是879万亿? 我试图找到一些关于后缀的文档,但找不到。

谢谢!

【问题讨论】:

  • 是的,T 是万亿。请注意,您不一定只比较两个不同语句的计划之间的成本,除非它们碰巧来自同一个 10053 跟踪。无法保证一个成本为 879 万亿的计划实际运行所需的时间比一个成本为 3700 万的计划要长。
  • @JustinCave 谢谢。是的,它们与查询相同,我只是在尝试使用提示。谢谢!
  • 但是,如果您要添加提示,它们就不是同一个查询。添加提示可以改变各种操作的成本计算方式,因此您不能只比较成本并得出提示是否会产生更好的计划的结论。

标签: sql oracle performance


【解决方案1】:

说明计划编号通常遵循International System of Units prefixes:K = 千克、M = 兆、G = 千兆、T = 兆、P = 拍和 E = 埃。

编号方案有一些奇怪之处。当我期望小写“k”时,解释计划使用大写“K”表示“kilo”。 Oracle 在前缀之间切换时存在一些不一致 - K、M 和 G 可以有四个数字,但 T 和 P 只能有三个数字。而“E”仅表示某些数字的“exa”;非常大的数字总是显示为“18E”。

以下是DBMS_XPLAN.DISPLAY使用的不同输入和显示数字:

Number of rows           Explain Plan Output
-----------------------  -------------------
9                        |     9 |
99                       |    99 |
999                      |   999 |
9999                     |  9999 |
99999                    | 99999 |
999999                   |   999K|
9999999                  |  9999K|
99999999                 |    99M|
999999999                |   999M|
9999999999               |  9999M|
99999999999              |    99G|
999999999999             |   999G|
9999999999999            |  9999G|
99999999999999           |    99T|
999999999999999          |   999T|
9999999999999999         |    10P|
99999999999999999        |   100P|
999999999999999999       |   999P|
9999999999999999999      |    10E|
99999999999999999999     |    18E|
999999999999999999999    |    18E|
9999999999999999999999   |    18E|

下面是生成结果的代码:

--Create sample table that is only used for statistics.
--drop table test1;
create table test1(a number);

--How does the DBMS_XPLAN.DISPLAY handle large numbers?
declare
    v_lines sys.odcivarchar2list;
    v_num_rows number;
begin
    dbms_output.put_line('Number of rows           Explain Plan Output');
    dbms_output.put_line('-----------------------  -------------------');

    --Repeat the process for many numbers.
    for i in 1 .. 22 loop
        --Increase the number of digits.
        v_num_rows := rpad('9', i, '9');

        --Change the stats.
        dbms_stats.set_table_stats(user, 'TEST1', numrows => v_num_rows);

        --Generate the explain plan.
        execute immediate 'explain plan for select * from test1';

        --Gather the explain plan.
        select plan_table_output
        bulk collect into v_lines
        from table(dbms_xplan.display);

        --Output the relevant part of the explain plan.
        --The row and column numbers may be different on your system.
        dbms_output.put(rpad(v_num_rows, 22, ' ') || '   ');
        dbms_output.put_line(substr(v_lines(6), 35, 9));
    end loop;
end;
/

(我使用行数而不是成本,因为行数更容易操作。我很确定 Oracle 以相同的方式显示这两个数字。)

【讨论】:

    猜你喜欢
    • 2012-11-12
    • 2011-02-04
    • 2012-04-16
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-05
    • 2013-02-02
    相关资源
    最近更新 更多