ITPub博客

首页 > 数据库 > Oracle > 偶然的实验,查询两条记录的全表很久,10046真好用...

偶然的实验,查询两条记录的全表很久,10046真好用...

原创 Oracle 作者:PiscesCanon 时间:2017-11-06 17:37:16 0 删除 编辑
操作系统版本:
  1. [oracle@oracle trace]$ uname -a
  2. Linux oracle.example.com 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
  3. [oracle@oracle trace]$ lsb_release -a
  4. LSB Version:     :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
  5. Distributor ID: RedHatEnterpriseServer
  6. Description:    Red Hat Enterprise Linux Server release 6.5 (Santiago)
  7. Release:        6.5
  8. Codename:       Santiago

数据库版本:
  1. SYS@proc> select * from v$version where rownum=1;

  2. BANNER
  3. --------------------------------------------------------------------------------
  4. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

查询现象:
  1. ZKM@proc> select count(*) from t;

  2.   COUNT(*)
  3. ----------
  4.          2

  5. Elapsed: 00:00:20.66

实验过程:

  1. ZKM@proc> create table t(id int);

  2. Table created.

  3. ZKM@proc> insert into t values(1);

  4. 1 row created.

  5. ZKM@proc> c/1/2
  6.   1* insert into t values(2)
  7. ZKM@proc> /

  8. 1 row created.

  9. ZKM@proc> commit;

  10. Commit complete.

  11. ZKM@proc> select * from t;

  12.         ID
  13. ----------
  14.          1
  15.          2

  16. ZKM@proc> select bytes from dba_segments where segment_name='T' and owner='ZKM';

  17.      BYTES
  18. ----------
  19.      65536

  20. ZKM@proc> set timing on
  21. ZKM@proc> begin
  22.             for i in 1..100000 loop
  23.                 insert into t select * from t;
  24.             end loop;
  25.             commit;
  26.             end;
  27.             /
  28. ^C
  29. *
  30. ERROR at line 1:
  31. ORA-01013: user requested cancel of current operation
  32. ORA-06512: at line 3


  33. Elapsed: 00:18:15.08
  34. ZKM@proc> select count(*) from t;

  35.   COUNT(*)
  36. ----------
  37.          2

  38. Elapsed: 00:00:20.66
一开始还以为Ctrl+c中断后,记录应该是超过两条的,没想到中断会回滚。
做了下10046,以下截取一部分。

  1. ...
  2. WAIT #140653717427600: nam='SQL*Net message to client' ela= 2 driver id=1650815232 #bytes=1 p3=0 obj#=88856 tim=1509951777507463
  3. WAIT #140653717427600: nam='direct path read' ela= 191 file number=4 first dba=561 block cnt=15 obj#=88856 tim=1509951777507731
  4. WAIT #140653717427600: nam='direct path read' ela= 37 file number=4 first dba=577 block cnt=15 obj#=88856 tim=1509951777507869
  5. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=593 block cnt=15 obj#=88856 tim=1509951777507979
  6. WAIT #140653717427600: nam='direct path read' ela= 37 file number=4 first dba=609 block cnt=15 obj#=88856 tim=1509951777508083
  7. WAIT #140653717427600: nam='direct path read' ela= 43 file number=4 first dba=625 block cnt=15 obj#=88856 tim=1509951777508300
  8. WAIT #140653717427600: nam='direct path read' ela= 39 file number=4 first dba=641 block cnt=15 obj#=88856 tim=1509951777508435
  9. WAIT #140653717427600: nam='direct path read' ela= 126 file number=4 first dba=770 block cnt=14 obj#=88856 tim=1509951777508630
  10. WAIT #140653717427600: nam='direct path read' ela= 183 file number=4 first dba=784 block cnt=16 obj#=88856 tim=1509951777508886
  11. WAIT #140653717427600: nam='direct path read' ela= 287 file number=4 first dba=800 block cnt=16 obj#=88856 tim=1509951777509248
  12. WAIT #140653717427600: nam='direct path read' ela= 153 file number=4 first dba=816 block cnt=16 obj#=88856 tim=1509951777509512
  13. WAIT #140653717427600: nam='direct path read' ela= 145 file number=4 first dba=832 block cnt=16 obj#=88856 tim=1509951777509738
  14. WAIT #140653717427600: nam='direct path read' ela= 121 file number=4 first dba=848 block cnt=16 obj#=88856 tim=1509951777509935
  15. WAIT #140653717427600: nam='direct path read' ela= 41 file number=4 first dba=864 block cnt=16 obj#=88856 tim=1509951777510055
  16. WAIT #140653717427600: nam='direct path read' ela= 263 file number=4 first dba=880 block cnt=16 obj#=88856 tim=1509951777510389
  17. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=898 block cnt=14 obj#=88856 tim=1509951777510526
  18. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=912 block cnt=16 obj#=88856 tim=1509951777510637
  19. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=928 block cnt=16 obj#=88856 tim=1509951777510740
  20. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=944 block cnt=16 obj#=88856 tim=1509951777510849
  21. WAIT #140653717427600: nam='direct path read' ela= 39 file number=4 first dba=960 block cnt=16 obj#=88856 tim=1509951777510959
  22. WAIT #140653717427600: nam='direct path read' ela= 40 file number=4 first dba=976 block cnt=16 obj#=88856 tim=1509951777511070
  23. WAIT #140653717427600: nam='direct path read' ela= 44 file number=4 first dba=992 block cnt=16 obj#=88856 tim=1509951777511235
  24. WAIT #140653717427600: nam='direct path read' ela= 38 file number=4 first dba=1008 block cnt=16 obj#=88856 tim=1509951777511354
  25. WAIT #140653717427600: nam='direct path read' ela= 33 file number=4 first dba=1026 block cnt=14 obj#=88856 tim=1509951777511460
  26. WAIT #140653717427600: nam='direct path read' ela= 37 file number=4 first dba=1040 block cnt=16 obj#=88856 tim=1509951777511567
  27. WAIT #140653717427600: nam='direct path read' ela= 37 file number=4 first dba=1056 block cnt=16 obj#=88856 tim=1509951777511668
  28. WAIT #140653717427600: nam='direct path read' ela= 35 file number=4 first dba=1072 block cnt=16 obj#=88856 tim=1509951777511775
  29. ....
  1. ZKM@proc> select bytes,bytes/1024/1024 M from dba_segments where segment_name='T' and owner='ZKM';

  2.      BYTES          M
  3. ---------- ----------
  4. 1214251008       1158
看来原因是高水位线被提高了。
如何验证高水位线被抬高了呢?可以查询dba_extents视图,但是该方法不清楚高水位线在哪里。
以下是查找高水位线过程。

  1. SYS@proc> select HEADER_FILE,HEADER_BLOCK from dba_segments where owner='ZKM' and segment_name='T'; --L3块地址

  2. HEADER_FILE HEADER_BLOCK
  3. ----------- ------------
  4.           4          530

  5. Elapsed: 00:00:00.12
  6. SYS@proc> alter system dump datafile 4 block 530;

  7. System altered.

  8. Elapsed: 00:00:00.22

  9. SYS@proc> select value from v$diag_info where name like '%De%';

  10. VALUE
  11. ----------------------------------------------------------------------
  12. /u01/app/oracle/diag/rdbms/proc_stb/proc/trace/proc_ora_3974.trc

  13. Elapsed: 00:00:00.22
截取部分proc_ora_3974.trc文件内容。
  1. Extent Control Header
  2.   -----------------------------------------------------------------
  3.   Extent Header:: spare1: 0 spare2: 0 #extents: 202 #blocks: 148224
  4.                   last map 0x00000000 #maps: 0 offset: 2716
  5.       Highwater:: 0x01024580 ext#: 201 blk#: 8192 ext size: 8192
  6.   #blocks in seg. hdr
其中,Highwater即是高水位线。
  1. SYS@proc> select to_number('01024580','xxxxxxxx') from dual;

  2. TO_NUMBER('01024580','XXXXXXXX')
  3. --------------------------------
  4.                         16926080

  5. Elapsed: 00:00:00.02
  6. SYS@proc> select dbms_utility.data_block_address_file(16926080) from dual;

  7. DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(16926080)
  8. ----------------------------------------------
  9.                                              4

  10. Elapsed: 00:00:00.27
  11. SYS@proc> select dbms_utility.data_block_address_block(16926080) from dual;

  12. DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(16926080)
  13. -----------------------------------------------
  14.                                          148864

  15. Elapsed: 00:00:00.00
由此得到高水位线的地址是4号文件的148864号块。一般这里可以猜测表最新的区最后块的地址为4,148863。
验证以下。
  1. SYS@proc> select * from (select EXTENT_ID,FILE_ID,BLOCK_ID,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='T' order by 1 desc) where rownum=1;

  2.  EXTENT_ID    FILE_ID   BLOCK_ID     BLOCKS
  3. ---------- ---------- ---------- ----------
  4.        201          4     140672       8192
140672+8192-1=148863刚好是这样。







来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30174570/viewspace-2146898/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-03-23

  • 博文量
    29
  • 访问量
    57487