彻底弄懂oracle硬解析、软解析、软软解析 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

    硬解析和软解析有相同的一步,而软软解析与硬解析、软解析完全不一样,

彻底弄懂oracle硬解析、软解析、软软解析

。先来说下理论上的东西,然后来做个实验。

    硬解析过程:

    1.语法、语义及权限检查;

    2.查询转换(通过应用各种不同的转换技巧,会生成语义上等同的新的SQL语句,如count(1)会转为count(*));

    3.根据统计信息生成执行计划(找出成本最低的路径,这一步比较耗时);

    4.将游标信息(执行计划)保存到库缓存。

    软解析过程:

    1.语法、语义及权限检查;

    2.将整条SQL hash后从库缓存中执行计划。

    软解析对比硬解析省了三个步骤。

    软软解析过程:

    要完全理解软软解析先要理解游标的概念,当执行SQL时,首先要打开游标,执行完成后,要关闭游标,游标可以理解为SQL语句的一个句柄。

    在执行软软解析之前,首先要进行软解析,MOS上说执行3次的SQL语句会把游标缓存到PGA,这个游标一直开着,当再有相同的SQL执行时,则跳过解析的所有过程直接去取执行计划。

    SQL> drop table test purge;

    SQL> alter system flush shared_pool;

    SQL> create table test as select * from dba_objects where 1<>1;

    SQL> exec dbms_stats.gather_table_stats(user,'test');

    硬解析:

    SQL> select * from test where object_id=20;

    未选定行

    SQL> select * from test where object_id=30;

    未选定行

    SQL> select * from test where object_id=40;

    未选定行

    SQL> select * from test where object_id=50;

    未选定行

    软解析:

    SQL> var oid number;

    SQL> exec :oid:=20;

    SQL> select * from test where object_id=:oid;

    未选定行

    SQL> exec :oid:=30;

    SQL> select * from test where object_id=:oid;

    未选定行

    SQL> exec :oid:=40;

    SQL> select * from test where object_id=:oid;

    未选定行

    SQL> exec :oid:=50;

    SQL> select * from test where object_id=:oid;

    未选定行

    软软解析:

    SQL> begin

    for i in 1..4 loop

    execute immediate 'select * from test where object_id=:i' using i;

    end loop;

    end;

    /

    SQL> col sql_text format a40

    SQL> select sql_text,s.PARSE_CALLS,loads,executions from v$sql s

    where sql_text like 'select * from test where object_id%'

    order by 1,2,3,4;

    SQL_TEXT PARSE_CALLS LOADS EXECUTIONS

    ---------------------------------------- ----------- ---------- ----------

    select * from test where object_id=20 1 1 1

    select * from test where object_id=30 1 1 1

    select * from test where object_id=40 1 1 1

    select * from test where object_id=50 1 1 1

    select * from test where object_id=:i 1 1 4

    select * from test where object_id=:oid 4 1 4

    可以看到软解析与软软解析相比,软软解析只是解析一次,

电脑资料

彻底弄懂oracle硬解析、软解析、软软解析》(http://meiwen.anslib.com)。

    字段解释:

    PARSE_CALLS 解析的次数

    LOADS 硬解析的次数

    EXECUTIONS 执行的次数

最新文章