Friday, September 20, 2013

Listing Chained Rows of Tables - Oracle Row chaining



Creating a CHAINED_ROWS Table

@$ORACLE_HOME/rdbms/admin/utlchain.sql

Eliminating Migrated or Chained Rows in a Table

You can use the information in the CHAINED_ROWS table to reduce or eliminate migrated and chained rows in an existing table. Use the following procedure.
  1. Use the ANALYZE statement to collect information about migrated and chained rows.
    ANALYZE TABLE order_hist LIST CHAINED ROWS;
    
  2. Query the output table:
    SELECT *
    FROM CHAINED_ROWS
    WHERE TABLE_NAME = 'ORDER_HIST';
    
    OWNER_NAME  TABLE_NAME  CLUST... HEAD_ROWID          TIMESTAMP
    ----------  ----------  -----... ------------------  ---------
    SCOTT       ORDER_HIST       ... AAAAluAAHAAAAA1AAA  04-MAR-96
    SCOTT       ORDER_HIST       ... AAAAluAAHAAAAA1AAB  04-MAR-96
    SCOTT       ORDER_HIST       ... AAAAluAAHAAAAA1AAC  04-MAR-96
    
    The output lists all rows that are either migrated or chained.
  3. If the output table shows that you have many migrated or chained rows, then you can eliminate migrated rows by continuing through the following steps:
  4. Create an intermediate table with the same columns as the existing table to hold the migrated and chained rows:
    CREATE TABLE int_order_hist
       AS SELECT *
          FROM order_hist
          WHERE ROWID IN
             (SELECT HEAD_ROWID
                FROM CHAINED_ROWS
                WHERE TABLE_NAME = 'ORDER_HIST');
    
  5. Delete the migrated and chained rows from the existing table:
    DELETE FROM order_hist
       WHERE ROWID IN
          (SELECT HEAD_ROWID
             FROM CHAINED_ROWS
             WHERE TABLE_NAME = 'ORDER_HIST');
    
  6. Insert the rows of the intermediate table into the existing table:
    INSERT INTO order_hist
       SELECT *
       FROM int_order_hist;
    
  7. Drop the intermediate table:
    DROP TABLE int_order_history;
    
  8. Delete the information collected in step 1 from the output table:
    DELETE FROM CHAINED_ROWS
       WHERE TABLE_NAME = 'ORDER_HIST';
    
  9. Use the ANALYZE statement again, and query the output table.
Any rows that appear in the output table are chained. You can eliminate chained rows only by increasing your data block size. It might not be possible to avoid chaining in all situations. Chaining is often unavoidable with tables that have a LONG column or large CHAR or VARCHAR2 columns.

No comments: