zoukankan      html  css  js  c++  java
  • Script:partition table into rowid extent chunks

    以下脚本可以用于将表按照rowid范围分区,获得指定数目的rowid Extent区间(Group sets of rows in the table into smaller chunks), 以便于非分区表利用rowid来实现并行删除或更新:  
    REM  rowid_ranges should be at least 21
    REM  utilize this script help delete large table
    REM  if update large table  Why not online redefinition or CTAS
    -- This script spits desired number of rowid ranges to be used for any parallel operations.
    -- Best to use it for copying a huge table with out of row lob columns in it or CTAS/copy the data over db links.
    -- This can also be used to simulate parallel insert/update/delete operations.
    -- Maximum number of rowid ranges you can get here is 255.
    -- Doesn't work for partitioned tables, but with minor changes it can be adopted easily.
    
    -- Doesn't display any output if the total table blocks are less than rowid ranges times 128.
    
    -- It can split a table into more ranges than the number of extents
    From Saibabu Devabhaktuni  http://sai-oracle.blogspot.com/2006/03/how-to-split-table-into-rowid-ranges.html
    
    
    
    set verify off
    undefine rowid_ranges
    undefine segment_name
    undefine owner
    set head off
    set pages 0
    set trimspool on
    
    select 'where rowid between ''' ||sys.dbms_rowid.rowid_create(1, d.oid, c.fid1, c.bid1, 0) ||''' and ''' ||sys.dbms_rowid.rowid_create(1, d.oid, c.fid2, c.bid2, 9999) || '''' ||';'
      from (select distinct b.rn,
                            first_value(a.fid) over(partition by b.rn order by a.fid, a.bid rows between unbounded preceding and unbounded following) fid1,
                            last_value(a.fid) over(partition by b.rn order by a.fid, a.bid rows between unbounded preceding and unbounded following) fid2,
                            first_value(decode(sign(range2 - range1),
                                               1,
                                               a.bid +
                                               ((b.rn - a.range1) * a.chunks1),
                                               a.bid)) over(partition by b.rn order by a.fid, a.bid rows between unbounded preceding and unbounded following) bid1,
                            last_value(decode(sign(range2 - range1),
                                              1,
                                              a.bid +
                                              ((b.rn - a.range1 + 1) * a.chunks1) - 1,
                                              (a.bid + a.blocks - 1))) over(partition by b.rn order by a.fid, a.bid rows between unbounded preceding and unbounded following) bid2
              from (select fid,
                           bid,
                           blocks,
                           chunks1,
                           trunc((sum2 - blocks + 1 - 0.1) / chunks1) range1,
                           trunc((sum2 - 0.1) / chunks1) range2
                      from (select /*+ rule */
                             relative_fno fid,
                             block_id bid,
                             blocks,
                             sum(blocks) over() sum1,
                             trunc((sum(blocks) over()) / &&rowid_ranges) chunks1,
                             sum(blocks) over(order by relative_fno, block_id) sum2
                              from dba_extents
                             where segment_name = upper('&&segment_name')
                               and owner = upper('&&owner'))
                     where sum1 > &&rowid_ranges) a,
                   (select rownum - 1 rn
                      from dual
                    connect by level <= &&rowid_ranges) b
             where b.rn between a.range1 and a.range2) c,
           (select max(data_object_id) oid
              from dba_objects
             where object_name = upper('&&segment_name')
               and owner = upper('&&owner')
               and data_object_id is not null) d
               /
  • 相关阅读:
    SQL Server 灾难恢复31天之第3天:在还原数据库时确定需要哪些备份文件
    发布订阅延迟故障排查案例:分发读进程延迟
    [分享]系统crash后SQL Server 在recovery时的rollback机制
    统计信息对执行计划的影响
    [荐][转]SQL SERVER SQLOS的任务调度
    SQL Server 灾难恢复31天之第1天:DBCC CHECK命令会自动使用已经存在的数据库快照吗?
    日志文件如何影响我数据库的启动
    SQL Server 2012 正式发布
    SQL Server 灾难恢复31天之第6天:管理区分配页损坏处理
    [转]Working Set和Private Bytes
  • 原文地址:https://www.cnblogs.com/macleanoracle/p/2967634.html
Copyright © 2011-2022 走看看