oracle 主键 hash,ORACLE-HASH分区表

测试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列,这样查询的速度会更快。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值