oracle 分区 索引 执行计划

本文介绍如何在Oracle数据库中创建分区表、添加分区、创建不同类型的索引(包括局部索引和全局索引),并展示了如何查看分区及索引的相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--创建分区表


createtable t_getpwd_record

(

serverName VARCHAR2(40),

accountVARCHAR2(64),

provinceCode VARCHAR2(2),

resultCode VARCHAR2(16),

descriptionVARCHAR2(256),

exceptionVARCHAR2(256),

requesttime datedefaultsysdate,

remark VARCHAR2(128)

)

 

partitionbyrange(requesttime)

(PARTITION P1405VALUESLESSTHAN (TO_DATE('201406','YYYYMM')));

如果该语句过慢,在该句后增加条件 WHERE 1=2  (仅创建空分区表)

 

---查看表分区(表名大写)

 

SELECTtable_name,partition_nameFROM user_tab_partitions

WHERE table_name='T_GETPWD_RECORD';

 

 

--增加表分区

altertable T_GETPWD_RECORDaddpartition P1406valueslessthan(to_date('201407','YYYYMM'));

 

--添加索引

createindex acc_phoneon t_special_account(phone);

 

--联合索引

createindex acc_type_releaseon t_special_account(account_type,account_release_time);

 

--查看索引

select *from user_indexeswhere table_nameLIKE'T_SPEC%'

 

--查看索引用的字段

selectindex_name,table_name,column_namefrom user_ind_columnswhere index_name='I_RELEASE_ACCTYPE_COM';

 

--添加分区索引

CREATEINDEXLIND_t_getpwd_record_IDON t_getpwd_record(accountLOCAL

(PARTITION P1405);

 

--查看分区索引

selectindex_name,partition_namefrom user_ind_partitions;

如果使用分区索引,删除分区的时候其他分区的索引还是可以使用的。
如果用全局索引,删除分区的时候,需要对全局索引update:
alter table ... drop partition ... update global indexes

 

 

 

 

--执行计划

explainplan for  select * from t_getpwd_recordwhere account='s';

select* from table(DBMS_XPLAN.DISPLAY)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值