Oracle分区表之创建维护分区表索引的详细步骤

【Kingbase人大金仓】授权文件更换 本文介绍了金仓数据库授权文件更换的步骤:1.通过ksql或客户端工具查询数据库版本;2.在官网下载对应版本的license.bat文件;3.替换前先备份原授权文件(使用tar命令压缩),再用新文件覆盖原文件。注意事项包括:版本号需严格对应,授权文件通常位于安装目录下,可使用find命令查找具体位置。操作需谨慎,建议先备份原文件以便恢复。 阅读详情

墨墨导读:本文来自墨天轮用户投稿,详细描述Oracle分区表之创建维护分区表索引的步骤。

分区索引分为本地(local index)索引和全局索引(global index)。局部索引比全局索引容易管理, 而全局索引比较快。


与索引有关的表:

dba_part_indexes 分区索引的概要统计信息,可以得知每个表上有哪些分区索引,分区索引的类型(local/global)

dba_ind_partitions 每个分区索引的分区级统计信息

dba_indexes/dba_part_indexes 可以得到每个表上有哪些非分区索引

Local索引肯定是分区索引,Global索引可以选择是否分区,如果分区,只能是有前缀的分区索引。


分区索引分2类:有前缀(prefix)的分区索引和无前缀(nonprefix)的分区索引:


(1)有前缀的分区索引指包含了分区键,并且将其作为引导列的索引。

如:

create index i_id_global on PDBA(id) global --引导列
2 partition by range(id) --分区键
3 (partition p1 values less than (200),
4 partition p2 values less than (maxvalue)
5 );


这里的ID 就是分区键,并且分区键id 也是索引的引导列。


(2)无前缀的分区索引的列不是以分区键开头,或者不包含分区键列。

如:

create index ix_custaddr_local_id_p on custaddr(id)
local (
partition t_list556 tablespace icd_service,
partition p_other tablespace icd_service
)

这个分区是按照areacode来的。但是索引的引导列是ID。所以它就是非前缀分区索引。


全局分区索引不支持非前缀的分区索引,如果创建,报错如下:

SQL> create index i_time_global on PDBA(id) global --索引引导列
2 partition by range(time) --分区建
3 (partition p1 values less than (TO_DATE(‘2010-12-1’, ‘YYYY-MM-DD’)),
4 partition p2 values less than (maxvalue)
5 );
partition by range(time)
*


第 2 行出现错误:
ORA-14038: GLOBAL 分区索引必须加上前缀


Local 本地索引

对于local索引,当表的分区发生变化时,索引的维护由Oracle自动进行。


分区表索引注意事项:

(1) 局部索引一定是分区索引,分区键等同于表的分区键。

(2) 前缀和非前缀索引都可以支持索引分区消除,前提是查询的条件中包含索引分区键。

(3) 局部索引只支持分区内的唯一性,无法支持表上的唯一性,因此如果要用局部索引去给表做唯一性约束,则约束中必须要包括分区键列。

(4) 局部分区索引是对单个分区的,每个分区索引只指向一个表分区;全局索引则不然,一个分区索引能指向n个表分区,同时,一个表分区,也可能指向n个索引分区,对分区表中的某个分区做truncate或者move,shrink等,可能会影响到n个全局索引分区,正因为这点,局部分区索引具有更高的可用性。

(5) 位图索引必须是局部分区索引。

(6) 局部索引多应用于数据仓库环境中。

(7) B树索引和位图索引都可以分区,但是HASH索引不可以被分区。

示例:

sql> create index ix_custaddr_local_id on custaddr(id) local;
索引已创建。


和下面SQL 效果相同,因为local索引就是分区索引:

create index ix_custaddr_local_id_p on custaddr(id)
local (
partition t_list556 tablespace icd_service,
partition p_other tablespace icd_service
)SQL> create index ix_custaddr_local_areacode on custaddr(areacode) local;

索引已创建。


验证2个索引的类型:

SQL> select index_name,table_name,partitioning_type,locality,ALIGNMENT from user_part_indexes where table_name=‘CUSTADDR’;index_name table_name partition locali alignment


ix_custaddr_local_areacode custaddr list local prefixed
ix_custaddr_local_id custaddr list local non_prefixed

因为我们的custaddr表是按areacode进行分区的,所以索引ix_custaddr_local_areacode是有前缀的索引(prefixed)。而ix_custaddr_local_id是非前缀索引。


Global索引

对于global索引,可以选择是否分区,而且索引的分区可以不与表分区相对应。全局分区索引只能是B树索引,到目前为止(10gR2),oracle只支持有前缀的全局索引。

另外oracle不会自动的维护全局分区索引,当我们在对表的分区做修改之后,如果对分区进行维护操作时不加上update global indexes的话,通常会导致全局索引的INVALDED,必须在执行完操作后 REBUILD。

注意事项:

(1)全局索引可以分区,也可以是不分区索引,全局索引必须是前缀索引,即全局索引的索引列必须是以索引分区键作为其前几列。

(2)全局索引可以依附于分区表;也可以依附于非分区表。

(3)全局分区索引的索引条目可能指向若干个分区,因此,对于全局分区索引,即使只截断一个分区中的数据,都需要rebulid若干个分区甚至是整个索引。

(4)全局索引多应用于oltp系统中。

(5)全局分区索引只按范围或者散列分区,hash分区是10g以后才支持。

(6) oracle9i以后对分区表做move或者truncate的时可以用update global indexes语句来同步更新全局分区索引,用消耗一定资源来换取高度的可用性。

(7) 表用a列作分区,索引用b做局部分区索引,若where条件中用b来查询,那么oracle会扫描所有的表和索引的分区,成本会比分区更高,此时可以考虑用b做全局分区索引。


注意:Oracle只支持2中类型的全局分区索引:

range partitioned 和 Hash Partitioned.


官网的说明如下:

Global Partitioned Indexes

Oracle offers two types of global partitioned index: range partitioned and hash partitioned.

(1)Global Range Partitioned Indexes

Global range partitioned indexes are flexible in that the degree of partitioning and the partitioning key are independent from the table’s partitioning method. They are commonly used for OLTP environments and offer efficient access to any individual record.

The highest partition of a global index must have a partition bound, all of whose values are MAXVALUE. This ensures that all rows in the underlying table can be represented in the index. Global prefixed indexes can be unique or nonunique.

You cannot add a partition to a global index because the highest partition always has a partition bound of MAXVALUE. If you wish to add a new highest partition, use the ALTER INDEX SPLIT PARTITION statement. If a global index partition is empty, you can explicitly drop it by issuing the ALTER INDEX DROP PARTITION statement. If a global index partition contains data, dropping the partition causes the next highest partition to be marked unusable. You cannot drop the highest partition in a global index.

(2)Global Hash Partitioned Indexes

Global hash partitioned indexes improve performance by spreading out contention when the index is monotonically growing. In other words, most of the index insertions occur only on the right edge of an index.

(3)Maintenance of Global Partitioned Indexes

By default, the following operations on partitions on a heap-organized table mark all global indexes as unusable:

ADD (HASH)

COALESCE (HASH)

DROP

EXCHANGE

MERGE

MOVE

SPLIT

TRUNCATE


示例1:全局索引,全局索引对所有分区类型都支持:

sql> create index ix_custaddr_ global_id on custaddr(id) global;

索引已创建。


示例2:全局分区索引,只支持Range 分区和Hash 分区:


(1)创建2个测试分区表:

sql> create table pdba (id number, time date) partition by range (time)
2 (
3 partition p1 values less than (to_date(‘2010-10-1’, ‘yyyy-mm-dd’)),
4 partition p2 values less than (to_date(‘2010-11-1’, ‘yyyy-mm-dd’)),
5 partition p3 values less than (to_date(‘2010-12-1’, ‘yyyy-mm-dd’)),
6 partition p4 values less than (maxvalue)
7 );
表已创建。
SQL> create table Thash
2 (
3 id number primary key,
4 item_id number(8) not null
5 )
6 partition by hash(id)
7 (
8 partition part_01,
9 partition part_02,
10 partition part_03
11 );
表已创建。

(2)创建分区索引

示例2:全局分区索引

SQL> create index i_id_global on PDBA(id) global
2 partition by range(id)
3 (partition p1 values less than (200),
4 partition p2 values less than (maxvalue)
5 );

索引已创建。


–这个是有前缀的分区索引。

SQL> create index i_time_global on PDBA(id) global
2 partition y range(time)
3 (partition p1 values less than (TO_DATE(‘2010-12-1’, ‘YYYY-MM-DD’)),
4 partition p2 values less than (maxvalue)
5 );partition by range(time)
*


第 2 行出现错误:

ORA-14038: GLOBAL 分区索引必须加上前缀
SQL> create index i_time_global on PDBA(time) global
2 partition by range(time)
3 (partition p1 values less than (TO_DATE(‘2010-12-1’, ‘YYYY-MM-DD’)),
4 partition p2 values less than (maxvalue)
5 );

索引已创建。


–有前缀的分区索引

SQL> select index_name,table_name,partitioning_type,locality,ALIGNMENT from user_part_indexes where table_name=‘PDBA’;index_name table_name partition locali alignmenti_id_global pdba range global prefixed
i_time_global pdba range global prefixedSQL> CREATE INDEX ix_hash ON PDBA (id,time) GLOBAL
2 PARTITION BY HASH (id)
3 (PARTITION p1,
4 PARTITION p2,
5 PARTITION p3,
6 PARTITION p4);

索引已创建。


只要索引的引导列包含分区键,就是有前缀的分区索引。

索引重建问题

(1)分区索引


对于分区索引,不能整体进行重建,只能对单个分区进行重建。语法如下:

Alter index idx_name rebuild partition index_partition_name [online nologging]

说明:

online:表示重建的时候不会锁表。

nologging:表示建立索引的时候不生成日志,加快速度。

如果要重建分区索引,只能drop表原索引,在重新创建:

SQL>create index loc_xxxx_col on xxxx(col) local tablespace SYSTEM;

这个操作要求较大的临时表空间和排序区。


示例:

SQL> select index_name,partition_name from user_ind_partitions where index_name=‘I_TIME_GLOBAL’;INDEX_NAME PARTITION_NAMEI_TIME_GLOBAL P1I_TIME_GLOBAL P2SQL> alter index I_TIME_GLOBAL rebuild partition p1 online nologging;

索引已更改。

SQL> alter index I_TIME_GLOBAL rebuild partition p2 online nologging;


索引已更改。


(2)全局索引

Oracle 会自动维护分区索引,对于全局索引,如果在对分区表操作时,没有指定update index,则会导致全局索引失效,需要重建。

SQL> select owner,index_name,table_name,status from dba_indexes where INDEX_NAME=‘IX_PDBA_GLOBAL’;owner index_name table_name statussys ix_pdba_global pdba valid

删除一个分区:

SQL> alter table pdba drop partition p2;

表已更改。

SQL> select owner,index_name,table_name,status from dba_indexes where INDEX_NAME=‘IX_PDBA_GLOBAL’;owner index_name table_name statussys ix_pdba_global pdba validsplit 分区:SQL> alter table pdba split partition P4 at(TO_DATE(‘2010-12-21 00:00:00’,‘YYYY-MM-DD HH24:MI:SS’)) into (partition P4, partition P5);

表已更改。

SQL> select owner,index_name,table_name,status from dba_indexes where INDEX_NAME=‘IX_PDBA_GLOBAL’;owner index_name table_name statussys ix_pdba_global pdba validdrop 分区时使用update indexesSQL> alter table pdba drop partition P4 UPDATE INDEXES;

表已更改。

SQL> select owner,index_name,table_name,status from dba_indexes where INDEX_NAME=‘IX_PDBA_GLOBAL’;owner index_name table_name statussys ix_pdba_global pdba valid

做了几个drop分区操作,全局索引没有失效,有点奇怪。不过如果在生产环境中,还是小心点。

重建全局索引命令如下:

Alter index idx_name rebuild [online nologging]


示例:

SQL> Alter index ix_pdba_global rebuild online nologging;

索引已更改。


补充一点,分区表存储空间的问题:

SQL> select table_name,partition_name,tablespace_name from user_tab_partitions where table_name=‘DBA’;TABLE_NAME PARTITION_NAME TABLESPACE_NAMEDBA P1 SYSTEM
DBA P2 SYSTEM
DBA P3 SYSTEM
DBA P4 SYSTEM

通过user_tab_partitions 表可以查看到每个分区对应的tablesapce_name. 但是,如果通过all_tables 表,却查不到分区表对应表空间的信息。


分区表:

SQL> select owner,table_name,tablespace_name,cluster_name from all_tables where table_name=‘DBA’;OWNER TABLE_NAME TABLESPACE_NAME CLUSTER_NAMESYS DBA

普通表:

SQL> select owner,table_name,tablespace_name,cluster_name from all_tables where table_name=‘DAVE’;OWNER TABLE_NAME TABLESPACE_NAME CLUSTER_NAME

墨天轮原文链接:https://www.modb.pro/db/21901

推荐阅读:144页!分享珍藏已久的数据库技术年刊

数据和云

ID:OraNews

如有收获,请划至底部,点击“在看”,谢谢!

点击下图查看更多 ↓

云和恩墨大讲堂 | 一个分享交流的地方

长按,识别二维码,加入万人交流社群

请备注:云和恩墨大讲堂

  点个“在看”

你的喜欢会被看到❤

Python逆向爬取Tik Tok,MsToken,X-Bogus以及signature tiktok作为字节海外的自媒体平台,具有很非常大的价值,本文旨在教会大家实现Tik Tok的签名获取以及数据的最终爬取。 阅读详情

相关推荐

索引维护方法

Microsoft SQL Server 索引维护维护源代码, Perfmon性能查看选择,留在自己用。

Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法

一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase)。分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中。分区完全对应用透明。 Oracle分区表可以包括多个分区,每个分区都是一个独立的段(SEGMENT),可以存放到不同的表空间中。查询时可以通过查询表来访问各个分区中的数据,也可以通过在查询时直接指定分区的方法来进行查询。

jinshiyill的博客 4347

FreqChip-Download V1.3.9.1.rar

FreqChip_Download V1.3.9.1.rar富芮坤蓝牙烧录工具根据相关技术资料和开发实践,​​FreqChip_Download​​ 是富芮坤微电子(Freqchip)为其蓝牙芯片(如 FR801x、FR800x 系列)开发的专用固件烧录工具,用于将编译后的二进制文件(.bin)写入芯片闪存。以下是其核心功能与使用要点:​​芯片支持​​专为富芮坤蓝牙 SoC 设计,覆盖主流型号(如 FR8016HA、FR8018H、FR8008 等)。​​注意​​:不同芯片需匹配对应版本工具(如 FR3000 系列与 FR8000 系列工具不通用)。​​烧录模式​​​​下载模式​​:通过 BOOT 引脚触发(通常需按住 BOOT 键复位设备)进入烧录状态。​​接口支持​​:USB 转串口(Type-C 或 UART 接口),波特率默认 ​​921600 bps​​。​​地址配置​​需手动设置固件烧录地址(如 Bootloader 地址 0x0,主程序地址 0x8000),与 SDK 编译生成的地址一致。

维护索引的三种方法

索引的数据是跟着基表的DML活动而经常发生变化的。 基表删除数据后,对应的索引叶节点中空间不会被释放、不会被重用。 在DML操作十分频繁的表上的索引,有可能会变得非常庞大。 方法一:删除索引,从新创建,drop index,create index。 方法二: ALTER INDEX ind_obj_id REBUILD ; ALTER INDEX ind_obj_id REBUILD ONLI...

Noblelxl的博客 5138

SQLServer 维护索引实现查询优化

索引分为两大类:聚集索引和非聚集索引一、聚集索引当数据表中的一列被确定为主键后,SQLServer会自动为它建立聚集索引,因为聚集索引是标识每个记录行的键,所以它将被应用到每个查询中.二、非聚集索引非聚集索引的情况就比较复杂了,因为它是相对于表独立组织的,在SQLServer中有单独的结构来存储非聚集索引. 有一点是要注意的,不要代替查询优化器去指定某个索引,DBA应该想办

ylqmf的专栏 7650

Oracle 错误总结及问题解决 ORA

ORA 错误大全

基于Oracle11G 19万+

oracle分区表local索引,Oracle分区表创建维护分区表索引详细步骤

ix_custaddr_local_areacode custaddr list local prefixedix_custaddr_local_id custaddr list local non_prefixed因为我们的custaddr表是按areacode进行分区的,所以索引ix_custaddr_local_areacode是有前缀的索引(prefixed)。而ix_custaddr_l...

weixin_39598069的博客 1475

oracle分区表local索引,【eygle】Oracle分区表和Local索引创建维护

Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对于分区及本地索引的一个示例。首先根据字典表创建一个测试:SQL> connect eygle/eygleConnected.SQL> CREATE TABLE dbobjs2 (OBJECT_ID NUMBER NOT NUL...

weixin_30949015的博客 910

oracle 建分区索引_创建维护Oracle分区表和本地索引(一)

Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对于分区及本地索引的一个示例。首先根据字典表创建一个测试分区表:SQL>connecteygle/eygleConnected.SQL>createTABLEdbobjs2(OBJECT_IDNUMBERNOTNULL,3O...

weixin_39630498的博客 860

Oracle分区表和Local索引创建维护

Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。 从产品上说,分区技术是Oracle企业版中独立收费的一个组件。 以下是对于分区及本地索引的一个示例。 首先根据字典表创建一个测试分区表: SQL> connect eygle/eyg

heqiyu34的专栏 4594

oracle删除建分区索引,Oracle分区表创建维护分区表索引详细步骤

分区索引分为本地(local index)索引和全局索引(global index)。局部索引比全局索引容易管理, 而全局索引比较快。与索引有关的表:dba_part_indexes 分区索引的概要统计信息,可以得知每个表上有哪些分区索引,分区索引的类型(local/global)dba_ind_partitions 每个分区索引的分区级统计信息dba_indexes/dba_part_index...

weixin_36252577的博客 907

oracle 建分区索引_Oracle分区表和Local索引创建维护

Oracle分区表和Local索引创建维护SQL> connect eygle/eygleConnected.SQL> CREATE TABLE dbobjs2 (OBJECT_ID NUMBER NOT NULL,3 OBJECT_NAME varchar2(128),4 CREATED DATE NOT NULL5...

weixin_39790102的博客 1137

创建维护Oracle分区表和本地索引

【原文: http://www.searchdatabase.com.cn/showcontent_12937.htm 】 Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对

zdleek的专栏 823

oracle本地索引维护,创建维护Oracle分区表和本地索引(三)

对于非分区表的测试:SQL>createTABLEdbobjs22(object_idNUMBERNOTNULL,3object_nameVARchar2(128),4createdDATENOTNULL5);Tablecreated.SQL>createINDEXdbobjs_idx2ONdbobjs2(created);Indexcrea...

weixin_42371234的博客 213

oracle10g 创建分区表,oracle10G分区的创建维护Oracle分区表和本地索引

CREATEINDEXdbobjs_idxONdbobjs(created)LOCAL(PARTITIONdbobjs_06TABLESPACEusers,PARTITIONdbobjs_07TABLESPACEusers)TABLESPACEusers;通过统一的tablespace子句为索引指定表空间。SQL>COLsegment_namefora20...

weixin_33740988的博客 113

【eygle】Oracle分区表和Local索引创建维护

Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对于分区及本地索引的一个示例。首先根据字典表创建一个测试分区表: SQL> ...

ctpq29224的博客 349

oracle10G分区的创建维护Oracle分区表和本地索引

Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对于分区及本地索引的一个示例。  Oracle的分区技术在某些条件下可以极大 Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。从产品上说,分区技术是Oracle企业版中独立收费的一个组件。以下是对于分区及本地索引的一个示例。  

qyq88888的专栏 638
上一篇: 经典故障:四个雷,3*2*2*3种随机方法的特殊恢复案例
下一篇: 直播丨易鲸捷HTAP融合型分布式数据库EsgynDB SQL编译器详解
数据和云
博客等级 码龄9年 3815粉丝 743原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值