Chinaunix首页 | 论坛 | 博客
  • 博客访问: 548895
  • 博文数量: 154
  • 博客积分: 4055
  • 博客等级: 上校
  • 技术积分: 1381
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-01 14:26
文章分类

全部博文(154)

文章存档

2014年(2)

2013年(2)

2011年(2)

2010年(11)

2009年(9)

2008年(35)

2007年(22)

2006年(71)

我的朋友

分类: Oracle

2007-10-21 22:19:48

列表分区和哈希分区组合,存储空间分散

 

SQL> CREATE TABLE LIST_HASH_TAB (
  2 id NUMBER,
  3 code VARCHAR2(10),
  4 description VARCHAR2(50),
  5 created_date DATE
  6 )
  7 PARTITION BY LIST (code)
  8 SUBPARTITION BY HASH (id)
  9 (
 10 PARTITION part_aa values ('AA')
 11 (
 12 SUBPARTITION part_aa_01,
 13 SUBPARTITION part_aa_02
 14 ),
 15 partition part_bb values ('BB')
 16 (
 17 SUBPARTITION part_bb_01,
 18 SUBPARTITION part_bb_02
 19 )
 20 );

Table created.

SQL> DECLARE
  2 l_code VARCHAR2(10);
  3 BEGIN
  4 FOR i IN 1 .. 40 LOOP
  5 IF MOD(i, 2) = 0 THEN
  6 l_code := 'BB';
  7 ELSE
  8 l_code := 'AA';
  9 END IF;
 10
 11 INSERT INTO LIST_HASH_TAB (id, code, description, created_date)
 12 VALUES (i, l_code, 'Description for ' || i || ' ' || l_code, SYSDATE);
 13 END LOOP;
 14 COMMIT;
 15 END;
 16 /

PL/SQL procedure successfully completed.

SQL> COLUMN table_name FORMAT A20
SQL> COLUMN partition_name FORMAT A20
SQL> COLUMN subpartition_name FORMAT A20
SQL> SELECT table_name, partition_name, subpartition_name, num_rows
  2 FROM user_tab_subpartitions
  3 ORDER by table_name, partition_name, subpartition_name;

TABLE_NAME PARTITION_NAME SUBPARTITION_NAME NUM_ROWS
-------------------- -------------------- -------------------- ----------
LIST_HASH_TAB PART_AA PART_AA_01
LIST_HASH_TAB PART_AA PART_AA_02
LIST_HASH_TAB PART_BB PART_BB_01
LIST_HASH_TAB PART_BB PART_BB_02

SQL> exec DBMS_STATS.gather_table_stats('SA','LIST_HASH_TAB', granularity=>'ALL');

PL/SQL procedure successfully completed.

SQL> l
  1 SELECT table_name, partition_name, subpartition_name, num_rows
  2 FROM user_tab_subpartitions
  3* ORDER by table_name, partition_name, subpartition_name
SQL> /

TABLE_NAME PARTITION_NAME SUBPARTITION_NAME NUM_ROWS
-------------------- -------------------- -------------------- ----------
LIST_HASH_TAB PART_AA PART_AA_01 7
LIST_HASH_TAB PART_AA PART_AA_02 13
LIST_HASH_TAB PART_BB PART_BB_01 10
LIST_HASH_TAB PART_BB PART_BB_02 10

SQL>
SQL>
SQL> spool off
SQL> COLUMN table_name FORMAT A20
SQL> COLUMN partition_name FORMAT A20
SQL> COLUMN subpartition_name FORMAT A20
SQL>
SQL> SELECT table_name, partition_name, subpartition_name, num_rows
  2 FROM user_tab_subpartitions
  3 ORDER by table_name, partition_name, subpartition_name;

TABLE_NAME PARTITION_NAME SUBPARTITION_NAME NUM_ROWS
-------------------- -------------------- -------------------- ----------
LIST_HASH_TAB PART_AA PART_AA_01 7
LIST_HASH_TAB PART_AA PART_AA_02 13
LIST_HASH_TAB PART_BB PART_BB_01 10
LIST_HASH_TAB PART_BB PART_BB_02 10

阅读(1156) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~