plan_hash_value

plan_hash_value
 
判断sql的访问路径是否改变的主要方法是:v$sql.plan_hash_value的值是否改变。如果不同的sql语句含有相同的

实验:
---创建表dept
SQL> create table dept as select * from scott.dept;

Table created.

---执行2条sql查询dept表
SQL> select deptno,dname from dept where deptno=10;

    DEPTNO DNAME
---------- --------------
        10 ACCOUNTING

SQL> select deptno,dname from dept;

    DEPTNO DNAME
---------- --------------
        10 ACCOUNTING
        20 RESEARCH
        30 SALES
        40 OPERATIONS

---通过v$sql查询关于dept的sql的address,hash_value,child_number,plan_hash_value,sql_text
col SQL_TEXT for a100  
select address,hash_value,child_number,plan_hash_value,sql_text from v$sql where sql_text like '%DEPT%';

ADDRESS          HASH_VALUE CHILD_NUMBER PLAN_HASH_VALUE SQL_TEXT
---------------- ---------- ------------ --------------- ----------------------------------------------------------------------------------------------------
000000008B589B40 3749466620            0       315352865 SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE NO_PARALLEL(SAMPLESUB) opt_param('paralle
                                                         l_execution_enabled', 'false') NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT /*+ NO_PARALLEL("DEPT") FULL("DEPT") NO_PARALLEL_INDEX("DEPT") */ 1 AS C1, 1 AS C
                                                         2 FROM "SYS"."DEPT" "DEPT") SAMPLESUB

0000000061211A40 2958346034            0      2657262937 select ADDRESS, HASH_VALUE, SQL_ID, PLAN_HASH_VALUE, CHILD_ADDRESS,          CHILD_NUMBER,  TIMESTAM
                                                         P, OPERATION,                                         OPTIONS, OBJECT_NODE, OBJECT#, OBJECT_OWNER, O
                                                         BJECT_NAME,                    OBJECT_ALIAS, OBJECT_TYPE, OPTIMIZER,
                                                                 ID, PARENT_ID, DEPTH, POSITION, SEARCH_COLUMNS, COST, CARDINALITY,           BYTES, OTHER_TA
                                                         G, PARTITION_START, PARTITION_STOP, PARTITION_ID,             OTHER, DISTRIBUTION, CPU_COST, IO_COST
                                                         , TEMP_SPACE,                          ACCESS_PREDICATES, FILTER_PREDICATES, PROJECTION, TIME, QBLOC
                                                         K_NAME,         REMARKS, OTHER_XML                                                           from GV
                                                         $SQL_PLAN                                                             where inst_id = USERENV('Insta
                                                         nce')

你可能感兴趣的:(数据库)