oracle partition by group_id 和 subpartition monthly

oracle partition by group_id and subpartition monthly

我想创建一个这样的table。

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp
);

为此table我想像

一样存储数据
 group_id=1
    jan-2015
    feb-2015
    ...
group_id=2
    jan-2015
    feb-2015
    ...    

等等。所以我假设我必须按范围为 group_id 创建一个分区,然后使用时间戳列按范围创建一个子分区,对吗?

所以它应该是这样的:

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp
)
PARTITION BY RANGE (group_id)
SUBPARTITION BY RANGE ("TIMESTAMP") 
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
 PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
 );

这样对吗?还有一个问题:有了这个分区,如果添加了一个新的 group_id,oracle 会自动为新的 group_id 创建一个新分区,并为新月份的新数据创建新的支持吗?

子分区级别不支持间隔分区:

http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_7002.htm#SQLRF54559

你可以这样定义它:

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp  -- not good naming
)
PARTITION BY RANGE ("TIMESTAMP")
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
SUBPARTITION BY RANGE (group_id) -- it could be hash or list as well
   subpartition template(
     ...
   )
(
 PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
);