Oracle - 如果已删除相应的间隔,如何在分区 table 中处理行?
Oracle - How the rows are handled in partitioned table, if the respective interval is already dropped?
我有一个基于范围分区的现有 table
架构:
create table History(
hid number(19,0),
type varchar2(255 char),
lastupdated timestamp (6) not null enable,
name varchar2(255 char),
primary key (hid))
partition by range (lastupdated) interval (numtodsinterval(1,'day'))
(partition retailhistory values less than (to_timestamp('12/01/2020','DD/MM/YYYY')));
我的目标是创建一个程序来删除旧分区,比如 15 天之前。根据要求,我开发了一个程序,它也删除了最后一个分区,即。 e. retailhistory,系统生成的分区。现在我想到了一个问题,既然区间分区的下界现在改变了,如果我再次插入丢失分区的数据会发生什么,
Say, in above case, partition for retail history is now dropped and then I want to insert a data with timestamp (11/01/2020) as the start date for partition was 12 jan.
How this data would be now allocated to a partition. I can see the row has been now inserted in table, but I cant see a system generated partition created for this date.
Any help would be appreciated. Thanks. :)
编辑:我使用以下技术删除了分区:
改变table历史设置间隔(numtodsinterval(1,'day'));
然后
更改table历史删除分区零售历史更新索引;
retailhistory分区存储1月12日之前的数据。删除此分区后,下一个系统生成的分区成为下限。
现在我想插入时间戳为 1 月 1 日的数据。那么如何处理呢。
您可以通过如下查询查看每行数据分配给哪个分区:
select h.lastupdated, uo.subobject_name
from history h
join user_objects uo on uo.data_object_id = dbms_rowid.rowid_object(h.rowid);
您插入的行将进入具有最低 high_value
且大于您要插入的日期 2020-01-11 的分区。如果您保留了 2 月日期的分区并删除了 1 月的所有分区,那么插入 2020-01-11 将与 2020-02-01 上的时间戳进入同一分区。 high_value
为 2020-02-02 00:00:00;你的数据在那之前,所以它会在那个里面。
After dropping this partition, the next system generated partition becomes lower bound.
不,这不是下限。
Each partition has a VALUES LESS THAN clause, that specifies a non-inclusive upper bound for the partitions. Any values of the partitioning key equal to or higher than this literal are added to the next higher partition. All partitions, except the first, have an implicit lower bound specified by the VALUES LESS THAN clause of the previous partition.
下一个系统生成的分区变成lower lowest upper bound
删除旧分区后,新的 'first' 分区仍然没有下限,因此任何较早的值都会进入该存储桶。
在只有 retailhistory
分区的原始 table 中,如果您在此之前插入了一个值 - 例如timestamp 1999-12-31
- 那么它仍然会进入该分区,因为该值小于 2020-01-12。
所有其他系统生成的分区恰好涵盖一天,但第一个分区可以返回任意天数。
我有一个基于范围分区的现有 table 架构:
create table History(
hid number(19,0),
type varchar2(255 char),
lastupdated timestamp (6) not null enable,
name varchar2(255 char),
primary key (hid))
partition by range (lastupdated) interval (numtodsinterval(1,'day'))
(partition retailhistory values less than (to_timestamp('12/01/2020','DD/MM/YYYY')));
我的目标是创建一个程序来删除旧分区,比如 15 天之前。根据要求,我开发了一个程序,它也删除了最后一个分区,即。 e. retailhistory,系统生成的分区。现在我想到了一个问题,既然区间分区的下界现在改变了,如果我再次插入丢失分区的数据会发生什么,
Say, in above case, partition for retail history is now dropped and then I want to insert a data with timestamp (11/01/2020) as the start date for partition was 12 jan.
How this data would be now allocated to a partition. I can see the row has been now inserted in table, but I cant see a system generated partition created for this date. Any help would be appreciated. Thanks. :)
编辑:我使用以下技术删除了分区:
改变table历史设置间隔(numtodsinterval(1,'day'));
然后
更改table历史删除分区零售历史更新索引;
retailhistory分区存储1月12日之前的数据。删除此分区后,下一个系统生成的分区成为下限。
现在我想插入时间戳为 1 月 1 日的数据。那么如何处理呢。
您可以通过如下查询查看每行数据分配给哪个分区:
select h.lastupdated, uo.subobject_name
from history h
join user_objects uo on uo.data_object_id = dbms_rowid.rowid_object(h.rowid);
您插入的行将进入具有最低 high_value
且大于您要插入的日期 2020-01-11 的分区。如果您保留了 2 月日期的分区并删除了 1 月的所有分区,那么插入 2020-01-11 将与 2020-02-01 上的时间戳进入同一分区。 high_value
为 2020-02-02 00:00:00;你的数据在那之前,所以它会在那个里面。
After dropping this partition, the next system generated partition becomes lower bound.
不,这不是下限。
Each partition has a VALUES LESS THAN clause, that specifies a non-inclusive upper bound for the partitions. Any values of the partitioning key equal to or higher than this literal are added to the next higher partition. All partitions, except the first, have an implicit lower bound specified by the VALUES LESS THAN clause of the previous partition.
下一个系统生成的分区变成lower lowest upper bound
删除旧分区后,新的 'first' 分区仍然没有下限,因此任何较早的值都会进入该存储桶。
在只有 retailhistory
分区的原始 table 中,如果您在此之前插入了一个值 - 例如timestamp 1999-12-31
- 那么它仍然会进入该分区,因为该值小于 2020-01-12。
所有其他系统生成的分区恰好涵盖一天,但第一个分区可以返回任意天数。