Pular para o conteúdo

Automatic List Partitioning

Automatic List Partitioning

O particionamento de lista automático (Auto-List Partitioning) é uma extensão do particionamento de lista, foi introduzido no Oracle Database 12c Release 2 e possibilita resolver o problema de como lidar com novos valores distintos que não correspondem a nenhuma das partições existentes da chave de particionamento de lista.

O Oracle Database 12c Release 2 introduziu uma série de novos e poderosos recursos de particionamento, neste artigo focaremos somente no Auto-List Partitioning, no futuro poderemos falar sobre os demais novos recursos.

No exemplo abaixo efetuarei a criação de uma tabela chamada MAPA com as seguintes partições (P_SUL, P_NORTE, P_SUDESTE).

Automatic List Partitioning
 GPO@morpheus> create table MAPA
     ( regiao varchar2(20),
       estado varchar2(20))
     partition by list (regiao)
     ( partition P_NORTE values ('NORTE'),
       partition P_SUDESTE values ('SUDESTE'),
       partition P_SUL values ('SUL'));
  
 Table created.
  
 GPO@morpheus> insert into MAPA values ('SUL','SANTA CATARINA');
  
 1 row created.
  
 GPO@morpheus> insert into MAPA values ('NORTE','TOCANTINS');
  
 1 row created.
  
 GPO@morpheus> insert into MAPA values ('NORDESTE','PERNAMBUCO');
 insert into MAPA values ('NORDESTE','PERNAMBUCO')
             *
 ERROR at line 1:
 ORA-14400: inserted partition key does not map to any partition 

Para resolver esse problema no Oracle Database 12c Release 1 ou versões anteriores:

 GPO@morpheus> drop table MAPA;
  
 Table dropped.
   
 GPO@morpheus> create table MAPA
     ( regiao varchar2(20),
       estado varchar2(20))
     partition by list (regiao)
     ( partition P_NORTE values ('NORTE'),
       partition P_SUDESTE values ('SUDESTE'),
       partition P_SUL values ('SUL'),
       partition P_OUTRAS_REGIOES values (default));
  
 Table created.
  
 GPO@morpheus> insert into MAPA values ('NORDESTE','PERNAMBUCO');
  
 1 row created. 

O Problema é que todos os outros registros que não se adequam a lista de valores (SUL, SUDESTE, NORTE) irão para a partição P_OUTRAS_REGIOES, podendo ocasionar uma diferença considerável na distribuição dos dados entre as partições a medida que a tabela for crescendo.

A partir do Oracle Database 12c Release 2 utilizando o Auto-List Partitioning, a medida que novos dados são carregados na tabela, o banco de dados efetua a criação de novas partições sob demanda baseado nos valores distintos que não se adequam as partições já existentes.

GPO@morpheus> create table MAPA
     ( regiao varchar2(20),
       estado varchar2(20))
     partition by list (regiao) AUTOMATIC
     ( partition P_NORTE values ('NORTE'),
       partition P_SUDESTE values ('SUDESTE'),
       partition P_SUL values ('SUL'));
  
 Table created.
  
 GPO@morpheus> insert into MAPA values ('SUL','SANTA CATARINA');
  
 1 row created.
  
 GPO@morpheus> insert into MAPA values ('NORTE','TOCANTINS');
  
 1 row created.
  
 GPO@morpheus> insert into MAPA values ('SUDESTE','MINAS GERAIS');
  
 1 row created.
  
 GPO@morpheus> commit;
  
 Commit complete.
  
 GPO@morpheus> exec dbms_stats.gather_table_stats('GPO','MAPA');
  
 PL/SQL procedure successfully completed.
  
 GPO@morpheus> insert into MAPA values ('NORDESTE','PERNAMBUCO');

 1 row created.

 GPO@morpheus> select partition_name, high_value from user_tab_partitions where table_name = 'MAPA' order by partition_position;
  
 PARTITION_NA HIGH_VALUE
 ------------ --------------------------------------------------------------------------------
 P_NORTE      'NORTE'
 P_SUDESTE    'SUDESTE'
 P_SUL        'SUL'
 SYS_P324     'NORDESTE'
  
 GPO@morpheus> insert into MAPA values ('CENTRO-OESTE','MATO GROSSO DO SUL');
  
 1 row created.
  
 GPO@morpheus> select partition_name, high_value from user_tab_partitions where table_name = 'MAPA' order by partition_position;
  
 PARTITION_NA HIGH_VALUE
 ------------ --------------------------------------------------------------------------------
 P_NORTE      'NORTE'
 P_SUDESTE    'SUDESTE'
 P_SUL        'SUL'
 SYS_P324     'NORDESTE'
 SYS_P325     'CENTRO-OESTE'
  
 GPO@morpheus> select table_name, partitioning_type, autolist, partition_count from user_part_tables where table_name = 'MAPA';
  
 TABLE_NAME PARTITION AUT PARTITION_COUNT
 ---------- --------- --- ---------------
 MAPA      LIST      YES           5
  
 GPO@morpheus> alter table MAPA set partitioning MANUAL;
  
 Table altered.
  
 GPO@morpheus> select table_name, partitioning_type, autolist, partition_count from user_part_tables where table_name = 'MAPA';
  
 TABLE_NAME PARTITION AUT PARTITION_COUNT
 ---------- --------- --- ---------------
 MAPA      LIST      NO            5
  
 GPO@morpheus> alter table MAPA set partitioning AUTOMATIC;
  
 Table altered.
  
 GPO@morpheus> select table_name, partitioning_type, autolist, partition_count from user_part_tables where table_name = 'MAPA';
  
 TABLE_NAME PARTITION AUT PARTITION_COUNT
 ---------- --------- --- ---------------
 MAPA      LIST      YES           5

Restrições do Auto-List Partitioning de acordo com a documentação oficial da Oracle:

Automatic list partitioning is subject to the restrictions listed in “Restrictions on List Partitioning”. The following additional restrictions apply:

  • An automatic list-partitioned table must have at least one partition when created. Because new partitions are automatically created for new, and unknown, partitioning key values, an automatic list-partitioned table cannot have a DEFAULT partition.
  • Automatic list partitioning is not supported for index-organized tables or external tables.
  • Automatic list partitioning is not supported for tables containing varray columns.
  • You cannot create a local domain index on an automatic list-partitioned table. You can create a global domain index on an automatic list-partitioned table.
  • An automatic list-partitioned table cannot be a child table or a parent table for reference partitioning.
  • Automatic list partitioning is not supported at the subpartition level.

Referências

Quão útil foi este post ?

Clique em uma estrela para classificar o post

nota média 5 / 5. Contagem de votos: 27

Sem votos ! Seja o primeiro a classificar !

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

plugins premium WordPress