2

在项目的后期,我们意识到我们需要使用 Oracle (11G) 分区来实现数据的性能和管理。我们有一个分层实体模型,其中包含许多 @OneToMany 和 @OneToOne 关系,并且一些实体是从 2 个或更多其他实体引用的。我们想在“父/根”实体上使用“按范围分区”(月份),在所有子实体上使用“按引用分区”。一年后,我们会将最旧的月份分区移动到存档数据库。这是一个 24-7 系统,因此数据不断增长。

来自 Oracle 文档:“引用分区允许通过引用约束对彼此相关的两个表进行分区。分区键通过现有的父子关系解析,由启用和活动的主键和外键约束强制执行。”

当有 2 个外键并且其中一个可以为空时,是否可以在表上使用“按引用分区”?(根据我读到的内容,您必须在外键上使用“not null”来进行“引用分区”)

一个小例子来说明这个问题:

A - parent entity
B - child entity to A
C - child entity to A or B

create table 
A (
   id number primary key,
   adate date
)
partition by range (adate) (
   partition p1 values less than (to_date('20130501','yyyymmdd')),
   partition p2 values less than (to_date('20130601','yyyymmdd')),
   partition pm values less than (maxvalue)
);

create table 
B (
   id number primary key,
   text varchar2(5),
   a_id number not null,
   constraint fk_ba foreign key (a_id) references A
)
partition by reference(fk_ba);

create table 
C (
   id number primary key,
   text varchar2(5),
   a_id number not null, -- NOT POSSIBLE as a_id or b_id will be null..
   b_id number not null, -- NOT POSSIBLE as a_id or b_id will be null..
   constraint fk_ca foreign key (a_id) references A,
   constraint fk_cb foreign key (b_id) references B
)
partition by reference(fk_ca)
partition by reference(fk_cb);

感谢您的任何建议。/垫子

4

1 回答 1

1

您不能通过两个外键进行分区。

如果 A 是 B 的父级并且 B 是 C 的父级,我建议通过 fk_cb 对 C 进行分区。天气你会在加入 A 和 C 时获得最大修剪 - 这是一个有趣的问题,你为什么不为我们进行测试?

问题 - 为什么你在表 C 中有 A 的 FK。不是 A 由 fk 隐含到 B 吗?

(我的猜测,从技术上讲这是可能的,但 oracle 必须访问表 B。我认为他不会这样做,所以我认为你不会被修剪)。

于 2013-05-20T17:28:51.760 回答