我应该分区/ subpartition我的表吗? [英] Should I partition/subpartition my table?

查看:198
本文介绍了我应该分区/ subpartition我的表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

案例


  1. 系统有 dispositives ,基本上由 id,type,name 形成。

  2. 我可能有N dispositives

  3. 我有一个表来存储日志所有 dispositives 。这是系统中最大的表。 (现在计数100 mi记录)

  4. log 表有: id_dispositive,date,status

问题



显然这个巨大的数据它导致性能问题。我必须存储至少两个月的日志值。



今天我有 dispositives type

  TYPE COUNT 
---------- -----
1 78956
2 125161
3 13213
4 6112
5 25426
6 12314
7 1241
8 622



我还有一些业务逻辑来提供 log 表。无论如何,这里是我的想法:



我的解决方案思考分区这个 log 表。这是问题:


  1. 是否值得?

  2. / li>
  3. 我应该按DATE按类型和子分区分区吗?

  4. 我可以通过编程方式进行分区吗?

由于这种类型是动态的,用户可以删除/插入新的。



日志类型。
如果他们插入一些类型,我必须注册(存储)该类型的所有日志。



根据Francesco Serra的回答编辑



我试图像这样创建表:

 创建表日志(
id_dispositive number,
类型编号,
date_verification日期,
状态编号

按范围分区(date_verification)
按分类的子分区
子分区TEMPLATE(
SUBPARTITION type1 VALUES(1),
SUBPARTITION type2 VALUES(2),
SUBPARTITION type3 VALUES(3),
SUBPARTITION type4 VALUES(4)
)(
interval(numtoyminterval(1,'MONTH'))(
partition p0816 values less than(to_date('01 / 09/2016','dd / mm / yyyy'))
));

我会得到:

 未找到ORA-14004:PARTITION关键字。 


解决方案

您可以这样尝试:使用INTERVAL oracle创建自动分区。您必须定义列(数字或日期)和间隔(在我的示例中为1个月)。 Oracle会把同一个分区中的所有行放在同一个区间(在这种情况下在同一个月份)。如果分区不存在将被创建。

 创建表日志(
id_dispositive number,
日期,
状态编号,
类型编号

按范围分区(日期)
间隔(numtoyminterval(1,'MONTH')) b分区p0701的值小于(to_date('2007-02-01','yyyy-mm-dd'))
);

也可以对类型列进行同样的操作。详细信息: http://www.oracle.com/technetwork/ article / sql / 11g-partitioning-084209.html



每个分区都可以使用TEMPLATE键进行子分区。

  create table log(
id_dispositive number,
date date,
status number,
type number

按范围(日期)间隔分区(numtoyminterval(1,'MONTH'))
按分区的子分区(类型)
子分区TEMPLATE(
SUBPARTITION types1 VALUES(1,2) TABLESPACE tbs_1,
SUBPARTITION types2 VALUES(3,4)TABLESPACE tbs_1


分区p0701值小于(to_date('2007-02-01','yyyy- mm-dd'))
);

在这种情况下,您不能创建自动子分区,如果新类型将添加运行alter table statment。这里更多的信息; https://docs.oracle.com/cd/B28359_01 /server.111/b32024/part_admin.htm#i1006655



在您的示例中:

  create table prova_log(
id_dispositive number,
type number,
date_verification date,
status number
$ b分区按范围(date_verification)间隔(numtoyminterval(1,'MONTH'))
按分区的子分区(类型)
subpartition TEMPLATE(
SUBPARTITION type1 VALUES ),
SUBPARTITION type2 VALUES(2),
SUBPARTITION type3 VALUES(3),
SUBPARTITION type4 VALUES(4)


分区p0816值小于(to_date('01 / 09/2016','dd / mm / yyyy'))
);

如果您尝试插入:

 插入prova_log值(1,1,TO_DATE('10 / 10/2016','dd / mm / yyyy'),1); 

您将在表上看到2个分区。



现在我已经测试过了!


Case

  1. The system has dispositives, basically formed by id, type, name.
  2. I may have N dispositives.
  3. I have a table to store a log of all dispositives. This is the biggest table in the system. (Now counting 100 mi records)
  4. The log table has: id_dispositive, date, status.

Problem

Obviously this huge data it's causing performance issues. I must store at least two months log values..

Today I have this dispositives by type:

TYPE     COUNT
---------------
1         78956  
2         125161
3         13213
4         6112
5         25426
6         12314
7         1241
8         622

I also have some business logic to feed this log table. Anyways, here is my thoughts:

My "solution"

I was thinking on partition this log table. Here is the questions:

  1. Does it worth it?
  2. Should I partition by type?
  3. Should I partition by type AND subpartition by DATE?
  4. Can I do it programmatically?

As this types are dynamics, users can delete/insert new ones.

So if they delete some type, I must delete all logs of that type. As if they insert some type, I must register(store) all logs of that type.

EDIT according Francesco Serra's answer

I'm trying to create the table like this:

create table log(
       id_dispositive    number,
       type       number,
       date_verification    date,
       status  number
)
partition by range (date_verification) 
subpartition by list (type)  
subpartition TEMPLATE (
    SUBPARTITION type1 VALUES (1),
    SUBPARTITION type2 VALUES (2),
    SUBPARTITION type3 VALUES (3),
    SUBPARTITION type4 VALUES (4)
)(                           
interval (numtoyminterval(1,'MONTH'))(
   partition p0816 values less than (to_date('01/09/2016','dd/mm/yyyy'))
));

and i'm getting:

ORA-14004: PARTITION keyword not found.

解决方案

You can try in this way: use INTERVAL to tell oracle to create automatic partitions. You must define column (number or date) and an interval (in my example 1 month). Oracle will put in the same partition all row in the same interval (in this case in the same month). If the partition doesn't exist will be created.

create table log(
       id_dispositive    number,
       date    date,
       status  number,
       type    number
)
partition by range (date)                              
interval (numtoyminterval(1,'MONTH'))(
   partition p0701 values less than (to_date('2007-02-01','yyyy-mm-dd'))
);

The same can be done also with type column. More information: http://www.oracle.com/technetwork/articles/sql/11g-partitioning-084209.html.

Every partition can be subpartitioned using TEMPLATE key.

create table log(
       id_dispositive    number,
       date    date,
       status  number,
       type    number
)
partition by range (date) interval (numtoyminterval(1,'MONTH'))
subpartition by list (type)  
subpartition TEMPLATE (
    SUBPARTITION types1 VALUES (1, 2) TABLESPACE tbs_1,
    SUBPARTITION types2 VALUES (3, 4) TABLESPACE tbs_1
)                          
(
   partition p0701 values less than (to_date('2007-02-01','yyyy-mm-dd'))
);

In this case you can't create an automatic subpartition, if a new type will be add you have to run an alter table statment. Here more informations; https://docs.oracle.com/cd/B28359_01/server.111/b32024/part_admin.htm#i1006655.

In your example:

create table prova_log(
       id_dispositive    number,
       type       number,
       date_verification    date,
       status  number
)
partition by range (date_verification) interval (numtoyminterval(1,'MONTH'))
subpartition by list (type)  
subpartition TEMPLATE (
    SUBPARTITION type1 VALUES (1),
    SUBPARTITION type2 VALUES (2),
    SUBPARTITION type3 VALUES (3),
    SUBPARTITION type4 VALUES (4)
)                          
(
   partition p0816 values less than (to_date('01/09/2016','dd/mm/yyyy'))
);

If you try to insert:

insert into prova_log values (1,1,TO_DATE('10/10/2016','dd/mm/yyyy'),1);

you will see 2 partition on your table.

Now I've tested it!

这篇关于我应该分区/ subpartition我的表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆