oracle patition 分区和索引

巧了我就是萌 提交于 2019-12-18 19:16:46

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

oracle patition 分区 参考博文

http://docs.oracle.com/cd/B10501_01/server.920/a96524/c12parti.htm#460945

简单的分区方法是 Hash Partitioning

Hash partitioning enables easy partitioning of data that does not lend itself to range or list partitioning. It does this with a simple syntax and is easy to implement. It is a better choice than range partitioning when:

  • You do not know beforehand how much data maps into a given range
  • The sizes of range partitions would differ quite substantially or would be difficult to balance manually
  • Range partitioning would cause the data to be undesirably clustered
  • Performance features such as parallel DML, partition pruning, and partition-wise joins are important

The concepts of splitting, dropping or merging partitions do not apply to hash partitions. Instead, hash partitions can be added and coalesced.

Hash Partitioning Example

CREATE TABLE sales_hash
(salesman_id  NUMBER(5), 
salesman_name VARCHAR2(30), 
sales_amount  NUMBER(10), 
week_no       NUMBER(2)) 
PARTITION BY HASH(salesman_id) 
PARTITIONS 4 
STORE IN (data1, data2, data3, data4);

The preceding statement creates a table sales_hash, which is hash partitioned on salesman_id field. The tablespace names are data1,data2data3, and data4.

对已有表添加partition的方法

https://docs.oracle.com/cd/E11882_01/server.112/e25523/part_admin002.htm#i1007318

 

根据partition 查询语句写

http://www.2cto.com/database/201202/118595.html

跨分区查询


select sum( *) from
(select count(*) cn from t_table_SS PARTITION (P200709_1)
union all
select count(*) cn from t_table_SS PARTITION (P200709_2)
);


查询表上有多少分区


SELECT * FROM useR_TAB_PARTITIONS WHERE TABLE_NAME='tableName'

查询索引信息


select object_name,object_type,tablespace_name,sum(value)
from v$segment_statistics
where statistic_name IN ('physical reads','physical write','logical reads')and object_type='INDEX'
group by object_name,object_type,tablespace_name
order by 4 desc
 
显示数据库所有分区表的信息:


select * from DBA_PART_TABLES

显示表分区名称之类的信息:

select * 
from DBA_PART_COL_STATISTICS
where table_name like '%MIGRAT%'

另外关于查询分区表的信息可以参考:

https://docs.oracle.com/cd/E18283_01/server.112/e16541/part_admin005.htm

为表添加索引的方法

https://docs.oracle.com/cd/B28359_01/server.111/b28310/indexes003.htm#i1006525

CREATE INDEX emp_ename ON emp(ename)
      TABLESPACE users
      STORAGE (INITIAL 20K
      NEXT 20k
      PCTINCREASE 75);

 

注意:当设置主键的时候,是默认会加上一个唯一索引的,是自动创建的。可以指定包含这个索引的用户空间。

Creating an Index Associated with a Constraint

Oracle Database enforces a UNIQUE key or PRIMARY KEY integrity constraint on a table by creating a unique index on the unique key or primary key. This index is automatically created by the database when the constraint is enabled. No action is required by you when you issue the CREATE TABLE or ALTER TABLE statement to create the index, but you can optionally specify a USING INDEX clause to exercise control over its creation. This includes both when a constraint is defined and enabled, and when a defined but disabled constraint is enabled.

To enable a UNIQUE or PRIMARY KEY constraint, thus creating an associated index, the owner of the table must have a quota for the tablespace intended to contain the index, or the UNLIMITED TABLESPACE system privilege. The index associated with a constraint always takes the name of the constraint, unless you optionally specify otherwise.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!