Documente Academic
Documente Profesional
Documente Cultură
1 de 4
http://uhesse.com/2010/02/15/partitioning-a-table-online-with-dbms_r...
08/08/2015 11:28
2 de 4
http://uhesse.com/2010/02/15/partitioning-a-table-online-with-dbms_r...
SQL> begin
dbms_redefinition.can_redef_table
(uname=>'ADAM',
tname=>'ORIGINAL',
options_flag=>DBMS_REDEFINITION.CONS_USE_ROWID);
end;
/
PL/SQL procedure successfully completed.
Because there is no Primary Key on the original table, I have to use CONS_USE_ROWID, else I
could use CONS_USE_PK. There are no objections against the online redenition of the table
here else an error message would appear. Next step is to create an interim table of the
structure, desired for the original table. In my case, I create it interval partitioned (an 11g New
Feature). I could also change storage a ributes and add or remove columns during that process.
SQL> create table interim
(id number,
channel_id number(1),
amount_sold number(4),
cust_id number(4),
time_id date)
partition by range (cust_id)
interval (10)
(partition p1 values less than (10));
Table created.
My original table has 1000 distinct cust_ids, so this will lead to 100 partitions each partion will
contain 10 distinct cust_ids. One benet of that would be the possibility of partition pruning,
should there be statements, specifying the cust_id in the where-condition. These statements will
be about 100 times faster as a full table scan. The next step will basically insert all the rows from
the orginal table into the interim table (thereby automatically generating 99 partitions), while
DML during that period is recorded:
SQL> set timing on
SQL>
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE
(uname=>'ADAM',
orig_table=>'ORIGINAL',
int_table=>'INTERIM',
options_flag=>DBMS_REDEFINITION.CONS_USE_ROWID);
end;
/
PL/SQL procedure successfully completed.
Elapsed: 00:00:22.76
If this step takes a long time to run it might be benecial to use the SYNC_INTERIM_TABLE
procedure occasionally from another session. That prevents a longer locking time for the last
step, the calling of FINISH_REDEF_TABLE. Next step is now to add the dependent
objects/privileges to the interim table:
SQL> set timing off
SQL> vari num_errors number
08/08/2015 11:28
3 de 4
http://uhesse.com/2010/02/15/partitioning-a-table-online-with-dbms_r...
PARTITION
------------------------------ --------ORIGINAL
RANGE
08/08/2015 11:28
4 de 4
http://uhesse.com/2010/02/15/partitioning-a-table-online-with-dbms_r...
------------------------------ --------ORIGINAL
RANGE
PRIVILEGE
------------------------------ ---------------------------------------HR
SELECT
TABLE_NAME
------------------------------ -----------------------------ORIGINAL_ID_IDX
ORIGINAL
TMP$$_ORIGINAL_ID_IDX0
INTERIM
The interim table can now be dropped. We changed the table into a partitioned table without
any end user noticing it!
This picture illustrates the steps you have seen above hope you nd it useful :-)
08/08/2015 11:28