返回顶部
首页 > 资讯 > 数据库 >数据库中plan_hash_value有什么用
  • 577
分享到

数据库中plan_hash_value有什么用

2024-04-02 19:04:59 577人浏览 泡泡鱼
摘要

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

这篇文章给大家分享的是有关数据库中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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C
                                                         2),0) FROM (SELECT 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 NVL(SUM(C1),0), NVL(SUM(C2),0), NVL(SUM(C3),0
                                                         ) FROM (SELECT 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有什么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

您可能感兴趣的文档:

--结束END--

本文标题: 数据库中plan_hash_value有什么用

本文链接: https://lsjlt.com/news/69855.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • 数据库中plan_hash_value有什么用
    这篇文章给大家分享的是有关数据库中plan_hash_value有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。 plan_hash_value...
    99+
    2024-04-02
  • 数据库有什么用
    数据库的作用用户可以通过接口使用数据库,并提供数据共享。减少数据的冗余度。对数据进行了集中管理。数据一致性和可维护性,以确保数据的安全性和可靠性。数据库管理系统可及时发现故障和修复故障。...
    99+
    2024-04-02
  • openstack中neutron数据库有什么用
    这篇文章主要介绍openstack中neutron数据库有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!一.Neutron 数据库的整体架构图Neutron Database采...
    99+
    2024-04-02
  • 数据库中索引有什么用
    这篇文章主要介绍数据库中索引有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!数据库索引的最大作用就是加快查询速度,它能从根本上减少需要扫表的记录行的数量,数据库索引就是数据库的...
    99+
    2024-04-02
  • 数据库中NESTED_TABLE_SET_REFS hint有什么用
    这篇文章将为大家详细讲解有关数据库中NESTED_TABLE_SET_REFS hint有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 ...
    99+
    2024-04-02
  • 数据库中有什么数据类型
    小编给大家分享一下数据库中有什么数据类型,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!数据库的常用数据类型有哪些?一、 整数数据类型:整数数据类型是最常用的数据类型之一。  1、...
    99+
    2024-04-02
  • 数据库中触发器有什么用
    这篇文章主要介绍了数据库中触发器有什么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。触发器有两个稳态,可分别表示二进制数码0和1,无外触发...
    99+
    2024-04-02
  • 数据库中dbwr、lgwr、ckpt有什么用
    这篇文章将为大家详细讲解有关数据库中dbwr、lgwr、ckpt有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 dbwr:1、当di...
    99+
    2024-04-02
  • MySQL数据库中索引有什么用
    这篇文章将为大家详细讲解有关MySQL数据库中索引有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、MySQL索引简介索引是MySQL数据库为了加快数据查询的速度,给表中的某一个或者是某几个列添加...
    99+
    2023-06-22
  • VB.NET数据库中DataAdapter类有什么用
    这篇文章主要介绍VB.NET数据库中DataAdapter类有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!DataAdapter类DataAdapter是数据提供程序的一个子组件。与Connection和Co...
    99+
    2023-06-17
  • mongoDB数据库有什么用
    这篇文章主要介绍了mongoDB数据库有什么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。作为一名程序员,我相信大家都要接触数据库,对于m...
    99+
    2024-04-02
  • circNet数据库有什么用
    这篇文章给大家分享的是有关circNet数据库有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。欢迎关注”生信修炼手册”!circNet是一个环状RNA的数据库,不仅收录了cirRNA的基本信息,还提供了环状...
    99+
    2023-06-19
  • plantcircbase数据库有什么用
    这篇文章将为大家详细讲解有关plantcircbase数据库有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。plantcircBase是一个植物环状RNA的数据库,网址如下http://ibi.zj...
    99+
    2023-06-19
  • circinteractome数据库有什么用
    这篇文章将为大家详细讲解有关circinteractome数据库有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。RNA binding protein, 简称RBP,称之为RNA结合蛋白,是一类调控...
    99+
    2023-06-19
  • PlantCircNet数据库有什么用
    这篇文章主要介绍PlantCircNet数据库有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!PlantCircNet数据库提供了植物相关的circRNA-miRNA-gene构成的ceRNA调控网络信息,网址...
    99+
    2023-06-19
  • circad数据库有什么用
    这篇文章给大家分享的是有关circad数据库有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。环状RNA具有重要的转录调控功能,越来越多的研究表明,环状RNA在许多疾病的发生与发展中扮演重要角色,circad...
    99+
    2023-06-19
  • circ2Traits数据库有什么用
    这篇文章主要为大家展示了“circ2Traits数据库有什么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“circ2Traits数据库有什么用”这篇文章吧。miRNA的研究起步很早,miRNA...
    99+
    2023-06-19
  • SomamiR数据库有什么用
    这篇文章主要介绍了SomamiR数据库有什么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。miRNA可以与多找RNA分子进行结合,从而在ceRNA调控网络中发挥重要作用。c...
    99+
    2023-06-19
  • mysql数据库有什么用
    mysql 数据库是一种关系型数据库管理系统,用于存储和管理数据,在以下应用中发挥关键作用:数据存储和管理数据处理业务应用程序网站和在线服务分析和报告数据安全高度可用性和可扩展性 My...
    99+
    2024-04-05
    mysql
  • 数据库索引有什么用
    这篇文章将为大家详细讲解有关数据库索引有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。数据库索引的作用是:可以快速访问数据库表中的特定信息。索引能提高数据的搜索及检...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作