为了了解partition及subpartition在表空间中的分布情况,做如下实验

create table message
(salesman_id number(5),
salesman_name varchar2(30),
sales_amount number(10),
sales_date date)
partition by range(sales_date)
subpartition by hash(salesman_id)
subpartitions 4 --subpartions的值为4,但store in 中给出3个表空间
store in (PART1_TEST_TB,PART2_TEST_TB,PART1_TEST_TB)
(partition message_part1 values less than(to_date('02/01/2000','DD/MM/YYYY')),
partition message_part2 values less than(to_date('03/01/2000','DD/MM/YYYY')),
partition message_part3 values less than(to_date('04/01/2000','DD/MM/YYYY'))
);
 
 通过user_tab_partitions可查看partition情况,表message被分为3个partition,由于partition子句中没有指定tablespace所以使用创建表用户的默认表空间MYWEBIM.。同时,每个partition的subpartition_count为4,对应命令中的subpartitions 4。

SQL> select table_name,partition_name,subpartition_count,partition_position,tablespace_name from user_tab_partitions;

TABLE_NAME         PARTITION_NAME                 SUBPARTITION_COUNT              PARTITION_POSITION             TABLESPACE_NAME

MESSAGE            MESSAGE_PART1                    4                                 1                                    MYWEBIM
MESSAGE            MESSAGE_PART2                    4                                 2                                    MYWEBIM
MESSAGE            MESSAGE_PART3                    4                                 3                                    MYWEBIM

 

在user_tab_subpartitions中查看subpartition情况,根据命令每个partition被分为4个subpartition,subpartition_position分别为1、2、3、4,但由于store in命令中只给定三个表空间,所以1、2、3号subpartition被散列到指定表空间中,4号被循环散列到第一个指定的表空间PART1_TEST_TB中

 1* select table_name,partition_name,subpartition_name,subpartition_position,tablespace_name from user_tab_subpartitions
SQL> /

TABLE_NAME                      PARTITION_NAME                     SUBPARTITION_NAME                   SUBPART_POSITION                      TABLESPACE_NAME

MESSAGE                       MESSAGE_PART1            SYS_SUBP21                              1                                           PART1_TEST_TB
MESSAGE                       MESSAGE_PART1            SYS_SUBP22                              2                                           PART2_TEST_TB
MESSAGE                       MESSAGE_PART1            SYS_SUBP23                              3                                           PART3_TEST_TB
MESSAGE                       MESSAGE_PART1            SYS_SUBP24                              4                                           PART1_TEST_TB


MESSAGE                       MESSAGE_PART2            SYS_SUBP25                              1                                          PART1_TEST_TB
MESSAGE                       MESSAGE_PART2            SYS_SUBP26                              2                                          PART2_TEST_TB
MESSAGE                       MESSAGE_PART2            SYS_SUBP27                              3                                          PART3_TEST_TB
MESSAGE                       MESSAGE_PART2            SYS_SUBP28                              4                                          PART1_TEST_TB


MESSAGE                       MESSAGE_PART3              SYS_SUBP29                             1                                         PART1_TEST_TB
MESSAGE                       MESSAGE_PART3              SYS_SUBP30                             2                                         PART2_TEST_TB
MESSAGE                       MESSAGE_PART3              SYS_SUBP31                             3                                         PART3_TEST_TB
MESSAGE                       MESSAGE_PART3              SYS_SUBP32                             4                                         PART1_TEST_TB