• <ul id="mayc0"></ul>
    <ul id="mayc0"><center id="mayc0"></center></ul>
    <strike id="mayc0"><input id="mayc0"></input></strike>
    <ul id="mayc0"></ul>
  • 始創(chuàng)于2000年 股票代碼:831685
    咨詢(xún)熱線(xiàn):0371-60135900 注冊(cè)有禮 登錄
    • 掛牌上市企業(yè)
    • 60秒人工響應(yīng)
    • 99.99%連通率
    • 7*24h人工
    • 故障100倍補(bǔ)償
    全部產(chǎn)品
    您的位置: 網(wǎng)站首頁(yè) > 幫助中心>文章內(nèi)容

    Oracle教程:select 操作產(chǎn)生的 redo

    發(fā)布時(shí)間:  2012/8/26 16:06:44

    數(shù)據(jù)庫(kù)版本:
    Oracle Database 10g Enterprise Edition Release 10.1.0.3.0


    創(chuàng)建測(cè)試表:
    SQL> create table a  as select * from all_objects  ;
    Table created.
    -
     


    SQL> set autotrace on statistics ;

    插入數(shù)據(jù)(hint。幔穑穑澹睿洌

    SQL> insert /*+ append */ into a select * from all_objects ;
    9891 rows created.

    Statistics
    ----------------------------------------------------------
            302  recursive calls
            137  db block gets
           6040  consistent gets
              0  physical reads
        1055332  redo size
            627  bytes sent via SQL*Net to client
            558  bytes received via SQL*Net from client
              3  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
           9891  rows processed
    SQL> commit ;
    Commit complete.

    第一次查詢(xún)數(shù)據(jù):
    SQL> select count(*) from a ;
      COUNT(*)
    ----------
         19782

    Statistics
    ----------------------------------------------------------
              0  recursive calls
              1  db block gets
            255  consistent gets
            248  physical reads
      168  redo size    --------------------------------->。??產(chǎn)生redo???
            395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed


    第二次查詢(xún):

    SQL> select count(*) from a ;
      COUNT(*)
    ----------
         19782

    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
            252  consistent gets
              1  physical reads
        0 redo size      
            395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed


    =================================================
    如上所示,為什么在查詢(xún)的時(shí)候會(huì)產(chǎn)生 redo ? 產(chǎn)生的redo 到底是做什么的?
    =================================================
    ----

    取消 hint append 插入數(shù)據(jù),第一次查詢(xún)不會(huì)產(chǎn)生redo

    SQL> insert into a select * from a ;

    19782 rows created.


    Statistics
    ----------------------------------------------------------
            112  recursive calls
          21100  db block gets
            699  consistent gets
              0  physical reads
        7149196  redo size
            642  bytes sent via SQL*Net to client
            534  bytes received via SQL*Net from client
              3  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
          19782  rows processed

    SQL>
    SQL>
    SQL> select count(*) from a ;

      COUNT(*)
    ----------
         39564


    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
            502  consistent gets
              0  physical reads
              0  redo size
            395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    ---------------------------------------------------

    對(duì)表做了truncate 操作后,第一次查詢(xún)也出現(xiàn) redo

    SQL> truncate table a ;

    Table truncated.

    SQL>
    SQL> select count(*) from a;

      COUNT(*)
    ----------
             0


    Statistics
    ----------------------------------------------------------
              1  recursive calls
              1  db block gets
              6  consistent gets
              0  physical reads
           96  redo size
            392  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed

    SQL>

    ----------------
    簡(jiǎn)單的說(shuō),在Oracle的block上都有活動(dòng)事務(wù)的標(biāo)志的,如果一個(gè)事務(wù)commit后,由于某些block在commit之前已經(jīng)寫(xiě)回datafile, 或者事務(wù)影響到的block數(shù)過(guò)多,則commi的時(shí)候只會(huì)清理undo segment header中的事務(wù)表信息,data block上的事務(wù)標(biāo)志不會(huì)清除,否則代價(jià)過(guò)高。那么在一些讀取這些block時(shí),需要將這些事務(wù)標(biāo)志進(jìn)行清除,就是延遲塊清除
    -------------------------
    這個(gè)在用append引語(yǔ)的時(shí)候才會(huì)產(chǎn)生select的redo日志,說(shuō)明在提交前已經(jīng)把數(shù)據(jù)塊給寫(xiě)了,也進(jìn)一步說(shuō)明了直插的模式,就是不走緩存,直接寫(xiě)數(shù)據(jù)塊和回滾快。滿(mǎn)足延遲塊清除的第一個(gè)條件,就是還沒(méi)提交,數(shù)據(jù)已經(jīng)寫(xiě)了。
    ---------------------------
    ====================================
    在做個(gè)測(cè)試如下:
    ====================================

    SQL> insert into a
      2  select * from a ;

    129103 rows created.


    Statistics
    ----------------------------------------------------------
            489  recursive calls
         137442  db block gets
           4058  consistent gets
           1516  physical reads
       46645744  redo size
            643  bytes sent via SQL*Net to client
            534  bytes received via SQL*Net from client
              3  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
         129103  rows processed

    SQL> alter system checkpoint ;

    System altered.

    SQL>
    SQL> select count(*) from a ;

      COUNT(*)
    ----------
        258206


    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
           3241  consistent gets
           2790  physical reads
              0  redo size
            395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed

    SQL> commit ;

    Commit complete.

    SQL> select count(*) from a ;

      COUNT(*)
    ----------
        258206


    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
           4857  consistent gets
           2796  physical reads
          116484  redo size ------------------------------------> 第一次查詢(xún)r(jià)edo產(chǎn)生 (延遲塊清除)
            395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed

    SQL> select count(*) from a ;

      COUNT(*)
    ----------
        258206


    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
           3241  consistent gets
           2746  physical reads
              0  redo size       
           395  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed

    SQL>

    -------------------
    說(shuō)白了就是數(shù)據(jù)塊上的信息在前面還沒(méi)來(lái)得及清理,select來(lái)幫它清理一下,既然select對(duì)數(shù)據(jù)塊做了操作了,自然就要寫(xiě)redo了。
     


    本文出自:億恩科技【www.vbseamall.com】

    服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營(yíng)性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營(yíng)性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營(yíng)性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話(huà):0371-60135900
  • 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話(huà):0371-60135900
  • 專(zhuān)注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號(hào)
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問(wèn):河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
      0
     
     
     
     

    0371-60135900
    7*24小時(shí)客服服務(wù)熱線(xiàn)