简体   繁体   English

Oracle 分区按 ID 和按 DATE 的子分区和间隔

[英]Oracle Partition by ID and subpartition by DATE with interval

The schema I'm working on has a small amount of customers, with lots of data per customer.我正在处理的模式有少量客户,每个客户有大量数据。

In determining a partitioning strategy, my first thought was to partition by customer_id and then subpartition by range with a day interval.在确定分区策略时,我的第一个想法是按 customer_id 分区,然后按范围以天为间隔进行子分区。 However you cannot use interval in subpartitions.但是,您不能在子分区中使用间隔。

Ultimately I would like a way to automatically create partitions for new customers as they are created, and also have automatic daily subpartitions created for the customers' data.最终,我想要一种在创建新客户时自动为新客户创建分区的方法,并且还为客户的数据创建每日自动子分区。 All application queries are at the customer_id level with various date ranges specified.所有应用程序查询都在 customer_id 级别,并指定了各种日期范围。

This post is nearly identical, but the answer involves reversing the partitioning strategy, and I would still like to find a way to accomplish range-range interval partitioning.这篇文章几乎相同,但答案涉及反转分区策略,我仍然想找到一种方法来完成范围-范围间隔分区。 One way could potentially be to have a monthly database job to create subpartitions for the days/months ahead, but that doesn't feel right.一种方法可能是让每月的数据库作业为未来的几天/几个月创建子分区,但这感觉不对。

Perhaps I'm wrong on my assumptions that the current data structure would benefit more from a range-range interval partitioning strategy.也许我的假设是错误的,即当前的数据结构将从范围-范围间隔分区策略中受益更多。 We have a few customers whose data dwarfs other customers, so I was thinking of ways to isolate customer data.我们有一些客户的数据使其他客户相形见绌,所以我在考虑隔离客户数据的方法。

Any thoughts/suggestions on a better approach?关于更好方法的任何想法/建议?

Thank you again!再次感谢你!

UPDATE更新

Here is an example of what I was proposing:这是我提出的一个例子:

    CREATE TABLE PART_TEST(
            CUSTOMER_ID NUMBER,
            LAST_MODIFIED_DATE DATE
        )
        PARTITION BY RANGE (CUSTOMER_ID) 
        INTERVAL (1) 
        SUBPARTITION BY RANGE (LAST_MODIFIED_DATE)
        SUBPARTITION TEMPLATE
         (
            SUBPARTITION subpart_1206_min values LESS THAN (TO_DATE('12/2006','MM/YYYY')),
            SUBPARTITION subpart_0107 values LESS THAN (TO_DATE('01/2007','MM/YYYY')),
            SUBPARTITION subpart_0207 values LESS THAN (TO_DATE('02/2007','MM/YYYY')),
            ...
            ...
            ...
            SUBPARTITION subpart_max values LESS THAN (MAXVALUE)
         )
         (
         PARTITION part_1 VALUES LESS THAN (1)
         )

I currently have 290 subpartitions in the template.我目前在模板中有 290 个子分区。 This appears to be working except for one snag.除了一个障碍外,这似乎有效。 In my tests I'm finding that any record with a CUSTOMER_ID greater than 3615 fails with ORA-14400: inserted partition key does not map to any partition在我的测试中,我发现 CUSTOMER_ID 大于 3615 的任何记录都会因 ORA-14400 失败:插入的分区键未映射到任何分区

You can make a RANGE INTERVAL partition on date and then LIST or RANGE subpartition on it.您可以在日期上创建RANGE INTERVAL分区,然后在其上创建LISTRANGE子分区。 Would be like this:会是这样的:

CREATE TABLE MY_PART_TABLE
(
  CUSTOMER_ID                      NUMBER             NOT NULL,
  THE_DATE                 TIMESTAMP(0) NOT NULL,
  OTHER_COLUMNS NUMBER
)
PARTITION BY RANGE (THE_DATE) INTERVAL (INTERVAL '1' MONTH)
    SUBPARTITION BY RANGE (CUSTOMER_ID)
        SUBPARTITION TEMPLATE (
        SUBPARTITION CUSTOMER_GROUP_1 VALUES LESS THAN (10),
        SUBPARTITION CUSTOMER_GROUP_2 VALUES LESS THAN (20),
        SUBPARTITION CUSTOMER_GROUP_3 VALUES LESS THAN (30),
        SUBPARTITION CUSTOMER_GROUP_4 VALUES LESS THAN (40),
        SUBPARTITION CUSTOMER_GROUP_5 VALUES LESS THAN (MAXVALUE)
        )
(PARTITION VALUES LESS THAN ( TIMESTAMP '2015-01-01 00:00:00') );



CREATE TABLE MY_PART_TABLE
(
  CUSTOMER_ID                      NUMBER             NOT NULL,
  THE_DATE                 TIMESTAMP(0) NOT NULL,
  OTHER_COLUMNS NUMBER
)
PARTITION BY RANGE (THE_DATE) INTERVAL (INTERVAL '1' MONTH)
    SUBPARTITION BY LIST (CUSTOMER_ID)
        SUBPARTITION TEMPLATE (
        SUBPARTITION CUSTOMER_1 VALUES (1),
        SUBPARTITION CUSTOMER_2 VALUES (2),
        SUBPARTITION CUSTOMER_3_to_6 VALUES (3,4,5,6),
        SUBPARTITION CUSTOMER_7 VALUES (7)
        )
(PARTITION VALUES LESS THAN ( TIMESTAMP '2015-01-01 00:00:00') );

Note, for the second solution the number (ie ID's) of customer is fix.请注意,对于第二个解决方案,客户的数量(即 ID)是固定的。 If you get new customers you have to alter the table and modify the SUBPARTITION TEMPLATE accordingly.如果您获得新客户,则必须更改表并相应地修改 SUBPARTITION TEMPLATE。

Monthly partitions will be created automatically by Oracle whenever new values are inserted or updated.每当插入或更新新值时,Oracle 都会自动创建每月分区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM