数据结构index是什么(数据库索引可以用hash实现吗)

技术数据库中plan_hash_value有什么用这篇文章给大家分享的是有关数据库中plan_hash_value有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

这篇文章给大家分享的是有关数据库中计划_散列_值有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

plan_hash_value判断sql的访问路径是否改变的主要方法是:v$sql.plan_hash_value的值是否改变。如果不同的sql语句含有相同的实验:---创建表deptSQL create table dept as select * from scott.dept;Table created.---执行2条sql查询dept表http://

;                     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')

000000008B5D3908 3410315986            0       903671040 select address,hash_value,child_number,plan_hash_value,sql_text from v$sql where sql_text like '%DEP
                                                         T%'

000000008B626668 3145184715            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 /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("DEPT") FULL("DEPT") NO_PARALLEL_INDEX("DEPT"
                                                         ) */ 1 AS C1, CASE WHEN "DEPT"."DEPTNO"=10 THEN 1 ELSE 0 END AS C2 FROM "SYS"."DEPT" "DEPT") SAMPLES
                                                         UB
                                                         
---通过v$sql_plan查询执行计划                                                         
SQL>  SELECT operation, options, object_name, cost  FROM v$sql_plan  WHERE address ='000000008B589B40' and HASH_VALUE='3749466620';

OPERATION                                                    OPTIONS                                                      OBJECT_NAME                          COST
------------------------------------------------------------ ------------------------------------------------------------
SELECT STATEMENT                                                                                                                                                  2
SORT                                                         AGGREGATE
TABLE ACCESS                                                 FULL                                                         DEPT                                    2

SQL>
SQL> SELECT operation, options, object_name, cost  FROM v$sql_plan  WHERE address ='000000008B626668' and HASH_VALUE='3145184715';

OPERATION                                                    OPTIONS                                                      OBJECT_NAME                          COST
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------ ----------
SELECT STATEMENT                                                                                                                                                  2
SORT                                                         AGGREGATE
TABLE ACCESS                                                 FULL                                                         DEPT                                    2
查询的执行计划完全一样

--对表dept做修改,增加索引
SQL> create index idx_dept_deptno on dept(deptno);

Index created.

---再次查看
SQL> 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')

000000008B5D3908 3410315986            0       903671040 select address,hash_value,child_number,plan_hash_value,sql_text from v$sql where sql_text like '%DEP
                                                         T%'

000000008E0A74E0 1470990285            0               0 LOCK TABLE "DEPT" IN SHARE MODE  NOWAIT
000000008B626668 3145184715            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 /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("DEPT") FULL("DEPT") NO_PARALLEL_INDEX("DEPT"
                                                         ) */ 1 AS C1, CASE WHEN "DEPT"."DEPTNO"=10 THEN 1 ELSE 0 END AS C2 FROM "SYS"."DEPT" "DEPT") SAMPLES
                                                         UB

----再次执行上述相同的2条sql
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下的address,hash_value,child_number,plan_hash_value,sql_text
SQL> 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')

000000008B5D3908 3410315986            0       903671040 select address,hash_value,child_number,plan_hash_value,sql_text from v$sql where sql_text like '%DEP
                                                         T%'

000000008E0A74E0 1470990285            0               0 LOCK TABLE "DEPT" IN SHARE MODE  NOWAIT
000000008B626668 3145184715            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 /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("DEPT") FULL("DEPT") NO_PARALLEL_INDEX("DEPT"
                                                         ) */ 1 AS C1, CASE WHEN "DEPT"."DEPTNO"=10 THEN 1 ELSE 0 END AS C2 FROM "SYS"."DEPT" "DEPT") SAMPLES
                                                         UB

00000000613ACE30 1756886759            0      2570986044 SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS opt_param('parallel_execution_enabled', 'false') NO_PARALLEL(
                                                         SAMPLESUB) NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),0), NVL(SUM(C2),0), NVL(SUM(C3),0
                                                         ) FROM (SELECT /*+ NO_PARALLEL("DEPT") INDEX("DEPT" IDX_DEPT_DEPTNO) NO_PARALLEL_INDEX("DEPT") */ 1
                                                         AS C1, 1 AS C2, 1 AS C3  FROM "SYS"."DEPT" "DEPT" WHERE "DEPT"."DEPTNO"=10 AND ROWNUM <= 2500) SAMPL
                                                         ESUB

6 rows selected.

---再次查看执行计划
SQL>   SELECT operation, options, object_name, cost  FROM v$sql_plan  WHERE address ='000000008B589B40' and HASH_VALUE='3749466620';

OPERATION                                                    OPTIONS                                                      OBJECT_NAME                          COST
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------ ----------
SELECT STATEMENT                                                                                                                                                  2
SORT                                                         AGGREGATE
TABLE ACCESS                                                 FULL                                                         DEPT                                    2

SQL> SELECT operation, options, object_name, cost  FROM v$sql_plan  WHERE address ='000000008B626668' and HASH_VALUE='3145184715';

OPERATION                                                    OPTIONS                                                      OBJECT_NAME                          COST
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------ ----------
SELECT STATEMENT                                                                                                                                                  2
SORT                                                         AGGREGATE
TABLE ACCESS                                                 FULL                                                         DEPT                                    2

SQL> SELECT operation, options, object_name, cost  FROM v$sql_plan  WHERE address ='00000000613ACE30' and HASH_VALUE='1756886759';

OPERATION                                                    OPTIONS                                                      OBJECT_NAME                          COST
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------ ----------
SELECT STATEMENT                                                                                                                                                  1
SORT                                                         AGGREGATE
VIEW                                                                                                                                                              1
COUNT                                                        STOPKEY
INDEX                                                        RANGE SCAN                                                   IDX_DEPT_DEPTNO                         1
最终发现执行计划已经改变,所以可以根据plan_hash_value值是否变化可知该sql语句的执行计划是否改变

通过v$sql视图的plan_hash_value值可以很方便的知道,该sql语句的执行计划是否改变,
通常我们的做法是分别将v$sql,v$sql_hash做两份快照,隔段时间后再做段快照,然后将其进行比较,查看是否有sql的执行计划已经改变。                                                       

感谢各位的阅读!关于“数据库中plan_hash_value有什么用”这篇文章就分享到这里了,希望

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/144266.html

(0)

相关推荐

  • Python海象运算符怎么用

    技术Python海象运算符怎么用这篇文章给大家分享的是有关Python海象运算符怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、在判断条件下允许操作。在一定程度上简化了代码,但降低了可

    攻略 2021年10月27日
  • 铵根的化合价,邱俊霖化合价style歌词

    技术铵根的化合价,邱俊霖化合价style歌词是这个吧铵根的化合价?!《化学价Style》——邱俊霖
    我背化合价
    化合价
    化合物中 钾钠银氢 常显 +1 价
    在化合物中 钙镁钡锌 通常显 +2 价
    在化合物中 氟氯溴碘 通

    生活 2021年10月20日
  • Hibernate查询方法有哪些

    技术Hibernate查询方法有哪些小编给大家分享一下Hibernate查询方法有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!1: QB

    攻略 2021年12月8日
  • 怎么在启动Jupyter Notebook时自动执行一段代码

    技术怎么在启动Jupyter Notebook时自动执行一段代码本篇内容主要讲解“怎么在启动Jupyter Notebook时自动执行一段代码”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编

    攻略 2021年10月26日
  • ADO.NET SqlConnection怎么使用

    技术ADO.NET SqlConnection怎么使用这篇文章主要讲解了“ADO.NET SqlConnection怎么使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“

    攻略 2021年12月3日
  • Java8新特性-日期时间

    技术Java8新特性-日期时间 Java8新特性-日期时间1.背景Java 8通过发布新的Date-Time API (JSR 310)来进一步加强对日期与时间的处理。在旧版的 Java 中,日期时间

    礼包 2021年10月27日