Row Chaining and Row Migration

Row Chaining and Row Migration
行鏈接和行遷移

Introduction
------------
介紹

This article discusses the difference between row chaining andmigration.
Guidelines are given on how to detect and resolve from thissituation.
本文主要討論行鏈接和行遷移直接的不同。指導怎麼發現和解決行鏈接和行遷移。

Concepts
--------
概念

There are two circumstances when this can occur, the data for a rowin a table
may be too large to fit into a single data block. 
This can be caused by either
row chaining or row migration.

Chaining
---------
行鏈接

Occurs when the row is too large to fit into one data block when itis first
inserted. In this case, Oracle stores the data for the row in achain of data
blocks (one or more) reserved for that segment. Row chaining mostoften occurs
with large rows, such as rows that contain a column of datatypeLONG, LONG RAW,
LOB, etc. Row chaining in these cases is unavoidable.
行鏈接產生在第一次插入數據時,如果一個block不能存放一行記錄的情況下。在這種情況下Oracle將使用鏈 接一個或者多個在這個段中保留的block存儲這一行記錄。行鏈接容易出現在大行上,比如包含LONG, LONG RAW,
LOB等字段類型的行,行鏈接是不可能避免的。

Migration
----------
行遷移

Occurs when a row that originally fitted into one data block isupdated so
that the overall row length increases, and the block's free spaceis already
completely filled.  In this case, Oracle migratesthe data for the entire row
to a new data block, assuming the entire row can fit in a newblock.  Oracle
preserves the original row piece of a migrated row to point to thenew block
containing the migrated row: the rowid of a migrated row does notchange.
原來存放到一個block的行被更新,導致行的長度增加,而block的預留空間已使用完,這種情況下,oracle將整行數據遷移到一個新的block,oracle會保留被遷移的行的原始指針指向新的存放行數據的block,被遷移行的rowid不改變。

When a row is chained or migrated, performance associated with thisrow
decreases because Oracle must scan more than one data block toretrieve the
information for that row.
當一行發生鏈接或遷移,和這行有關的性能會下降,因爲oracle如果取這行數據,必須掃描不止一個block。

o INSERT and UPDATE statements that cause migration and chainingperform poorly,
  because they perform additionalprocessing.
  產生行遷移和行鏈接的insert和update執行效率低。

o SELECTs that use an index to select migrated or chained rows mustperform
  additional I/Os.
  使用index的select查詢遷移或者鏈接的行必須執行額外的I/O。
 

Detection
---------
檢查

Migrated and chained rows in a table or cluster can be identifiedby using the
ANALYZE command with the LIST CHAINED ROWS option. This commandcollects
information about each migrated or chained row and places thisinformation into
a specified output table.  To create the tablethat holds the chained rows,
execute script UTLCHAIN.SQL.
使用帶LIST CHAINEDROWS的ANALYZE命令,可以發現一個表或簇中遷移和鏈接的行。這個命令蒐集關於遷移和鏈接的行的信息,並將信息記錄到指定的表。執行UTLCHAIN.SQL創建記錄遷移的行的表。

  SQL> ANALYZE TABLE scott.emp LIST CHAINEDROWS;
  SQL> SELECT * FROM chained_rows;
 
You can also detect migrated and chained rows by checking the
'table fetch continued row' statistic in the v$sysstat view.
通過v$sysstat的'table fetch continued row'也可以檢查遷移和鏈接的行。

  SQL> SELECT name, value FROM v$sysstat WHEREname = 'table fetch continued row';
 
 NAME                                                                VALUE
 -------------------------------------------------------------------------
  table fetch continuedrow                                             308

Although migration and chaining are two different things,internally they are
represented by Oracle as one.  When detectingmigration and chaining of rows
you should analyze carrefully what you are dealing with.
儘管行遷移和行鏈接兩個是不同的,但是oracle內部把它作爲一個來對待。當發現行遷移和行鏈接,你需要仔細分析你處理的是行遷移還是行鏈接。

Resolving
---------
解決

o In most cases chaining is unavoidable, especially when thisinvolves tables
  with large columns such as LONGS, LOBs,etc.  When you have a lot of chained
  rows in different tables and the average rowlength of these tables is not
  that large, then you might consider rebuildingthe database with a larger
  blocksize.
  多數情況下,行鏈接是無法避免的,尤其當牽扯的表包含LONGS,LOBs等列。如果在不同的表中有大連的鏈接行,並且這些的表的行平均長度不是太大,那可能需要考慮使用較大的blocksize重建blocksize。
 
  e.g.: You have a database with a 2K block size.Different tables have multiple
       large varchar columns with an average row length of more than2K.  Then this
       means that you will have a lot of chained rows because your blocksize is
       too small.  Rebuilding the database with a largerblock size can give you
       a significant performance benefit.
       
o Migration is caused by PCTFREE being set too low, there is notenough room in
  the block for updates.  Toavoid migration, all tables that are updated should
  have their PCTFREE set so that there is enoughspace within the block for updates.
  You need to increase PCTFREE to avoid migratedrows.  If you leave more free
  space available in the block for updates, thenthe row will have more room to
  grow.
 PCTFREE設置的太低,會導致行遷移,因爲block沒有爲update留下充足的空間。爲了避免行遷移,被update的表應該有可以滿足update的PCTFREE設置。
 
 
  SQL Script to eliminate row migration :
  消除行遷移的sql腳本:
 
    -- Get thename of the table with migrated rows:
    ACCEPTtable_name PROMPT 'Enter the name of the table with migrated rows:'
 
    -- Clean upfrom last execution
    set echooff
    DROP TABLEmigrated_rows;
    DROP TABLEchained_rows;
 
    -- Createthe CHAINED_ROWS table
   @$ORACLE_HOME/rdbms/admin/utlchain.sql
    set echoon
    spoolfix_mig
    -- List thechained and migrated rows
    ANALYZETABLE &table_name LIST CHAINED ROWS;
   
    -- Copy thechained/migrated rows to another table
    create tablemigrated_rows as
     SELECT orig.*
     FROM &table_name orig, chained_rows cr
     WHERE orig.rowid = cr.head_rowid
      
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章