Table patition and aautomate sub partition. [message #642634] |
Tue, 15 September 2015 18:34 |
|
raopatwariyahoocom
Messages: 39 Registered: October 2011 Location: GA
|
Member |
|
|
I need to create a table with partitionon and subpartition s
I have tow columns in the table on which I should do partitionon
cycle_code number,
cycle_month number( has both year and month 'YYYYMM')
cycle_code is day of the month which is supposed to be (1 thru 31) can be list or range partition,
under that partition I want cycle_month as sub partition which should be automated.
I am adding the script of what I have done so far , I could not get this working. Appreciate your help in advance.
I am adding as a sample two partitions p_cyc_1 and p_cyc_2 as samples under each partiton I should have 12 months automated subpartitions. and I will have p_cyc_1 until p_cyc_31
CREATE TABLE abcd
( fileid NUMBER CONSTRAINT mrc_credits_ad_id_nn NOT NULL ENABLE,
cycle_date DATE CONSTRAINT mrc_credits_cycle_date_nn NOT NULL ENABLE,
time_key NUMBER CONSTRAINT mrc_credits_time_key_nn NOT NULL ENABLE,
rslr_partner_id NUMBER CONSTRAINT mrc_credits_rslr_nn NOT NULL ENABLE,
reseller_id VARCHAR2(2 BYTE) CONSTRAINT mrc_credits_rslr_id_nn NOT NULL ENABLE,
soc VARCHAR2(25 BYTE) CONSTRAINT mrc_credits_soc_nn NOT NULL ENABLE,
amount NUMBER,
company VARCHAR2(3 BYTE),
status_ind VARCHAR2(25 BYTE),
cycle_code number,
cycle_month number)
PARTITION BY LIST (cycle_code)
SUBPARTITION BY RANGE (cycle_month) to_number(to_char(INTERVAL(NUMTOYMINTERVAL(1,'YEAR*MONTH')),'YYYYMM'))
( PARTITION p_cyc_1 VALUES (1)
( SUBPARTITION before_01 VALUES LESS THAN to_number(to_char((TO_DATE('01-JAN-2000','dd-MON-yyyy')),'YYYYMM'))
)
,PARTITION p_cyc_2 VALUES (2)
( SUBPARTITION before_02 VALUES LESS THAN to_number(to_char((TO_DATE('01-JAN-2000','dd-MON-yyyy')),'YYYYMM'))
)
) ;
|
|
|
|
|
Re: Table patition and aautomate sub partition. [message #642641 is a reply to message #642636] |
Wed, 16 September 2015 02:05 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Your code doesn't work:orclz>
orclz> CREATE TABLE abcd
2 ( fileid NUMBER CONSTRAINT mrc_credits_ad_id_nn NOT NULL ENABLE,
3 cycle_date DATE CONSTRAINT mrc_credits_cycle_date_nn NOT NULL ENABLE,
4 time_key NUMBER CONSTRAINT mrc_credits_time_key_nn NOT NULL ENABLE,
5 rslr_partner_id NUMBER CONSTRAINT mrc_credits_rslr_nn NOT NULL ENABLE,
6 reseller_id VARCHAR2(2 BYTE) CONSTRAINT mrc_credits_rslr_id_nn NOT NULL ENABLE,
7 soc VARCHAR2(25 BYTE) CONSTRAINT mrc_credits_soc_nn NOT NULL ENABLE,
8 amount NUMBER,
9 company VARCHAR2(3 BYTE),
10 status_ind VARCHAR2(25 BYTE),
11 cycle_code number,
12 cycle_month number)
13 PARTITION BY LIST (cycle_code)
14 SUBPARTITION BY RANGE (cycle_month) to_number(to_char(INTERVAL(NUMTOYMINTERVAL(1,'YEAR*MONTH')),'YYYYMM'))
15 ( PARTITION p_cyc_1 VALUES (1)
16 ( SUBPARTITION before_01 VALUES LESS THAN to_number(to_char((TO_DATE('01-JAN-2000','dd-MON-yyyy')),'YYYYMM'))
17 )
18 ,PARTITION p_cyc_2 VALUES (2)
19 ( SUBPARTITION before_02 VALUES LESS THAN to_number(to_char((TO_DATE('01-JAN-2000','dd-MON-yyyy')),'YYYYMM'))
20 )
21 ) ;
SUBPARTITION BY RANGE (cycle_month) to_number(to_char(INTERVAL(NUMTOYMINTERVAL(1,'YEAR*MONTH')),'YYYYMM'))
*
ERROR at line 14:
ORA-00922: missing or invalid option
orclz> What are you trying to achieve? What is the the nature of the queries and DDLs that you expect to run against this table? Prtitioning is often a disaster if you have not designed the strategy to fit the problem.
And of course you need to correct your syntax.
|
|
|
|
|
|
Re: Table patition and aautomate sub partition. [message #642658 is a reply to message #642656] |
Wed, 16 September 2015 07:37 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
raopatwariyahoocom wrote on Wed, 16 September 2015 13:20when I am selecting the data I use in the where clause
where cycle_month = 'YYYYMM' -- this has both year and month
and cycle_code = 31;
if I am trying to retreive the data where cycle_code is 31(numberof cycles)
and cycle_month = 'YYYYMM'('201602')
the whole value cannot be kept as date because there is no data value like '31-FEB-2016'. Thats why I had to go this route.
else I could have automated ad date making that as cycle_date date datatype
As you are using equality predicates, hash partitioning would probably be better than range. However, are you sure that you should partition at all? Unless each query is retrieving a significant proportion of the rows in the table, index access will be better than table scans with partition pruning. How many rows in the table? How many rows have cycle_code=31 and cycle_month = 'YYYYMM'('201602') ?
|
|
|
Re: Table patition and aautomate sub partition. Req changed [message #642663 is a reply to message #642634] |
Wed, 16 September 2015 11:07 |
|
raopatwariyahoocom
Messages: 39 Registered: October 2011 Location: GA
|
Member |
|
|
Requirements are changed bit
I need to create a table with partition and subpartition s
I have two columns in the table on which I should do partitionon
cycle_code number,
month_year DATE
cycle_code is day of the month which is supposed to be (1 thru 31) can be list or range partition,
under that partition I want month_year as sub partition which should be automated.
I am adding the script of what I have done so far , I could not get this working. Appreciate your help in advance.
I am adding as a sample two partitions p_cyc_1 and p_cyc_2 as samples under each partiton I should have 12 months automated subpartitions.
and I will have p_cyc_1 until p_cyc_31
p_cyc_1 list partition should have 12 months sub partitions
CREATE TABLE ds_mrc_credits_cyc
( fileid NUMBER CONSTRAINT mrc_credits_ad_id_nn1 NOT NULL ENABLE,
time_key NUMBER CONSTRAINT mrc_credits_time_key_nn1 NOT NULL ENABLE,
rslr_partner_id NUMBER CONSTRAINT mrc_credits_rslr_nn1 NOT NULL ENABLE,
reseller_id VARCHAR2(2 BYTE) CONSTRAINT mrc_credits_rslr_id_nn1 NOT NULL ENABLE,
soc VARCHAR2(25 BYTE) CONSTRAINT mrc_credits_soc_nn1 NOT NULL ENABLE,
amount NUMBER,
company VARCHAR2(3 BYTE),
status_ind VARCHAR2(25 BYTE),
cycle_code number,
month_year DATE)
PARTITION BY LIST ( cycle_code )
SUBPARTITION BY RANGE( month_year )
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
( PARTITION p_cyc_1 VALUES (1)
(SUBPARTITION before_01 VALUES LESS THAN (TO_DATE('20140201', 'YYYYMMDD'))),
PARTITION p_cyc_2 VALUES (2)
(SUBPARTITION before_01 VALUES LESS THAN (TO_DATE('20140201', 'YYYYMMDD')))
);
|
|
|
|