How to Perform a FAST SPLIT PARTITION Using ALTER TABLE? (Doc ID 1268714.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 10.2.0.3 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Information in this document applies to any platform.

GOAL

The Article:   [ID 378138.1] states:  文章:[ID 378138.1]指出:

According to the documentation:  根据文档

"Fast split partitioning takes advantage of those situations in which a split partition results in all rows being moved to a single partition. If all the rows map into a single partition and if the segment attributes of the old partition and the segment attributes of the partition inheriting all the rows match, then the database simply reuses the old segment and adds an empty segment for the other partition. Another benefit of this is that global indexes do not have to be invalidated and, in certain cases, local index partitions corresponding to the new partitions are also usable."

快速拆分分区利用了以下情况:拆分分区导致所有行都移到单个分区。如果所有行都映射到单个分区,并且旧分区的段属性和分区的段属性 继承所有行匹配的内容,数据库将简单地重用旧段并为另一个分区添加一个空段,这样做的另一个好处是不必使全局索引无效,并且在某些情况下,本地索引分区对应于 新的分区也可以使用。”

Thus, the new partitions should have the same storage configuration as the original partition.  因此,新分区应具有与原始分区相同的存储配置。

This last statement has been the reason for the worked example below.  这最后一个陈述是下面的工作示例的原因。

SOLUTION

NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product. Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.

This has been tested on 10.2.0.5 and 11.2.  这已经在10.2.0.5和11.2上进行了测试。

Logon to sqlplus  

connect rk_mview/pwd

Create the partitioned table to work on.  创建要处理的分区表

drop TABLE test;

CREATE TABLE test
( GPS_GUID RAW(16) DEFAULT (sys_guid()) NOT NULL ENABLE,
DVC_ID NUMBER(12,0) NOT NULL ENABLE,
USR_ID NUMBER(12,0) NOT NULL ENABLE,
ENTRY_UTC TIMESTAMP (6) DEFAULT (SYS_EXTRACT_UTC(SYSTIMESTAMP)) NOT NULL ENABLE,
COVERAGE_STAT_ID NUMBER(12,0) NOT NULL ENABLE,
SPEED FLOAT(126) DEFAULT (0),
DIRECTION FLOAT(126) DEFAULT (0),
ESTIMATED_ACCURACY NUMBER(12,0),
UPDATE_UTC TIMESTAMP (6) DEFAULT (SYS_EXTRACT_UTC(SYSTIMESTAMP)) NOT NULL ENABLE,
LATITUDE FLOAT(126),
LONGITUDE FLOAT(126),
TS_GUID RAW(16),
CLUSTER_ID VARCHAR2(50),
GEOCODE_UTC TIMESTAMP (6),
STREET NVARCHAR2(100),
SUITE VARCHAR2(50),
CITY NVARCHAR2(100),
STATE_PROVINCE NVARCHAR2(100),
POSTAL_CODE NVARCHAR2(20),
COUNTRY NVARCHAR2(100),
CONSTRAINT PK_GPS PRIMARY KEY (GPS_GUID)
USING INDEX PCTFREE 5 INITRANS 10 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 1M NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE users ENABLE
) PCTFREE 30 PCTUSED 0 INITRANS 10 MAXTRANS 255
STORAGE(BUFFER_POOL DEFAULT)
TABLESPACE users
PARTITION BY RANGE (ENTRY_UTC)
(PARTITION GPS_DATA_2010_08_08 VALUES LESS THAN (TIMESTAMP'2010-08-08 00:00:00')
PCTFREE 5 PCTUSED 0 INITRANS 10 MAXTRANS 255
STORAGE(INITIAL 1M NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE users NOCOMPRESS ,
PARTITION GPS_DATA_2010_08_15 VALUES LESS THAN (TIMESTAMP'2010-08-15 00:00:00')
PCTFREE 5 PCTUSED 0 INITRANS 10 MAXTRANS 255
STORAGE(INITIAL 1M NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE users NOCOMPRESS ,
PARTITION GPS_DATA_MAX VALUES LESS THAN (MAXVALUE)
PCTFREE 5 PCTUSED 0 INITRANS 10 MAXTRANS 255
STORAGE(INITIAL 1M NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE users NOCOMPRESS ) ENABLE ROW MOVEMENT;

insert into test values ('2',2,2,TIMESTAMP'2010-11-14 00:00:00',1,1,1,1,TIMESTAMP'2010-11-14 00:00:00',1,1,'1','1',TIMESTAMP'2010-11-14 00:00:00','1','1','1','1','1','1');
commit;

BEGIN
DBMS_STATS.gather_table_stats ('schema name',
'test',
partname => 'GPS_DATA_MAX',
granularity => 'PARTITION',
estimate_percent => 3,
DEGREE => 2 );
END;
/

In the above situation we can see that the row inserted has been added to the MAX partition, due to missing partitions.  Therefore to provide further partitions to avoid the use of the MAX partition we will need to add a partition immediately before this MAX partition.  We can use the SPLIT PARTITION syntax and this will actually perform a FAST SPLIT if all the data ends up in only one of the partitions.

在上述情况下,我们可以看到由于缺少分区,因此插入的行已添加到MAX分区中。 因此,为了提供更多的分区以避免使用MAX分区,我们需要在此MAX分区之前立即添加一个分区。 我们可以使用SPLIT PARTITION语法,并且如果所有数据最终仅位于一个分区中,则这实际上将执行FAST SPLIT。

Gather Statistics on the MAX partition to review the num_rows and to ensure a FAST SPLIT optimization occurs.
--收集MAX分区上的统计信息以查看num_rows并确保进行FAST SPLIT优化。
BEGIN
DBMS_STATS.gather_table_stats ('schema name',
'test',
partname => 'GPS_DATA_MAX',
granularity => 'PARTITION',
estimate_percent => 3,
DEGREE => 2 );
END;
/
 
Select Queries utilized to validate the split has occurred:
--选择用于验证拆分的查询:
select FILE_ID,EXTENT_ID,BLOCK_ID from dba_extents where PARTITION_NAME='GPS_DATA_MAX';
select table_name,PARTITION_NAME, num_rows from dba_tab_partitions where table_name='TEST';

Now to run the actual split:  现在运行实际拆分:
Note.  Normally this will create 2 partitions and then move the data to each based on the partition boundaries.  For a FAST SPLIT this will add a new partition and leave the data in the partition where the data fits. 注意。 通常,这将创建2个分区,然后根据分区边界将数据移至每个分区。 对于FAST SPLIT,这将添加一个新分区,并将数据保留在数据适合的分区中。

ALTER TABLE test SPLIT PARTITION
GPS_DATA_MAX AT ((TIMESTAMP'2010-11-28 00:00:00 +0:00'))
INTO ( PARTITION GPS_DATA_2010_11_28
LOGGING
NOCOMPRESS
TABLESPACE users
PCTFREE 5
INITRANS 10
MAXTRANS 255
STORAGE (
INITIAL 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
) ,
PARTITION GPS_DATA_MAX );

Proof the split has occurred:   发生spli证明:

BEFORE the split:   --拆分之前:

select FILE_ID,EXTENT_ID,BLOCK_ID,PARTITION_NAME from dba_extents where segment_NAME='test';

FILE_ID EXTENT_ID BLOCK_ID PARTITION_NAME
---------- ---------- ---------- ------------------------------
4 0 27657 GPS_DATA_2010_08_08
4 0 27785 GPS_DATA_2010_08_15
4 0 27913 GPS_DATA_MAX


select table_name,PARTITION_NAME, num_rows from dba_tab_partitions where table_name='test';

TABLE_NAME PARTITION_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
GPS GPS_DATA_2010_08_08
GPS GPS_DATA_2010_08_15
GPS GPS_DATA_MAX              1


AFTER the split  --拆分之后

select FILE_ID,EXTENT_ID,BLOCK_ID,PARTITION_NAME from dba_extents where segment_NAME='test';

FILE_ID EXTENT_ID BLOCK_ID PARTITION_NAME
---------- ---------- ---------- ------------------------------
4 0 27657 GPS_DATA_2010_08_08
4 0 27785 GPS_DATA_2010_08_15
4 0 27913 GPS_DATA_2010_11_28
4 0 26377 GPS_DATA_MAX

select table_name,PARTITION_NAME, num_rows from dba_tab_partitions where table_name='test';

TABLE_NAME PARTITION_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
GPS GPS_DATA_2010_08_08
GPS GPS_DATA_2010_08_15
GPS GPS_DATA_MAX                0
GPS GPS_DATA_2010_11_28         1

So we can see from the above that the MAX partition has indeed become the new partition, and a new MAX has been added.  So a fast split has occurred.

因此,从上面我们可以看到,MAX分区确实已成为新分区,并添加了新的MAX。 因此发生了快速拆分。

Confirmed FAST SPLIT Syntax  确认的FAST SPLIT语法

ALTER TABLE test SPLIT PARTITION
GPS_DATA_MAX AT ((TIMESTAMP'2010-11-20 00:00:00 +0:00'))
INTO ( PARTITION GPS_DATA_2010_11_20
LOGGING
NOCOMPRESS
TABLESPACE users
PCTFREE 5
INITRANS 10
MAXTRANS 255 -- This is the one that works. The pctfree, initrans and maxtrans outside the storage clause.
STORAGE
(INITIAL 1M NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
BUFFER_POOL DEFAULT),
PARTITION GPS_DATA_MAX );

  

猜你喜欢

转载自www.cnblogs.com/zylong-sys/p/12120683.html
今日推荐