[20180914]oracle 12c 表 full_hash_value如何计算.txt

[20180914]oracle 12c 表 full_hash_value如何计算.txt

–//昨天在12c下看表full_hash_value与11g的full_hash_value不同,不过12c使用pdb,猜测跟pdb有关.
–//通过测试说明问题.

1.环境:
scott@book> @ &r/ver1
port_string                    version        banner
—————————— ————– ——————————————————————————–
x86_64/linux 2.4.xx            11.2.0.4.0     oracle database 11g enterprise edition release 11.2.0.4.0 – 64bit production

scott@book> select owner,name,namespace,type,hash_value,full_hash_value from v$db_object_cache where owner=’scott’ and name=’emp’;
owner  name namespace       type  hash_value full_hash_value
—— —- ————— —– ———- ——————————–
scott  emp  table/procedure table 3800164305 684ea11e3eab602b778e1dd1e281e7d1

–//以上11g的结果.
$ echo -e -n “emp.scott\01\0\0\0” | md5sum |sed ‘s/  -//’ | xxd -r -p | od -t x4 | sed  -n  -e ‘s/^0000000 //’ -e ‘s/ //gp’
684ea11e3eab602b778e1dd1e281e7d1

2.而在12c下:

scott@test01p> @ ver1
port_string                    version        banner                                                                               con_id
—————————— ————– ——————————————————————————– ———-
ibmpc/win_nt64-9.1.0           12.1.0.1.0     oracle database 12c enterprise edition release 12.1.0.1.0 – 64bit production              0

scott@test01p> select owner,name,namespace,type,hash_value,full_hash_value,con_id,con_name from v$db_object_cache where owner=’scott’ and name=’emp’;
owner                name                 namespace            type                 hash_value full_hash_value                      con_id con_name
——————– ——————– ——————– ——————– ———- ——————————– ———- ——————–
scott                emp                  table/procedure      table                1676251406 5675b61ea54d0cd0370c43ab63e9910e          3 test01p

–//对比前面可以发现full_hash_value不一样,也很容易猜测12c 的full_hash_value计算加入con_name的内容.
d:\tools\rlwrap>d:\tools\linux\usr\local\wbin\echo -e -n “emp.scott.test01p\01\0\0\0” | md5sum |sed “s/  -//” | d:\tools\vim\vim80\xxd -r -p | od -t x4 | sed  -n  -e “s/^0000000 //” -e “s/ //gp”
5675b61ea54d0cd0370c43ab63e9910e

–//ok,能对上.
–//注:windows要安装unxutil包.echo不能使用windows下的echo.必须使用ubxutil包的echo(该命令支持-n -e参数)
–//sed 命令格式要使用双引号.
–//我个人还使用vim自带的xxd.

–//可以发现12c计算表的full_hash_value是 计算table_name.owner_name.con_name\01\0\0\0的md5sum值.

3.从以上测试可以联想到的问题就是后面都是补”\01\0\0\0″,为什么呢?
–//很容易联想到namespace

sys@test> select distinct kglhdnsp,kglhdnsd,kglobtyd from x$kglob order by 1;
kglhdnsp kglhdnsd                       kglobtyd
——– —————————— ——————-
       0 sql area                       cursor
       1 table/procedure                cursor
       1 table/procedure                function
       1 table/procedure                library
       1 table/procedure                operator
       1 table/procedure                package
       1 table/procedure                procedure
       1 table/procedure                scheduler class
       1 table/procedure                scheduler job
       1 table/procedure                scheduler program
       1 table/procedure                scheduler schedule
       1 table/procedure                scheduler window
       1 table/procedure                sequence
       1 table/procedure                synonym
       1 table/procedure                table
       1 table/procedure                type
       1 table/procedure                view
       2 body                           cursor
       2 body                           package body
       3 trigger                        trigger
       4 index                          index
       5 cluster                        cluster
       5 cluster                        cursor
      10 queue                          queue
      18 pub sub internal information   pub sub internal information
      23 ruleset                        ruleset
      24 resource manager               resource manager consumer group
      24 resource manager               resource manager plan
      28 subscription                   subscription
      38 rule evaluation context        rule evaluation context
      45 multi-version object for table cursor
      45 multi-version object for table multi-versioned object
      48 multi-version object for index cursor
      48 multi-version object for index multi-versioned object
      51 scheduler global attribute     cursor
      51 scheduler global attribute     scheduler global attribute
      52 resource manager cdb           resource manager cdb plan
      64 edition                        edition
      69 dblink                         cursor
      72 object id                      object id
      73 schema                         cursor
      73 schema                         none
      74 dbinstance                     cursor
      75 sql area stats                 cursor stats
      79 account_status                 none
      82 sql area build                 cursor
      88 pdb                            cursor
      88 pdb                            pdb
      93 audit policy                   audit policy
     103 optimizer finding              optimizer finding
     104 optimizer directive owner      cursor
     104 optimizer directive owner      optimizer directive owner
     113 gtt session private stats      cursor
     125 pdboper                        cursor
54 rows selected.

–//比如你就不能建立emp的sequence.
scott@test01p> create sequence emp cache 100;
create sequence emp cache 100
                *
error at line 1:
ora-00955: name is already used by an existing object

4.sql语句的full_hash_value(sql_id)计算还是和以前一样计算 sql文本\0(不包括分号) md5sum值.
–//这样带来一个问题,就是如果不同pdb下的语句如果一样,由于文本内容一样,这样计算的sql_id一样,导致出现大量子光标.

(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐