--创建分区表
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(account) LOCAL
(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)