ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ORACLE-HASH分区表

ORACLE-HASH分区表

原创 Linux操作系统 作者:sunwei553722769 时间:2010-12-30 13:53:37 0 删除 编辑
  测试Oracle分区hash分区表的查询效率:
  建立临时表
  -- Create table
create table Z_HASH
(
  ID            NUMBER(22) not null,
  ORG_ID NUMBER(22),
  NAME     VARCHAR2(50)
)
partition by hash (ORG_ID)
(
  partition PART01
    tablespace USERS,
  partition PART02
    tablespace USERS,
  partition PART03
    tablespace USERS,
  partition PART04
    tablespace USERS,
  partition PART05
    tablespace USERS,
  partition PART06
    tablespace USERS,
  partition PART07
    tablespace USERS,
  partition PART08
    tablespace USERS
);
-- Create/Recreate primary, unique and foreign key constraints
alter table Z_HASH
  add constraint PRK_Z_HASH_ID_1 primary key (ID)
  using index
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 128K
    minextents 1
    maxextents unlimited
  );
和
-- Create table
create table Z_HASH_NEW
(
  ID     NUMBER(22) not null,
  ORG_ID NUMBER(22),
  NAME   VARCHAR2(50)
)
partition by hash (ID)
(
  partition PART01
    tablespace USERS,
  partition PART02
    tablespace USERS,
  partition PART03
    tablespace USERS,
  partition PART04
    tablespace USERS,
  partition PART05
    tablespace USERS,
  partition PART06
    tablespace USERS,
  partition PART07
    tablespace USERS,
  partition PART08
    tablespace USERS
);
-- Create/Recreate primary, unique and foreign key constraints
alter table Z_HASH_NEW
  add constraint PRK_Z_HASH_ID_2 primary key (ID)
  using index
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 128K
    minextents 1
    maxextents unlimited
  );
 
这两个表都是分区表,唯一的区别是第一个表的hash列是id,第二个表的hash列是org_id,编写存储过程,插入10000000条数据
 
create or replace procedure ETL_Z_HASH IS
v_a NUMBER:=1;
v_b NUMBER:=1;
BEGIN
  LOOP
    v_a:=v_a+1;
    v_b:=v_b+1;
   
    --插入数据
    INSERT INTO Z_HASH VALUES(z_hash_id.nextval,v_a,z_hash_id.currval||'-'||v_a);
    COMMIT;
    IF v_a>200000 THEN
      v_a:=1;
    END IF;
    IF v_b>10000000 THEN
      EXIT;
    END IF;
  END LOOP;
end ETL_Z_HASH;
 
现在开始测试
SELECT * FROM z_hash h WHERE h.org_id=198622----1
SELECT * FROM z_hash_new h WHERE h.org_id=198622----2
在org_id同样没有索引的条件下sql1执行速度是sql2执行速度的10倍。
总结:在建立hash分区表的时候,应该将最常检索的列作为hash列,这样查询的速度会更快。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24757413/viewspace-682866/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Tomcat-加密数据源
下一篇: Oracle分析函数
请登录后发表评论 登录
全部评论

注册时间:2010-12-14

  • 博文量
    9
  • 访问量
    23460